Skip to content

Commit

Permalink
Improve type hinting in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Dec 26, 2023
1 parent cc46a04 commit a7f272b
Show file tree
Hide file tree
Showing 32 changed files with 192 additions and 284 deletions.
35 changes: 16 additions & 19 deletions tests/Application/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Rougin\Slytherin\Dispatching\Phroute\Router as PhrouteRouter;
use Rougin\Slytherin\Dispatching\Vanilla\Router;
use Rougin\Slytherin\Http\Uri;
use Rougin\Slytherin\IoC\Vanilla\Container;
use Rougin\Slytherin\Testcase;

/**
Expand Down Expand Up @@ -57,7 +56,7 @@ public function testRunMethod()
{
$this->expectOutputString('Hello');

$this->runApplication('GET', '/')->run();
$this->setUrl('GET', '/')->run();
}

/**
Expand All @@ -70,7 +69,7 @@ public function testRunMethodWithResponse()
{
$this->expectOutputString('Hello with response');

$this->runApplication('GET', '/hello')->run();
$this->setUrl('GET', '/hello')->run();
}

/**
Expand All @@ -83,7 +82,7 @@ public function testRunMethodWithParameter()
{
$this->expectOutputString('Hello');

$this->runApplication('GET', '/parameter')->run();
$this->setUrl('GET', '/parameter')->run();
}

/**
Expand All @@ -96,7 +95,7 @@ public function testRunMethodWithOptionalParameter()
{
$this->expectOutputString('Hello');

$this->runApplication('GET', '/optional')->run();
$this->setUrl('GET', '/optional')->run();
}

/**
Expand All @@ -109,7 +108,7 @@ public function testRunMethodWithCallback()
{
$this->expectOutputString('Hello');

$this->runApplication('GET', '/callback')->run();
$this->setUrl('GET', '/callback')->run();
}

/**
Expand All @@ -122,7 +121,7 @@ public function testRunMethodWithPutHttpMethod()
{
$this->expectOutputString('Hello from PUT HTTP method');

$this->runApplication('PUT', '/hello', array('_method' => 'PUT'))->run();
$this->setUrl('PUT', '/hello', array('_method' => 'PUT'))->run();
}

/**
Expand All @@ -133,10 +132,12 @@ public function testRunMethodWithPutHttpMethod()
*/
public function testRunMethodWithPhroute()
{
// @codeCoverageIgnoreStart
if (! class_exists('Phroute\Phroute\RouteCollector'))
{
$this->markTestSkipped('Phroute is not installed.');
}
// @codeCoverageIgnoreEnd

$this->expectOutputString('Hello');

Expand All @@ -150,7 +151,7 @@ public function testRunMethodWithPhroute()

$this->components->setDispatcher($dispatcher);

$this->runApplication('GET', '/')->run();
$this->setUrl('GET', '/')->run();
}

