Skip to content

Commit e9d1cd1

Browse files
committed
Refactored test methods
2 parents 1b5dbf4 + 988ba7c commit e9d1cd1

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

tests/AppHandlerIntegrationTest.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@
2121

2222
class AppHandlerIntegrationTest extends TestCase
2323
{
24-
public function testInstantiation()
24+
public function test_Instantiation()
2525
{
2626
$this->assertInstanceOf(AppHandler::class, $this->app());
2727
}
2828

29-
public function testConfig_ReturnsSetupEntry()
29+
public function test_Config_ReturnsSetupEntry()
3030
{
3131
$app = $this->app();
3232
$this->assertInstanceOf(Container\Setup\Entry::class, $app->config('test'));
3333
}
3434

35-
public function testRoutingContainerIntegration()
35+
public function test_RoutingContainerIntegration()
3636
{
3737
$app = $this->app(['test' => new Container\Records\Record\ValueRecord('Hello World!')]);
3838
$response = $app->handle(new Doubles\FakeServerRequest());
3939
$this->assertSame('//example.com/foo/bar: Hello World!', (string) $response->getBody());
4040
}
4141

42-
public function testRepeatedHandleCallsWithMiddlewareProcessing_ReturnsEqualResponse()
42+
public function test_RepeatedHandleCalls_WithMiddlewareProcessing_ReturnEqualResponse()
4343
{
4444
$app = $this->middlewareContextsApp();
4545
$request = new Doubles\FakeServerRequest('GET', Doubles\FakeUri::fromString('/test'));
@@ -50,13 +50,13 @@ public function testRepeatedHandleCallsWithMiddlewareProcessing_ReturnsEqualResp
5050
$this->assertEquals($response, $app->handle($request));
5151
}
5252

53-
public function testInstanceWithDefinedInternalContainerId_ThrowsException()
53+
public function test_InstanceWithDefinedInternalContainerId_ThrowsException()
5454
{
5555
$this->expectException(Container\Setup\Exception\OverwriteRuleException::class);
5656
$this->app([AppHandler::ROUTER_ID => new Container\Records\Record\ValueRecord('Hello World!')]);
5757
}
5858

59-
public function testFallbackNotFoundRoute()
59+
public function test_FallbackNotFoundRoute()
6060
{
6161
$app = $this->app();
6262
$app->routeFound = false;
@@ -67,7 +67,7 @@ public function testFallbackNotFoundRoute()
6767
$this->assertSame($app->notFoundResponse, $response);
6868
}
6969

70-
public function testShutdownRegisteredOnProduction()
70+
public function test_ShutdownRegistered_OnProduction()
7171
{
7272
Fixtures\ShutdownState::reset();
7373
Fixtures\ShutdownState::$override = true;
@@ -80,7 +80,7 @@ public function testShutdownRegisteredOnProduction()
8080
$this->assertTrue(Fixtures\ShutdownState::$outputBufferCleared);
8181
}
8282

83-
public function testShutdownNotRegisteredOnDevelopment()
83+
public function test_ShutdownNotRegistered_OnDevelopment()
8484
{
8585
Fixtures\ShutdownState::reset();
8686
Fixtures\ShutdownState::$override = true;
@@ -90,20 +90,19 @@ public function testShutdownNotRegisteredOnDevelopment()
9090
$this->assertFalse(is_callable(Fixtures\ShutdownState::$callback));
9191
}
9292

93-
private function app(array $records = [], bool $secure = false): Doubles\MockedAppHandler
93+
private function app(array $records = []): Doubles\MockedAppHandler
9494
{
95-
$setup = $secure ? new Container\Setup\Build\ValidatedBuild($records) : new Container\Setup\Build($records);
96-
return new Doubles\MockedAppHandler($setup);
95+
return new Doubles\MockedAppHandler(new Container\Setup\Build($records));
9796
}
9897

9998
private function middlewareContextsApp(): Doubles\MockedAppHandler
10099
{
101100
$app = $this->app();
102101
$app->config('test')->value('MAIN');
103102
$app->middleware('one')->value(new Doubles\FakeMiddleware('outerContext'));
104-
$app->middleware('two')->callback(function ($c) {
105-
return new Doubles\FakeMiddleware($c->get('one')->inContext ? 'innerContext' : '--- error ---');
106-
});
103+
$app->middleware('two')->callback(
104+
fn ($c) => new Doubles\FakeMiddleware($c->get('one')->inContext ? 'innerContext' : '--- error ---')
105+
);
107106

108107
return $app;
109108
}

tests/ServerProcessTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@
2020

2121
class ServerProcessTest extends TestCase
2222
{
23-
public function testInstantiation()
23+
public function test_Instantiation()
2424
{
2525
$this->assertInstanceOf(ServerProcess::class, $this->server());
2626
}
2727

28-
public function testResponseBodyIsEmitted()
28+
public function test_ResponseBody_IsEmitted()
2929
{
3030
$server = $this->server(new Doubles\FakeResponse('Hello World!'));
3131
$this->assertSame('Hello World!', $this->emit($server));
3232
}
3333

34-
public function testResponseBodyExceedingOutputBufferIsEmitted()
34+
public function test_ResponseBodyExceedingOutputBuffer_IsEmitted()
3535
{
3636
$response = new Doubles\FakeResponse('Hello World');
3737
$server = $this->server($response, 3);
3838
$this->assertSame('Hello World', $this->emit($server));
3939
}
4040

41-
public function testSendResponseWhenHeadersAlreadySent_ThrowsException()
41+
public function test_SendResponse_WhenHeadersAlreadySent_ThrowsException()
4242
{
4343
$server = $this->server();
4444

@@ -47,7 +47,7 @@ public function testSendResponseWhenHeadersAlreadySent_ThrowsException()
4747
$this->emit($server);
4848
}
4949

50-
public function testHeadersAreEmitted()
50+
public function test_Headers_AreEmitted()
5151
{
5252
$response = new Doubles\FakeResponse();
5353

@@ -70,7 +70,7 @@ public function testHeadersAreEmitted()
7070
$this->assertSame($expected, Fixtures\HeadersState::$headers);
7171
}
7272

73-
public function testHeadersSetOutsideServerInstanceAreIgnored()
73+
public function test_HeadersSetOutsideServerInstance_AreIgnored()
7474
{
7575
$response = new Doubles\FakeResponse();
7676
$server = $this->server($response);
@@ -94,9 +94,7 @@ public function testHeadersSetOutsideServerInstanceAreIgnored()
9494
private function server(?Doubles\FakeResponse $response = null, int $buffer = 0): ServerProcess
9595
{
9696
Fixtures\HeadersState::reset();
97-
$requestHandler = new Doubles\FakeRequestHandler(function () use ($response) {
98-
return $response ?: new Doubles\FakeResponse();
99-
});
97+
$requestHandler = new Doubles\FakeRequestHandler(fn () => $response ?: new Doubles\FakeResponse());
10098
return new ServerProcess($requestHandler, $buffer);
10199
}
102100

0 commit comments

Comments
 (0)