Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
68 | public function testUpdateTenant(): void |
||
69 | { |
||
70 | $tenant = new Tenant(); |
||
71 | $tenant |
||
72 | ->setAddonKey('test') |
||
73 | ->setClientKey('test') |
||
74 | ->setPublicKey('test') |
||
75 | ->setSharedSecret('test') |
||
76 | ->setServerVersion('test') |
||
77 | ->setPluginsVersion('test') |
||
78 | ->setBaseUrl('test') |
||
79 | ->setProductType('test') |
||
80 | ->setDescription('test') |
||
81 | ->setEventType('test') |
||
82 | ->setOauthClientId('test'); |
||
83 | |||
84 | $repository = $this->createMock(TenantRepositoryInterface::class); |
||
85 | $repository->expects($this->once()) |
||
86 | ->method('findByClientKey') |
||
87 | ->with('test') |
||
88 | ->willReturn($tenant); |
||
89 | $repository |
||
90 | ->expects($this->never()) |
||
91 | ->method('initializeTenant'); |
||
92 | |||
93 | $expectedTenant = new Tenant(); |
||
94 | $expectedTenant |
||
95 | ->setAddonKey('test2') |
||
96 | ->setClientKey('test') |
||
97 | ->setPublicKey('test2') |
||
98 | ->setSharedSecret('test') |
||
99 | ->setServerVersion('test2') |
||
100 | ->setPluginsVersion('test') |
||
101 | ->setBaseUrl('test2') |
||
102 | ->setProductType('test2') |
||
103 | ->setDescription('test') |
||
104 | ->setEventType('test') |
||
105 | ->setOauthClientId('test'); |
||
106 | |||
107 | $repository->expects($this->once()) |
||
108 | ->method('save') |
||
109 | ->with($expectedTenant); |
||
110 | |||
111 | $controller = new HandshakeController($repository, new Logger()); |
||
112 | $request = new Request([], [], [], [], [], ['HTTP_AUTHORIZATION' => 'Bearer '.JWT::encode([], 'test', 'HS256')], json_encode([ |
||
113 | 'key' => 'test2', |
||
114 | 'clientKey' => 'test', |
||
115 | 'publicKey' => 'test2', |
||
116 | 'sharedSecret' => 'test', |
||
117 | 'serverVersion' => 'test2', |
||
118 | 'pluginsVersion' => 'test', |
||
119 | 'baseUrl' => 'test2', |
||
120 | 'productType' => 'test2', |
||
121 | 'description' => 'test', |
||
122 | 'eventType' => 'test', |
||
123 | 'oauthClientId' => 'test', |
||
124 | ])); |
||
125 | |||
126 | $response = $controller->registerAction($request); |
||
127 | self::assertEquals(200, $response->getStatusCode()); |
||
128 | self::assertEquals('OK', $response->getContent()); |
||
129 | } |
||
180 |