Skip to content

Commit

Permalink
refactor: enable phpunit code quality set for rector (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 4, 2025
1 parent b7f1dc0 commit 0d92d6f
Show file tree
Hide file tree
Showing 27 changed files with 262 additions and 308 deletions.
24 changes: 12 additions & 12 deletions tests/CallableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function testFunctionRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('hello world', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('hello world', (string)$response->getBody());
}

public function testObjectRoute(): void
Expand All @@ -33,8 +33,8 @@ public function testObjectRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('invoked', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('invoked', (string)$response->getBody());
}

public function testObjectViaContainerRoute(): void
Expand All @@ -46,8 +46,8 @@ public function testObjectViaContainerRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('invoked', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('invoked', (string)$response->getBody());
}

public function testHandlerRoute(): void
Expand All @@ -59,8 +59,8 @@ public function testHandlerRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('handler', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('handler', (string)$response->getBody());
}

public function testHandlerViaContainerRoute(): void
Expand All @@ -72,8 +72,8 @@ public function testHandlerViaContainerRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('handler', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('handler', (string)$response->getBody());
}

public function testInvalidTarget(): void
Expand All @@ -87,7 +87,7 @@ public function testInvalidTarget(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/something')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('handler', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('handler', (string)$response->getBody());
}
}
32 changes: 16 additions & 16 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public function testRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/test')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('hello world', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('hello world', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/echo')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('echoed', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('echoed', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/id/888')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('888', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('888', (string)$response->getBody());
}

public function testOptionalParam(): void
Expand All @@ -63,12 +63,12 @@ public function testOptionalParam(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/default')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('default', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('default', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/default/123')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('123', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('123', (string)$response->getBody());
}

public function testFallbackHandler(): void
Expand All @@ -92,12 +92,12 @@ public function testOptionalParamWithDefaultInt(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/defaultInt')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('int: 1', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('int: 1', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/defaultInt/123')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('string: 123', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('string: 123', (string)$response->getBody());
}

public function testUriGeneration(): void
Expand All @@ -109,10 +109,10 @@ public function testUriGeneration(): void
);

$uri = $router->uri('action/test');
$this->assertSame('/test', $uri->getPath());
self::assertSame('/test', $uri->getPath());

$uri = $router->uri('action/id', ['id' => 100]);
$this->assertSame('/id/100', $uri->getPath());
self::assertSame('/id/100', $uri->getPath());
}

public function testClientException(): void
Expand Down
22 changes: 11 additions & 11 deletions tests/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testAutoCore(): void
$action = new Action(TestController::class, 'test');
$handler = $action->getHandler($this->getContainer(), []);

$this->assertInstanceOf(CoreHandler::class, $handler);
self::assertInstanceOf(CoreHandler::class, $handler);
}

public function testWithAutoCore(): void
Expand All @@ -53,11 +53,11 @@ public function testWithAutoCore(): void
$action = $action->withCore(new TestCore($this->getContainer()->get(CoreInterface::class)));

$handler = $action->getHandler($this->getContainer(), []);
$this->assertInstanceOf(CoreHandler::class, $handler);
self::assertInstanceOf(CoreHandler::class, $handler);

$result = $handler->handle(new ServerRequest('GET', ''));

$this->assertSame('@wrapped.hello world', (string)$result->getBody());
self::assertSame('@wrapped.hello world', (string)$result->getBody());
}

public function testErrAction(): void
Expand All @@ -70,7 +70,7 @@ public function testErrAction(): void
$action = $action->withCore(new TestCore($this->getContainer()->get(CoreInterface::class)));

$handler = $action->getHandler($this->getContainer(), []);
$this->assertInstanceOf(CoreHandler::class, $handler);
self::assertInstanceOf(CoreHandler::class, $handler);

$handler->handle(new ServerRequest('GET', ''));
}
Expand All @@ -80,24 +80,24 @@ public function testRSP(): void
$action = new Action(TestController::class, 'rsp');

$handler = $action->getHandler($this->getContainer(), []);
$this->assertInstanceOf(CoreHandler::class, $handler);
self::assertInstanceOf(CoreHandler::class, $handler);

$result = $handler->handle(new ServerRequest('GET', ''));

$this->assertSame('rspbuf', (string)$result->getBody());
self::assertSame('rspbuf', (string)$result->getBody());
}

public function testJson(): void
{
$action = new Action(TestController::class, 'json');

$handler = $action->getHandler($this->getContainer(), []);
$this->assertInstanceOf(CoreHandler::class, $handler);
self::assertInstanceOf(CoreHandler::class, $handler);

$result = $handler->handle(new ServerRequest('GET', ''));

$this->assertSame(301, $result->getStatusCode());
$this->assertSame('{"status":301,"msg":"redirect"}', (string)$result->getBody());
self::assertSame(301, $result->getStatusCode());
self::assertSame('{"status":301,"msg":"redirect"}', (string)$result->getBody());
}

public function testForbidden(): void
Expand Down Expand Up @@ -138,10 +138,10 @@ public function testRESTFul(): void
$action = new Action(TestController::class, 'Target', Action::RESTFUL);
$r = $action->getHandler($this->getContainer(), [])->handle(new ServerRequest('POST', ''));

$this->assertSame('POST', (string)$r->getBody());
self::assertSame('POST', (string)$r->getBody());

$r = $action->getHandler($this->getContainer(), [])->handle(new ServerRequest('DELETE', ''));

$this->assertSame('DELETE', (string)$r->getBody());
self::assertSame('DELETE', (string)$r->getBody());
}
}
11 changes: 4 additions & 7 deletions tests/DefaultPatternRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ public function testAll(): void
$registry->register('foo', '\d+');
$registry->register('bar', '\d+');

$this->assertSame(
self::DEFAULT_PATTERNS + [
'foo' => '\d+',
'bar' => '\d+'
],
$registry->all()
);
self::assertSame(self::DEFAULT_PATTERNS + [
'foo' => '\d+',
'bar' => '\d+'
], $registry->all());
}
}
8 changes: 4 additions & 4 deletions tests/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public function testRoute(): void
);

$response = $router->handle(new ServerRequest('GET', new Uri('/test')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('hello world', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('hello world', (string)$response->getBody());

$response = $router->handle(new ServerRequest('GET', new Uri('/test/id/900')));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('900', (string)$response->getBody());
self::assertSame(200, $response->getStatusCode());
self::assertSame('900', (string)$response->getBody());
}

public function testRouteOther(): void
Expand Down
16 changes: 6 additions & 10 deletions tests/HostsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ public function testRoute(): void
new Action(TestController::class, 'test')
));

$this->assertNotNull(
$r = $router->handle(new ServerRequest('GET', 'http://domain.com/'))
);
self::assertNotNull($r = $router->handle(new ServerRequest('GET', 'http://domain.com/')));

$this->assertSame(200, $r->getStatusCode());
$this->assertSame('hello world', (string)$r->getBody());
self::assertSame(200, $r->getStatusCode());
self::assertSame('hello world', (string)$r->getBody());

$this->assertNotNull(
$r = $router->handle(new ServerRequest('GET', 'https://domain.com/'))
);
self::assertNotNull($r = $router->handle(new ServerRequest('GET', 'https://domain.com/')));

$this->assertSame(200, $r->getStatusCode());
$this->assertSame('hello world', (string)$r->getBody());
self::assertSame(200, $r->getStatusCode());
self::assertSame('hello world', (string)$r->getBody());
}
}
Loading

0 comments on commit 0d92d6f

Please sign in to comment.