/**
Expand Down Expand Up @@ -200,7 +201,7 @@ public function testRunMethodWithIntegrateMethod()
* @param array<string, string> $data
* @return \Rougin\Slytherin\Application
*/
private function runApplication($method, $uri, $data = array())
private function setUrl($method, $uri, $data = array())
{
$result = $this->components->getHttp();

Expand All @@ -214,18 +215,14 @@ private function runApplication($method, $uri, $data = array())

$request = $request->withMethod($method)->withUri($uri);

switch ($method)
if ($method === 'GET')
{
case 'GET':
$request = $request->withQueryParams($data);

break;
case 'POST':
case 'PUT':
case 'DELETE':
$request = $request->withParsedBody($data);
$request = $request->withQueryParams($data);
}

break;
if (in_array($method, array('POST', 'PUT', 'DELETE')))
{
$request = $request->withParsedBody($data);
}

$this->components->setHttp($request, $response);
Expand Down
18 changes: 8 additions & 10 deletions tests/Application/ApplicationTestCases.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class ApplicationTestCases extends Testcase
*/
protected function doSetUp()
{
// @codeCoverageIgnoreStart
$this->markTestSkipped('No implementation style defined.');
// @codeCoverageIgnoreEnd
}

/**
Expand Down Expand Up @@ -242,18 +244,14 @@ protected function request($method, $uri, $data = array(), $server = array())

$request = new ServerRequest($server);

switch ($method)
if ($method === 'GET')
{
case 'GET':
$request = $request->withQueryParams($data);

break;
case 'POST':
case 'PUT':
case 'DELETE':
$request = $request->withParsedBody($data);
$request = $request->withQueryParams($data);
}

break;
if (in_array($method, array('POST', 'PUT', 'DELETE')))
{
$request = $request->withParsedBody($data);
}

return $request;
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/AurynContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ class AurynContainerTest extends ApplicationTestCases
*/
protected function doSetUp()
{
// @codeCoverageIgnoreStart
if (! class_exists('Auryn\Injector'))
{
$this->markTestSkipped('Auryn is not installed.');
}
// @codeCoverageIgnoreEnd

$container = new AurynContainer(new Injector);

Expand Down
20 changes: 9 additions & 11 deletions tests/Application/IntegrationInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,21 @@ class IntegrationInterfaceTest extends ApplicationTestCases
*/
protected function doSetUp()
{
$integrations = array();
$items = array();

$integrations[] = 'Rougin\Slytherin\Debug\ErrorHandlerIntegration';
$integrations[] = 'Rougin\Slytherin\Http\HttpIntegration';
$integrations[] = 'Rougin\Slytherin\Routing\RoutingIntegration';
$integrations[] = 'Rougin\Slytherin\Middleware\MiddlewareIntegration';
$integrations[] = 'Rougin\Slytherin\Template\RendererIntegration';
$integrations[] = 'Rougin\Slytherin\Integration\ConfigurationIntegration';
$items[] = 'Rougin\Slytherin\Debug\ErrorHandlerIntegration';
$items[] = 'Rougin\Slytherin\Http\HttpIntegration';
$items[] = 'Rougin\Slytherin\Routing\RoutingIntegration';
$items[] = 'Rougin\Slytherin\Middleware\MiddlewareIntegration';
$items[] = 'Rougin\Slytherin\Template\RendererIntegration';
$items[] = 'Rougin\Slytherin\Integration\ConfigurationIntegration';

$config = new Configuration;

$router = $this->router();

$config->set('app.router', $router);
$config->set('app.router', $this->router());

$app = new Application;

$this->application = $app->integrate($integrations, $config);
$this->application = $app->integrate($items, $config);
}
}
4 changes: 4 additions & 0 deletions tests/Component/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@ public function testSetHttpResponseMethod()
*/
public function testSetMiddlewareMethod()
{
// @codeCoverageIgnoreStart
if (! Interop::exists())
{
$this->markTestSkipped('Interop middleware/s not yet installed');
}
// @codeCoverageIgnoreEnd

$expected = new VanillaMiddleware;

Expand All @@ -213,10 +215,12 @@ public function testSetTemplateMethod()
{
$twig = new TwigLoader;

// @codeCoverageIgnoreStart
if (! $twig->exists())
{
$this->markTestSkipped('Twig is not installed.');
}
// @codeCoverageIgnoreEnd

/** @var string */
$path = realpath(__DIR__ . '/../../Fixture/Templates');
Expand Down
7 changes: 6 additions & 1 deletion tests/Container/AurynContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class AurynContainerTest extends \Rougin\Slytherin\Testcase
*/
protected function doSetUp()
{
class_exists('Auryn\Injector') || $this->markTestSkipped('Auryn is not installed.');
// @codeCoverageIgnoreStart
if (! class_exists('Auryn\Injector'))
{
$this->markTestSkipped('Auryn is not installed.');
}
// @codeCoverageIgnoreEnd

$this->container = new \Rougin\Slytherin\Container\AurynContainer(new \Auryn\Injector);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Container/LeagueContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class LeagueContainerTest extends Testcase
*/
protected function doSetUp()
{
// @codeCoverageIgnoreStart
if (! class_exists('League\Container\Container'))
{
$this->markTestSkipped('League Container is not installed.');
}
// @codeCoverageIgnoreEnd

$this->container = new LeagueContainer;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Debug/Whoops/DebuggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class DebuggerTest extends Testcase
*/
protected function doSetUp()
{
// @codeCoverageIgnoreStart
if (! class_exists('Whoops\Run'))
{
$this->markTestSkipped('Whoops is not installed.');
}
// @codeCoverageIgnoreEnd

$this->debugger = new Debugger(new \Whoops\Run);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Dispatching/FastRoute/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class DispatcherTest extends Testcase
*/
protected function doSetUp()
{
// @codeCoverageIgnoreStart
if (! interface_exists('FastRoute\Dispatcher'))
{
$this->markTestSkipped('FastRoute is not installed.');
}
// @codeCoverageIgnoreEnd

$middleware = 'Rougin\Slytherin\Fixture\Middlewares\LastMiddleware';

Expand Down
2 changes: 2 additions & 0 deletions tests/Dispatching/FastRoute/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class RouterTest extends Testcase
*/
protected function doSetUp()
{
// @codeCoverageIgnoreStart
if (! class_exists('FastRoute\RouteCollector'))
{
$this->markTestSkipped('FastRoute is not installed.');
}
// @codeCoverageIgnoreEnd

// Generate a sample route for testing --------------
$class = 'Rougin\Slytherin\Fixture\Classes\NewClass';
Expand Down
2 changes: 2 additions & 0 deletions tests/Dispatching/Phroute/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class DispatcherTest extends Testcase
*/
protected function doSetUp()
{
// @codeCoverageIgnoreStart
if (! class_exists('Phroute\Phroute\Dispatcher'))
{
$this->markTestSkipped('Phroute is not installed.');
}
// @codeCoverageIgnoreEnd

$routes = array();
$routes[] = array('GET', '/', array('Rougin\Slytherin\Fixture\Classes\NewClass', 'index'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Dispatching/Phroute/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class RouterTest extends Testcase
*/
protected function doSetUp()
{
// @codeCoverageIgnoreStart
if (! class_exists('Phroute\Phroute\RouteCollector'))
{
$this->markTestSkipped('Phroute is not installed.');
}
// @codeCoverageIgnoreEnd

// Generate a sample route for testing --------------
$class = 'Rougin\Slytherin\Fixture\Classes\NewClass';
Expand Down
44 changes: 0 additions & 44 deletions tests/Fixture/Classes/Container.php

This file was deleted.

Loading

0 comments on commit a7f272b

Please sign in to comment.