Skip to content

Commit

Permalink
code sniffer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattvb91 committed Nov 1, 2023
1 parent 511e39f commit 753c693
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 89 deletions.
153 changes: 90 additions & 63 deletions tests/Integration/CaddyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CaddyTest extends TestCase
/**
* @covers \mattvb91\CaddyPhp\Caddy::load
*/
public function test_can_load_config(): void
public function testCanLoadConfig(): void
{
$caddy = new Caddy();

Expand All @@ -31,11 +31,12 @@ public function test_can_load_config(): void
/**
* @coversNothing
*/
public function test_can_load_with_logs(): void
public function testCanLoadWithLogs(): void
{
$caddy = new Caddy();
$caddy->setLogging((new Logging())
->addLog(new Log())
$caddy->setLogging(
(new Logging())
->addLog(new Log())
);

$this->assertTrue($caddy->load());
Expand All @@ -44,14 +45,16 @@ public function test_can_load_with_logs(): void
/**
* @coversNothing
*/
public function test_can_load_with_http_app(): void
public function testCanLoadWithHttpApp(): void
{
$caddy = new Caddy();
$caddy->addApp(
(new Http())->addServer(
'server1', (new Http\Server())->addRoute(
(new Route())
))
'server1',
(new Http\Server())->addRoute(
(new Route())
)
)
);

$this->assertTrue($caddy->load());
Expand All @@ -60,16 +63,18 @@ public function test_can_load_with_http_app(): void
/**
* @coversNothing
*/
public function test_can_load_static_response_app(): void
public function testCanLoadStaticResponseApp(): void
{
$caddy = new Caddy();
$caddy->addApp(
(new Http())->addServer(
'server1', (new Http\Server())->addRoute(
(new Route())->addHandle(
new StaticResponse('phpunit', 200)
'server1',
(new Http\Server())->addRoute(
(new Route())->addHandle(
new StaticResponse('phpunit', 200)
)
)
))
)
);

$this->assertTrue($caddy->load());
Expand All @@ -89,23 +94,28 @@ public function test_can_load_static_response_app(): void
* @covers \mattvb91\CaddyPhp\Caddy::removeHostname
* @covers \mattvb91\CaddyPhp\findHost
*/
public function test_can_add_remove_hosts()
public function testCanAddRemoveHosts()
{
$caddy = new Caddy();
$caddy->addApp(
(new Http())->addServer(
'server1', (new Http\Server())->addRoute(
(new Route())->addHandle(
new StaticResponse('host test', 200)
)->addMatch((new Host('main'))
->setHosts(['test.localhost'])
)
)->addRoute((new Route())
->addHandle(new StaticResponse('Not found', 404))
->addMatch((new Host('notFound'))
->setHosts(['*.localhost'])
'server1',
(new Http\Server())->addRoute(
(new Route())->addHandle(
new StaticResponse('host test', 200)
)->addMatch(
(new Host('main'))
->setHosts(['test.localhost'])
)
)->addRoute(
(new Route())
->addHandle(new StaticResponse('Not found', 404))
->addMatch(
(new Host('notFound'))
->setHosts(['*.localhost'])
)
)
))
)
);

$this->assertTrue($caddy->load());
Expand Down Expand Up @@ -159,22 +169,25 @@ public function test_can_add_remove_hosts()
/**
* @covers \mattvb91\CaddyPhp\Caddy::syncHosts
*/
public function test_sync_hosts_works()
public function testSyncHostsWorks()
{
$caddy = new Caddy();
$caddy->addApp(
(new Http())->addServer(
'server1', (new Http\Server())->addRoute(
(new Route())->addHandle(
new StaticResponse('host test', 200)
)->addMatch((new Host('main'))
->setHosts([
'test.localhost',
'test2.localhost',
'localhost',
])
'server1',
(new Http\Server())->addRoute(
(new Route())->addHandle(
new StaticResponse('host test', 200)
)->addMatch(
(new Host('main'))
->setHosts([
'test.localhost',
'test2.localhost',
'localhost',
])
)
)
))
)
);
$caddy->load();

Expand All @@ -183,11 +196,13 @@ public function test_sync_hosts_works()
$mainHost = new Host('main');
$caddy->addApp(
(new Http())->addServer(
'server1', (new Http\Server())->addRoute(
(new Route())->addHandle(
new StaticResponse('host test', 200)
)->addMatch($mainHost)
))
'server1',
(new Http\Server())->addRoute(
(new Route())->addHandle(
new StaticResponse('host test', 200)
)->addMatch($mainHost)
)
)
);

$caddy->syncHosts('main');
Expand All @@ -197,24 +212,31 @@ public function test_sync_hosts_works()
/**
* @coversNothing
*/
public function test_http_basic_auth()
public function testHttpBasicAuth()
{
$caddy = new Caddy();
$caddy->addApp(
(new Http())->addServer(
'server1', (new Http\Server())->addRoute(
(new Route())
->addHandle((new Authentication())
->addProvider((new HttpBasic())
->addAccount(new Account('test', 'test123'))))
->addHandle(
new StaticResponse('auth test', 200)
)->addMatch((new Host('main'))
->setHosts([
'localhost',
])
)
))
'server1',
(new Http\Server())->addRoute(
(new Route())
->addHandle(
(new Authentication())
->addProvider(
(new HttpBasic())
->addAccount(new Account('test', 'test123'))
)
)
->addHandle(
new StaticResponse('auth test', 200)
)->addMatch(
(new Host('main'))
->setHosts([
'localhost',
])
)
)
)
);
$caddy->load();

Expand All @@ -236,7 +258,6 @@ public function test_http_basic_auth()
],
]);
$this->assertEquals(200, $request->getStatusCode());

}

/**
Expand Down Expand Up @@ -278,16 +299,22 @@ public function test_http_basic_auth()
/**
* @covers \mattvb91\CaddyPhp\Caddy::getRemoteConfig
*/
public function test_caddy_get_config()
public function testCaddyGetConfig()
{
$caddy = new Caddy();
$caddy->addApp((new Http())
->addServer('test', (new Http\Server())
->addRoute((new Route())
->addHandle((new StaticResponse('test'))))));
$caddy->addApp(
(new Http())
->addServer(
'test',
(new Http\Server())
->addRoute(
(new Route())
->addHandle((new StaticResponse('test')))
)
)
);
$caddy->load();

$this->assertEquals(json_decode(json_encode($caddy->toArray())), $caddy->getRemoteConfig());
}

}
}
16 changes: 9 additions & 7 deletions tests/Unit/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ class CacheTest extends TestCase
* @covers \mattvb91\CaddyPhp\Config\Apps\Cache\Api\Souin::toArray
* @covers \mattvb91\CaddyPhp\Config\Apps\Cache\Api\Souin::setEnable
*/
public function test_api()
public function testApi()
{
$api = new Api((new Api\Souin())
->setBasePath('/test2')
->setEnable(false));
$api = new Api(
(new Api\Souin())
->setBasePath('/test2')
->setEnable(false)
);
$api->setBasePath('/test');

$this->assertEquals([
'basepath' => '/test',
'souin' => [
'basepath' => '/test2',
'enable' => false
]
'enable' => false,
],
], $api->toArray());
}
}
}
29 changes: 18 additions & 11 deletions tests/Unit/CaddyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CaddyTest extends TestCase
* @covers \mattvb91\CaddyPhp\Caddy::getClient
* @covers \mattvb91\CaddyPhp\Caddy::__construct
*/
public function test_can_instantiate(): void
public function testCanInstantiate(): void
{
$caddy = new Caddy();
$this->assertInstanceOf(Caddy::class, $caddy);
Expand All @@ -49,13 +49,14 @@ public function test_can_instantiate(): void
* @covers \mattvb91\CaddyPhp\Config\Apps\Http::setGracePeriod
* @covers \mattvb91\CaddyPhp\Config\Apps\Http::toArray
*/
public function test_can_add_app()
public function testCanAddApp()
{
$caddy = new Caddy();
$caddy->addApp((new Http())
->setHttpPort(1)
->setHttpsPort(2)
->setGracePeriod(3)
$caddy->addApp(
(new Http())
->setHttpPort(1)
->setHttpsPort(2)
->setGracePeriod(3)
)->addApp(new Tls());

self::assertArraySubset([
Expand All @@ -74,11 +75,17 @@ public function test_can_add_app()
/**
* @covers \mattvb91\CaddyPhp\Caddy::load
*/
public function test_client_exception()
public function testClientException()
{
/** @var MockObject|Caddy $mockClient */
$mockClient = $this->createPartialMock(Client::class, ['post']);
$mockClient->method('post')->willThrowException(new ClientException('error', new Request('post', '/'), new Response(500)));
$mockClient->method('post')->willThrowException(
new ClientException(
'error',
new Request('post', '/'),
new Response(500)
)
);
$this->expectException(CaddyClientException::class);

$caddy = new Caddy(client: $mockClient);
Expand All @@ -91,7 +98,7 @@ public function test_client_exception()
* @covers \mattvb91\CaddyPhp\Config\Admin::toArray
* @covers \mattvb91\CaddyPhp\Config\Admin::getListen
*/
public function test_admin()
public function testAdmin()
{
$admin = (new Admin())
->setDisabled(true)
Expand All @@ -108,7 +115,7 @@ public function test_admin()
* @covers \mattvb91\CaddyPhp\Config\Apps\Http\Server::setListen
* @covers \mattvb91\CaddyPhp\Config\Apps\Http\Server::addRoute
*/
public function test_server()
public function testServer()
{
$server = (new Http\Server())
->setListen([':122'])
Expand All @@ -123,4 +130,4 @@ public function test_server()
],
], $server->toArray());
}
}
}
8 changes: 3 additions & 5 deletions tests/Unit/LoggingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class LoggingTest extends TestCase
* @covers \mattvb91\CaddyPhp\Caddy::setLogging
* @covers \mattvb91\CaddyPhp\Caddy::toArray
*/
public function test_adding_default_log()
public function testAddingDefaultLog()
{
$caddy = new Caddy();
$caddy->setLogging((new Logging())
->addLog(new Log())
);
->addLog(new Log()));

$this->assertEquals([
'logs' => [
Expand All @@ -29,5 +28,4 @@ public function test_adding_default_log()
]
], $caddy->toArray()['logging']);
}

}
}
Loading

0 comments on commit 753c693

Please sign in to comment.