Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 19 | class SilexUserServiceProviderDependenciesTest extends WebTestCase |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @expectedException LogicException |
||
| 23 | * @expectedExceptionMessage You must register the ServiceControllerServiceProvider to use the SilexUserServiceProvider |
||
| 24 | */ |
||
| 25 | public function testRegisterWithoutServiceController() |
||
| 26 | { |
||
| 27 | $this->app->register(new SilexUserServiceProvider()); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @expectedException LogicException |
||
| 32 | * @expectedExceptionMessage You must register the TwigServiceProvider to use the SilexUserServiceProvider |
||
| 33 | */ |
||
| 34 | public function testRegisterWithoutTwig() |
||
| 35 | { |
||
| 36 | $this->app->register(new ServiceControllerServiceProvider()); |
||
| 37 | $this->app->register(new SilexUserServiceProvider()); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @expectedException LogicException |
||
| 42 | * @expectedExceptionMessage You must register the SessionServiceProvider to use the SilexUserServiceProvider |
||
| 43 | */ |
||
| 44 | public function testRegisterWithoutSession() |
||
| 45 | { |
||
| 46 | $this->app->register(new ServiceControllerServiceProvider()); |
||
| 47 | $this->app->register(new TwigServiceProvider()); |
||
| 48 | $this->app->register(new SilexUserServiceProvider()); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @expectedException LogicException |
||
| 53 | * @expectedExceptionMessage You must register the TranslationServiceProvider to use the SilexUserServiceProvider |
||
| 54 | */ |
||
| 55 | public function testRegisterWitoutTranslation() |
||
| 56 | { |
||
| 57 | $this->app->register(new ServiceControllerServiceProvider()); |
||
| 58 | $this->app->register(new TwigServiceProvider()); |
||
| 59 | $this->app->register(new SessionServiceProvider()); |
||
| 60 | $this->app->register(new SilexUserServiceProvider()); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @expectedException LogicException |
||
| 65 | * @expectedExceptionMessage You must register the ValidatorServiceProvider to use the SilexUserServiceProvider |
||
| 66 | */ |
||
| 67 | public function testRegisterWitoutValidator() |
||
| 68 | { |
||
| 69 | $this->app->register(new ServiceControllerServiceProvider()); |
||
| 70 | $this->app->register(new TwigServiceProvider()); |
||
| 71 | $this->app->register(new SessionServiceProvider()); |
||
| 72 | $this->app->register(new LocaleServiceProvider()); |
||
| 73 | $this->app->register(new TranslationServiceProvider()); |
||
| 74 | $this->app->register(new SilexUserServiceProvider()); |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @expectedException LogicException |
||
| 79 | * @expectedExceptionMessage You must register the FormServiceProvider to use the SilexUserServiceProvider |
||
| 80 | */ |
||
| 81 | public function testRegisterWitoutForm() |
||
| 82 | { |
||
| 83 | $this->app->register(new ServiceControllerServiceProvider()); |
||
| 84 | $this->app->register(new TwigServiceProvider()); |
||
| 85 | $this->app->register(new SessionServiceProvider()); |
||
| 86 | $this->app->register(new LocaleServiceProvider()); |
||
| 87 | $this->app->register(new TranslationServiceProvider()); |
||
| 88 | $this->app->register(new ValidatorServiceProvider()); |
||
| 89 | $this->app->register(new SilexUserServiceProvider()); |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @expectedException LogicException |
||
| 94 | * @expectedExceptionMessage You must register the DoctrineOrmServiceProvider to use the SilexUserServiceProvider |
||
| 95 | */ |
||
| 96 | public function testRegisterWitoutDoctrineOrm() |
||
| 97 | { |
||
| 98 | $this->app->register(new ServiceControllerServiceProvider()); |
||
| 99 | $this->app->register(new TwigServiceProvider()); |
||
| 100 | $this->app->register(new SessionServiceProvider()); |
||
| 101 | $this->app->register(new LocaleServiceProvider()); |
||
| 102 | $this->app->register(new TranslationServiceProvider()); |
||
| 103 | $this->app->register(new ValidatorServiceProvider()); |
||
| 104 | $this->app->register(new FormServiceProvider()); |
||
| 105 | $this->app->register(new SilexUserServiceProvider()); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @expectedException LogicException |
||
| 110 | * @expectedExceptionMessage You must register the SecurityServiceProvider to use the SilexUserServiceProvider |
||
| 111 | */ |
||
| 112 | public function tetRegisterWitoutSecurity() |
||
| 113 | { |
||
| 114 | $this->app->register(new ServiceControllerServiceProvider()); |
||
| 115 | $this->app->register(new TwigServiceProvider()); |
||
| 116 | $this->app->register(new SessionServiceProvider()); |
||
| 117 | $this->app->register(new LocaleServiceProvider()); |
||
| 118 | $this->app->register(new TranslationServiceProvider()); |
||
| 119 | $this->app->register(new ValidatorServiceProvider()); |
||
| 120 | $this->app->register(new FormServiceProvider()); |
||
| 121 | $this->app->register(new DoctrineServiceProvider()); |
||
| 122 | $this->app->register(new DoctrineOrmServiceProvider()); |
||
| 123 | |||
| 124 | $this->app->register(new SilexUserServiceProvider()); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function createApplication() |
||
| 128 | { |
||
| 129 | $app = new Application([ |
||
| 130 | 'debug' => true |
||
| 131 | ]); |
||
| 132 | |||
| 133 | return $app; |
||
| 134 | } |
||
| 135 | } |
||
| 136 |