Skip to content

Commit 4baf322

Browse files
authored
Merge pull request #1136: apply Rector on tests files
2 parents ac677c1 + 5157391 commit 4baf322

File tree

78 files changed

+246
-472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+246
-472
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,3 @@ clover.xml
2020
.env
2121
builds
2222
build
23-
24-
/src/Prototype/tests/runtime/cache/
25-
/src/Scaffolder/tests/App/runtime/cache/

rector.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6+
use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector;
7+
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
68
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
79
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodParameterRector;
810
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
911
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
1012
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
1113
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodParameterRector;
14+
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
1215
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
1316
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
1417
use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector;
@@ -17,6 +20,7 @@
1720
return RectorConfig::configure()
1821
->withPaths([
1922
__DIR__ . '/src/*/src',
23+
__DIR__ . '/src/*/tests',
2024
__DIR__ . '/tests',
2125
])
2226
->withParallel()
@@ -30,13 +34,17 @@
3034
__DIR__ . '/src/Scaffolder/src/Command/FilterCommand.php',
3135
__DIR__ . '/src/Scaffolder/src/Command/JobHandlerCommand.php',
3236
__DIR__ . '/src/Scaffolder/src/Command/MiddlewareCommand.php',
37+
__DIR__ . '/src/Console/tests/PromptArgumentsTest.php',
3338
],
3439
RemoveUnusedPrivateMethodRector::class => [
3540
__DIR__ . '/src/Boot/src/Bootloader/ConfigurationBootloader.php',
3641
__DIR__ . '/src/Broadcasting/src/Bootloader/BroadcastingBootloader.php',
3742
__DIR__ . '/src/Cache/src/Bootloader/CacheBootloader.php',
3843
__DIR__ . '/src/Serializer/src/Bootloader/SerializerBootloader.php',
3944
__DIR__ . '/src/Validation/src/Bootloader/ValidationBootloader.php',
45+
__DIR__ . '/src/Translator/tests/IndexerTest.php',
46+
__DIR__ . '/src/Tokenizer/tests/ReflectionFileTest.php',
47+
__DIR__ . '/src/Core/tests/SingletonsTest.php',
4048
],
4149
RemoveUselessVarTagRector::class => [
4250
__DIR__ . '/src/Console/src/Traits/HelpersTrait.php',
@@ -54,16 +62,37 @@
5462
],
5563
RemoveUnusedPrivateMethodParameterRector::class => [
5664
__DIR__ . '/src/Core/src/Internal/Factory.php',
65+
__DIR__ . '/src/Core/tests/InjectableTest.php',
66+
],
67+
RemoveDoubleAssignRector::class => [
68+
__DIR__ . '/src/Core/tests/Scope/FinalizeAttributeTest.php',
69+
],
70+
RemoveUnusedVariableAssignRector::class => [
71+
__DIR__ . '/src/Core/tests/ExceptionsTest.php',
72+
],
73+
RemoveDeadStmtRector::class => [
74+
__DIR__ . '/src/Core/tests/ExceptionsTest.php',
5775
],
5876

59-
// to be enabled later after upgrade to 1.2.4 merged
60-
// to easier to review
77+
// to be enabled later for bc break 4.x
6178
RemoveUnusedPublicMethodParameterRector::class,
6279
RemoveEmptyClassMethodRector::class,
6380
RemoveUnusedPromotedPropertyRector::class,
6481

6582
// start with short open tag
83+
__DIR__ . '/src/Views/tests/fixtures/other/var.php',
6684
__DIR__ . '/tests/app/views/native.php',
85+
86+
// example code for test
87+
'*/Fixtures/*',
88+
'*/Stub/*',
89+
'*/Stubs/*',
90+
'*/tests/Classes/*',
91+
'*/tests/Internal/*',
92+
__DIR__ . '/src/Console/tests/Configurator',
93+
94+
// cache
95+
'*/runtime/cache/*',
6796
])
6897
->withPhpSets(php74: true)
6998
->withPreparedSets(deadCode: true);

src/AnnotatedRoutes/tests/RouteLocatorListenerTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ private function configureRouter(): void
5454
$this->container = new Container();
5555

