Skip to content

Commit

Permalink
Redo basis of unit test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ralflang committed Aug 5, 2021
1 parent be3e102 commit 77f413a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 38 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"role": "lead"
}
],
"time": "2021-07-16",
"time": "2021-08-05",
"repositories": [
{
"type": "composer",
Expand All @@ -35,5 +35,10 @@
"psr-4": {
"Horde\\Http\\Server\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Horde\\Http\\Server\\Test\\": "test/"
}
}
}
37 changes: 25 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/Horde/Http/Server/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">lib</directory>
</include>
</coverage>
<testsuites>
<testsuite name="horde/Http/Server">
<directory>test</directory>
</testsuite>
</testsuites>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="test/bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="horde/http_server">
<directory>test</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
20 changes: 10 additions & 10 deletions src/RampageRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@

/**
* The Rampage request handler.
*
*
* Enqueue any list of middleware and optionally a payload request handler.
*
*
* Each middleware a request passes may change the request details,
* add middleware to the bottom of the queue or cause side effects.
*
*
* Calculated, loaded or derived data may be stored in a request attribute.
*
*
* The list of middleware will be processed until a response is returned or
* the list has been consumed. In this case, a payload request handler will
* produce the initial Response object. If there is no payload request handler,
* the RampageRequestHandler itself will create a very simple response.
*
*
* Once a response is returned, the response object passes back through
* all the previous layers and may be changed by them or cause side effects.
*
*
* The final response returned by RampageRequestHandler should
*
*
* Note that middlewares or the payload could themselves delegate their
* duties to other middlewares, handlers or other code
*/
Expand Down Expand Up @@ -80,13 +80,13 @@ public function nextMiddleware(): ?MiddlewareInterface

/**
* Handle a request
*
*
* Each middleware will either create a response or
* return control to the handler.
*
*
* If the middlewares created no response,
* the payload handler will.
*
*
* Finally the we will return a response ourselves.
*/
public function handle(RequestInterface $request): ResponseInterface
Expand Down
2 changes: 1 addition & 1 deletion src/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* RequestBuilder applies global state or other resources to a ServerRequest
*
*
* Builder uses a fluent interface returning itself.
* To return the produced request, run ->build()
*/
Expand Down
5 changes: 0 additions & 5 deletions test/Horde/Http/Server/AllTests.php

This file was deleted.

9 changes: 0 additions & 9 deletions test/Horde/Http/Server/bootstrap.php

This file was deleted.

31 changes: 31 additions & 0 deletions test/SimpleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace Horde\Http\Server\Test;
use \PHPUnit\Framework\TestCase;
use Horde\Http\RequestFactory;
use Horde\Http\ResponseFactory;
use Horde\Http\StreamFactory;
use Horde\Http\Server\RampageRequestHandler;
use Psr\Http\Message\ResponseInterface;

/**
* @author Ralf Lang <[email protected]>
* @license http://www.horde.org/licenses/bsd LGPL BSD-3-Clause
* @category Horde
* @package Http_Server
* @subpackage UnitTests
*/
class SimpleTest extends TestCase
{
public function testRunnerSetup()
{
// Production code would use Injector/DIC instead
$responseFactory = new ResponseFactory;
$streamFactory = new StreamFactory;
$handler = new RampageRequestHandler($responseFactory, $streamFactory);
$requestFactory = new RequestFactory();
$request = $requestFactory->createServerRequest('GET', 'https://www.horde.org');
$response = $handler->handle($request);
$this->assertInstanceOf(ResponseInterface::class, $handler->handle($request));
}

}
12 changes: 12 additions & 0 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$candidates = [
dirname(__FILE__, 2) . '/vendor/autoload.php',
dirname(__FILE__, 4) . '/autoload.php',
];
// Cover root case and library case
foreach ($candidates as $candidate) {
if (file_exists($candidate)) {
require_once $candidate;
}
}
\Horde_Test_Bootstrap::bootstrap(dirname(__FILE__));

0 comments on commit 77f413a

Please sign in to comment.