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 |
||
21 | class SilexUserServiceProviderConfigurationTest extends WebTestCase |
||
22 | { |
||
23 | /** |
||
24 | * @expectedException LogicException |
||
25 | * @expectedExceptionMessage The "user_class" option must be set |
||
26 | */ |
||
27 | public function testWithoutUserClass() |
||
28 | { |
||
29 | $this->app->boot(); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @expectedException LogicException |
||
34 | * @expectedExceptionMessage The "user_class" option must be set |
||
35 | */ |
||
36 | public function testWithEmptyUserClass() |
||
37 | { |
||
38 | $this->app['silex_user.options'] = [ |
||
39 | 'user_class' => '' |
||
40 | ]; |
||
41 | |||
42 | $this->app->boot(); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @expectedException LogicException |
||
47 | * @expectedExceptionMessage The "firewall_name" option must be set |
||
48 | */ |
||
49 | public function testWithoutFirewallName() |
||
50 | { |
||
51 | $this->app['silex_user.options'] = [ |
||
52 | 'user_class' => 'User' |
||
53 | ]; |
||
54 | |||
55 | $this->app->boot(); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @expectedException LogicException |
||
60 | * @expectedExceptionMessage The "firewall_name" option must be set |
||
61 | */ |
||
62 | public function testWithEmptyFirewallName() |
||
63 | { |
||
64 | $this->app['silex_user.options'] = [ |
||
65 | 'user_class' => 'User', |
||
66 | 'firewall_name' => '' |
||
67 | ]; |
||
68 | |||
69 | $this->app->boot(); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @expectedException LogicException |
||
74 | * @expectedExceptionMessage You must configure a mailer to enable email notifications |
||
75 | */ |
||
76 | public function testEmailConfirmationWithoutMailer() |
||
77 | { |
||
78 | $this->app['silex_user.options'] = [ |
||
79 | 'user_class' => 'User', |
||
80 | 'firewall_name' => 'main', |
||
81 | 'registration.confirmation.enabled' => true |
||
82 | ]; |
||
83 | |||
84 | $this->app->boot(); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @expectedException LogicException |
||
89 | * @expectedExceptionMessage The "registration.confirmation.from_email" option must be set |
||
90 | */ |
||
91 | public function testEmailConfirmationWithoutFromEmail() |
||
92 | { |
||
93 | $this->app->register(new SwiftmailerServiceProvider()); |
||
94 | |||
95 | $this->app['silex_user.options'] = [ |
||
96 | 'user_class' => 'User', |
||
97 | 'firewall_name' => 'main', |
||
98 | 'registration.confirmation.enabled' => true |
||
99 | ]; |
||
100 | |||
101 | $this->app->boot(); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @expectedException LogicException |
||
106 | * @expectedExceptionMessage The "registration.confirmation.from_email" option must be set |
||
107 | */ |
||
108 | public function testEmailConfirmationWithEmptyFromEmail() |
||
109 | { |
||
110 | $this->app->register(new SwiftmailerServiceProvider()); |
||
111 | |||
112 | $this->app['silex_user.options'] = [ |
||
113 | 'user_class' => 'User', |
||
114 | 'firewall_name' => 'main', |
||
115 | 'registration.confirmation.enabled' => true, |
||
116 | 'registration.confirmation.from_email' => '' |
||
117 | ]; |
||
118 | |||
119 | $this->app->boot(); |
||
120 | } |
||
121 | |||
122 | public function createApplication() |
||
123 | { |
||
124 | $app = new Application([ |
||
125 | 'debug' => true |
||
126 | ]); |
||
127 | |||
128 | $app->register(new ServiceControllerServiceProvider()); |
||
129 | $app->register(new TwigServiceProvider()); |
||
130 | $app->register(new SessionServiceProvider()); |
||
131 | $app->register(new LocaleServiceProvider()); |
||
132 | $app->register(new TranslationServiceProvider()); |
||
133 | $app->register(new ValidatorServiceProvider()); |
||
134 | $app->register(new FormServiceProvider()); |
||
135 | $app->register(new DoctrineServiceProvider()); |
||
136 | $app->register(new DoctrineOrmServiceProvider()); |
||
137 | $app->register(new SecurityServiceProvider()); |
||
138 | $app->register(new SilexUserServiceProvider()); |
||
139 | |||
140 | $app['security.firewalls'] = [ |
||
141 | 'main' => [ |
||
142 | 'form' => [] |
||
143 | ] |
||
144 | ]; |
||
145 | |||
146 | return $app; |
||
147 | } |
||
148 | } |
||
149 |