5656
$this->container->bindSingleton(UriFactoryInterface::class, new Psr17Factory());
57-
$this->container->bindSingleton(RouterInterface::class, static function (UriHandler $handler, Container $container) {
58-
return new Router('/', $handler, $container);
59-
});
57+
$this->container->bindSingleton(
58+
RouterInterface::class,
59+
static fn(UriHandler $handler, Container $container) => new Router(
60+
'/',
61+
$handler,
62+
$container,
63+
),
64+
);
6065
$this->container->bindSingleton(GroupRegistry::class, new GroupRegistry($this->container));
6166

6267
$this->listener = new RouteLocatorListener(

src/AuthHttp/tests/Diactoros/ResponseFactory.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ final class ResponseFactory implements ResponseFactoryInterface
1414
/** @var HttpConfig */
1515
protected $config;
1616

17-
/**
18-
* @param HttpConfig $config
19-
*/
2017
public function __construct(HttpConfig $config)
2118
{
2219
$this->config = $config;
2320
}
2421

25-
/**
26-
* @param int $code
27-
* @param string $reasonPhrase
28-
*
29-
* @return ResponseInterface
30-
*/
22+
3123
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
3224
{
3325
$response = new Response($code);

src/AuthHttp/tests/Diactoros/UriFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
final class UriFactory implements UriFactoryInterface
1212
{
13-
/**
14-
* @param string $uri
15-
* @return UriInterface
16-
*/
1713
public function createUri(string $uri = ''): UriInterface
1814
{
1915
return new Uri($uri);

src/Boot/tests/ConfigsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testCustomConfigLoader(): void
3030
'config' => __DIR__ . '/config',
3131
])->run();
3232

33-
/** @var ConfiguratorInterface $config */
33+
/** @var ConfiguratorInterface $configurator */
3434
$configurator = $core->getContainer()->get(ConfiguratorInterface::class);
3535

3636
$this->assertSame(['test-key' => 'test value'], $configurator->getConfig('yaml'));

src/Boot/tests/EnvironmentTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ public function testSetNullValueWithoutOverwriting(): void
8484
}
8585

8686
/**
87-
* @param array $env
88-
* @return EnvironmentInterface
8987
* @throws \Throwable
9088
*/
9189
protected function getEnv(array $env, bool $overwite= true): EnvironmentInterface

src/Broadcasting/tests/Middleware/AuthorizationMiddlewareTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ public function testAuthorizationEventsShouldBeDispatched(string $event, bool $a
151151
$handler = m::mock(RequestHandlerInterface::class);
152152
$dispatcher = m::mock(EventDispatcherInterface::class);
153153
$status = new AuthorizationStatus($authStatus, ['topic_name'], ['foo' => 'bar']);
154-
$dispatcher->shouldReceive('dispatch')->once()->withArgs(function (Authorized $e) use($event, $status) {
155-
return $e->status === $status && $e::class === $event;
156-
});
154+
$dispatcher->shouldReceive('dispatch')->once()->withArgs(fn(Authorized $e) => $e->status === $status && $e::class === $event);
157155

158156
$middleware = new AuthorizationMiddleware(
159157
$broadcast = m::mock(BroadcastInterface::class, GuardInterface::class),
@@ -179,11 +177,9 @@ public function testAuthorizationEventsWithoutGuardShouldBeDispatched(): void
179177
$request = m::mock(ServerRequestInterface::class);
180178
$handler = m::mock(RequestHandlerInterface::class);
181179
$dispatcher = m::mock(EventDispatcherInterface::class);
182-
$dispatcher->shouldReceive('dispatch')->once()->withArgs(function (Authorized $event) {
183-
return $event->status->success === true
184-
&& $event->status->topics === null
185-
&& $event->status->response === null;
186-
});
180+
$dispatcher->shouldReceive('dispatch')->once()->withArgs(fn(Authorized $event) => $event->status->success === true
181+
&& $event->status->topics === null
182+
&& $event->status->response === null);
187183

188184
$middleware = new AuthorizationMiddleware(
189185
m::mock(BroadcastInterface::class),

src/Console/tests/ConfigureTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ public function testNoBreakFailure(): void
125125
$this->assertEquals(1, $output->getCode());
126126
}
127127

128-
/**
129-
* @return Console
130-
*/
131128
private function bindFailure(): Console
132129
{
133130
$core = $this->getCore(

src/Console/tests/InterceptorTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ public function testInterceptorShouldBeResolved(): void
2727

2828
$interceptor->shouldReceive('process')
2929
->once()
30-
->withArgs(function (string $controller, string $action, array $parameters, CoreInterface $core) {
31-
return $controller === TestCommand::class
32-
&& $action === 'perform'
33-
&& $parameters['input'] instanceof InputInterface
34-
&& $parameters['output'] instanceof OutputInterface
35-
&& $parameters['command'] instanceof TestCommand;
36-
})
37-
->andReturnUsing(function (string $controller, string $action, array $parameters, CoreInterface $core) {
38-
return $core->callAction($controller, $action, $parameters);
39-
});
30+
->withArgs(fn(string $controller, string $action, array $parameters, CoreInterface $core) => $controller === TestCommand::class
31+
&& $action === 'perform'
32+
&& $parameters['input'] instanceof InputInterface
33+
&& $parameters['output'] instanceof OutputInterface
34+
&& $parameters['command'] instanceof TestCommand)
35+
->andReturnUsing(
36+
fn(
37+
string $controller,
38+
string $action,
39+
array $parameters,
40+
CoreInterface $core,
41+
) => $core->callAction($controller, $action, $parameters),
42+
);
4043

4144
$core = $this->getCore($this->getStaticLocator([
4245
TestCommand::class

src/Console/tests/UpdateTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ public function testNoBreakFailure(): void
122122
$this->assertEquals(1, $output->getCode());
123123
}
124124

125-
/**
126-
* @return Console
127-
*/
128125
private function bindFailure(): Console
129126
{
130127
$core = $this->getCore(

src/Cookies/tests/CookiesTest.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ public function testSetNotProtectedCookie(): void
104104
public function testDecrypt(): void
105105
{
106106
$core = $this->httpCore([CookiesMiddleware::class]);
107-
$core->setHandler(function (ServerRequestInterface $r) {
108-
return $r->getCookieParams()['name'];
109-
});
107+
$core->setHandler(fn(ServerRequestInterface $r) => $r->getCookieParams()['name']);
110108

111109
$value = $this->container->get(EncrypterInterface::class)->encrypt('cookie-value');
112110

@@ -118,9 +116,7 @@ public function testDecrypt(): void
118116
public function testDecryptArray(): void
119117
{
120118
$core = $this->httpCore([CookiesMiddleware::class]);
121-
$core->setHandler(function (ServerRequestInterface $r) {
122-
return $r->getCookieParams()['name'][0];
123-
});
119+
$core->setHandler(fn(ServerRequestInterface $r) => $r->getCookieParams()['name'][0]);
124120

125121
$value[] = $this->container->get(EncrypterInterface::class)->encrypt('cookie-value');
126122

@@ -132,9 +128,7 @@ public function testDecryptArray(): void
132128
public function testDecryptBroken(): void
133129
{
134130
$core = $this->httpCore([CookiesMiddleware::class]);
135-
$core->setHandler(function (ServerRequestInterface $r) {
136-
return $r->getCookieParams()['name'];
137-
});
131+
$core->setHandler(fn(ServerRequestInterface $r) => $r->getCookieParams()['name']);
138132

139133
$value = $this->container->get(EncrypterInterface::class)->encrypt('cookie-value') . 'BROKEN';
140134

@@ -195,9 +189,7 @@ public function testGetUnprotected(): void
195189
]));
196190

197191
$core = $this->httpCore([CookiesMiddleware::class]);
198-
$core->setHandler(function (ServerRequestInterface $r) {
199-
return $r->getCookieParams()['name'];
200-
});
192+
$core->setHandler(fn(ServerRequestInterface $r) => $r->getCookieParams()['name']);
201193

202194
$value = 'cookie-value';
203195

@@ -228,9 +220,7 @@ public function testHMAC(): void
228220
$cookies = $this->fetchCookies($response);
229221
$this->assertArrayHasKey('name', $cookies);
230222

231-
$core->setHandler(function ($r) {
232-
return $r->getCookieParams()['name'];
233-
});
223+
$core->setHandler(fn($r) => $r->getCookieParams()['name']);
234224

235225
$response = $this->get($core, '/', [], [], $cookies);
236226
$this->assertSame(200, $response->getStatusCode());
@@ -286,9 +276,9 @@ private function fetchCookies(ResponseInterface $response): array
286276
foreach ($response->getHeaders() as $line) {
287277
$cookie = explode('=', implode('', $line));
288278
$result[$cookie[0]] = rawurldecode(substr(
289-
(string)$cookie[1],
279+
$cookie[1],
290280
0,
291-
(int)strpos((string)$cookie[1], ';')
281+
(int)strpos($cookie[1], ';')
292282
));
293283
}
294284

src/Cookies/tests/TestResponseFactory.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ final class TestResponseFactory implements ResponseFactoryInterface
1414
/** @var HttpConfig */
1515
protected $config;
1616

17-
/**
18-
* @param HttpConfig $config
19-
*/
2017
public function __construct(HttpConfig $config)
2118
{
2219
$this->config = $config;
2320
}
2421

25-
/**
26-
* @param int $code
27-
* @param string $reasonPhrase
28-
*
29-
* @return ResponseInterface
30-
*/
22+
3123
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
3224
{
3325
$response = new Response($code);

src/Core/tests/BindingsTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public function testBasicBinding(): void
2020

2121
$this->assertFalse($container->has('abc'));
2222

23-
$container->bind('abc', function () {
24-
return 'hello';
25-
});
23+
$container->bind('abc', fn() => 'hello');
2624

2725
$this->assertTrue($container->has('abc'));
2826
$this->assertEquals('hello', $container->get('abc'));
@@ -33,9 +31,7 @@ public function testStringBinding(): void
3331
$container = new Container();
3432

3533
$this->assertFalse($container->has('abc'));
36-
$container->bind('abc', function () {
37-
return 'hello';
38-
});
34+
$container->bind('abc', fn() => 'hello');
3935

4036
$container->bind('dce', 'abc');
4137

src/Core/tests/InjectableTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ public function testInjector(): void
102102
$container->bind(ConfigsInterface::class, $configurator);
103103

104104
$configurator->shouldReceive('createInjection')
105-
->with(m::on(static function (ReflectionClass $r) {
106-
return $r->getName() === TestConfig::class;
107-
}), null)
105+
->with(m::on(static fn(ReflectionClass $r) => $r->getName() === TestConfig::class), null)
108106
->andReturn($expected);
109107

110108
$this->assertSame($expected, $container->get(TestConfig::class));
@@ -119,9 +117,7 @@ public function testInjectorWithContext(): void
119117
$container->bind(ConfigsInterface::class, $configurator);
120118

121119
$configurator->shouldReceive('createInjection')
122-
->with(m::on(static function (ReflectionClass $r) {
123-
return $r->getName() === TestConfig::class;
124-
}), 'context')
120+
->with(m::on(static fn(ReflectionClass $r) => $r->getName() === TestConfig::class), 'context')
125121
->andReturn($expected);
126122

127123
$this->assertSame($expected, $container->get(TestConfig::class, 'context'));
@@ -236,9 +232,6 @@ public function createInjection(\ReflectionClass $class, mixed $context = null):
236232
$this->assertInstanceOf(\ReflectionParameter::class, $result->context);
237233
}
238234

239-
/**
240-
* @param TestConfig $contextArgument
241-
*/
242235
private function methodInjection(TestConfig $contextArgument): void
243236
{
244237
}

src/Core/tests/InvokerTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public function testCallValidClosure(): void
9595
$this->container->bindSingleton(Bucket::class, $bucket = new Bucket('foo'));
9696

9797
$result = $this->container->invoke(
98-
static function (Bucket $bucket, SampleClass $class, string $name, string $path = 'baz') {
99-
return \compact('bucket', 'class', 'name', 'path');
100-
},
98+
static fn(Bucket $bucket, SampleClass $class, string $name, string $path = 'baz') => \compact('bucket', 'class', 'name', 'path'),
10199
['name' => 'bar']
102100
);
103101

@@ -113,9 +111,7 @@ public function testCallValidClosureWithNotResolvableDependencies(): void
113111
$this->expectExceptionMessage('Unable to resolve required argument `name` when resolving');
114112

115113
$this->container->invoke(
116-
static function (Bucket $bucket, SampleClass $class, string $name, string $path = 'baz') {
117-
return \compact('bucket', 'class', 'name', 'path');
118-
},
114+
static fn(Bucket $bucket, SampleClass $class, string $name, string $path = 'baz') => \compact('bucket', 'class', 'name', 'path'),
119115
['name' => 'bar']
120116
);
121117
}

0 commit comments

Comments
 (0)