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 |
||
5 | use Nord\Lumen\OAuth2\OAuth2Service; |
||
6 | |||
7 | class OAuth2ServiceTest extends \Codeception\TestCase\Test |
||
8 | { |
||
9 | use \Codeception\Specify; |
||
10 | |||
11 | /** |
||
12 | * @var \UnitTester |
||
13 | */ |
||
14 | protected $tester; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected static $token = [ |
||
20 | 'access_token' => 'mF_9.B5f-4.1JqM', |
||
21 | 'token_type' => 'Bearer', |
||
22 | 'expires_in' => 3600, |
||
23 | 'refresh_token' => 'tGzv3JOkF0XG5Qx2TlKWIA' |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * @inheritdoc |
||
28 | */ |
||
29 | protected function setup() |
||
33 | |||
34 | /** |
||
35 | * |
||
36 | */ |
||
37 | public function testAssertIssueAccessToken() |
||
49 | |||
50 | /** |
||
51 | * |
||
52 | */ |
||
53 | View Code Duplication | public function testAssertValidateAccessToken() |
|
60 | |||
61 | /** |
||
62 | * |
||
63 | */ |
||
64 | View Code Duplication | public function testAssertGetResourceOwnerId() |
|
72 | |||
73 | /** |
||
74 | * |
||
75 | */ |
||
76 | View Code Duplication | public function testAssertGetResourceOwnerType() |
|
84 | |||
85 | /** |
||
86 | * |
||
87 | */ |
||
88 | View Code Duplication | public function testAssertGetClientId() |
|
96 | |||
97 | /** |
||
98 | * @return \League\OAuth2\Server\AuthorizationServer|\PHPUnit_Framework_MockObject_MockObject |
||
99 | */ |
||
100 | private function createAuthorizationServer() |
||
108 | |||
109 | /** |
||
110 | * @return \League\OAuth2\Server\ResourceServer |
||
111 | */ |
||
112 | private function createResourceServer() |
||
113 | { |
||
114 | return new \League\OAuth2\Server\ResourceServer( |
||
115 | new MockSessionStorage(), |
||
116 | new MockAccessTokenStorage(), |
||
117 | new MockClientStorage(), |
||
118 | new MockScopeStorage() |
||
119 | ); |
||
120 | } |
||
122 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: