J. King
4 years ago
8 changed files with 624 additions and 37 deletions
@ -0,0 +1,31 @@ |
|||||
|
<?php |
||||
|
/** @license MIT |
||||
|
* Copyright 2018 J. King |
||||
|
* See LICENSE and AUTHORS files for details */ |
||||
|
|
||||
|
declare(strict_types=1); |
||||
|
namespace MensBeam\Lax\TestCase\JSON; |
||||
|
|
||||
|
use GuzzleHttp\Psr7\Response; |
||||
|
|
||||
|
/** @covers MensBeam\Lax\Parser\HTTP\Message */ |
||||
|
class HTTPTest extends \MensBeam\Lax\TestCase\AbstractParserTestCase { |
||||
|
/** @dataProvider provideHTTPMessages */ |
||||
|
public function testParseAnHttpMessage(Response $input, ?string $url, $exp): void { |
||||
|
$p = new \MensBeam\Lax\Parser\HTTP\Message($input, $url); |
||||
|
if ($exp instanceof \Exception) { |
||||
|
$this->expectExceptionObject($exp); |
||||
|
$p->parse(); |
||||
|
} else { |
||||
|
$act = $p->parse(); |
||||
|
$this->assertEquals($exp, $act); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function provideHTTPMessages(): iterable { |
||||
|
foreach ($this->provideParserTests(__DIR__."/*.yaml") as $k => $t) { |
||||
|
array_splice($t, 1, 1); |
||||
|
yield $k => $t; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
Dates: |
||||
|
input: |
||||
|
head: |
||||
|
Date: 'Thu, 05 Mar 2020 23:08:55 GMT' |
||||
|
Expires: 'Fri, 06 Mar 2020 09:22:00 GMT' |
||||
|
Last-Modified: 'Tue, 03 Mar 2020 06:14:00 GMT' |
||||
|
output: |
||||
|
meta: |
||||
|
date: '2020-03-05T23:08:55Z' |
||||
|
expires: '2020-03-06T09:22:00Z' |
||||
|
lastModified: '2020-03-03T06:14:00Z' |
||||
|
|
||||
|
Invalid dates: |
||||
|
input: |
||||
|
head: |
||||
|
Date: 'Thu, 05 Mar 2020 25:08:55 GMT' |
||||
|
Expires: 'Fri, 06 Mar 2020 09:22:00 EST' |
||||
|
Last-Modified: 'Wed, 03 Mar 2020 06:14:00 GMT' |
||||
|
output: |
||||
|
meta: {} |
@ -0,0 +1,43 @@ |
|||||
|
# The Lax test suite |
||||
|
|
||||
|
## Feed parsing tests |
||||
|
|
||||
|
The tests under the `JSON`, `XML`, and `HTTP` directories are parser tests |
||||
|
with a shared format and test harness. The test harness is largely contained |
||||
|
in the `AbstractParserTestCase.php` file, which contains the logic to |
||||
|
transform the tests themselves into native PHP input and output. |
||||
|
|
||||
|
Tests are series of YAML files each containing a map (an object), each entry |
||||
|
an individual test which is itself a map. Tests have the following keys: |
||||
|
|
||||
|
- `input`: The test input as a string, or a map (see below) |
||||
|
- `output`: The result of the parsing upon success; described |
||||
|
in more detail below |
||||
|
- `exception`: The exception ID thrown upon failure |
||||
|
- `type`: An HTTP Content-Type (with or without parameters) for |
||||
|
the document |
||||
|
- `doc_url`: A fictitious URL where a newsfeed might be located, |
||||
|
used for relative URL resolution |
||||
|
|
||||
|
The 'input' key along with either 'output' or 'exception' are required for |
||||
|
all tests. All other keys may or may not be omitted in a test. |
||||
|
|
||||
|
The test output is necessarily mangled due to the limits of YAML: |
||||
|
|
||||
|
- Any field which should be an absolute URL is written as a string; relative |
||||
|
URLs are represented as a sequence with the relative part first, followed |
||||
|
by the base that is be applied to it |
||||
|
- Any collections are represented as sequences of maps |
||||
|
- Rich text can either be supplied as a string (which represents a Text object |
||||
|
with plain-text content) or as a map with any of the properties of the |
||||
|
Text class listed |
||||
|
|
||||
|
If the test input is a map, it represents a response from an HTTP server, |
||||
|
with the following keys: |
||||
|
|
||||
|
- `status`: The response status code. This is usually omitted |
||||
|
and should be assumed to be 200 unless specified |
||||
|
- `head`: The map of header-field in the response. Each entry |
||||
|
may be a string, or a sequence of strings |
||||
|
- `body`: The message body as a a string; it may be omitted |
||||
|
if not relevant to the functionality being tested |
@ -1,6 +1,8 @@ |
|||||
{ |
{ |
||||
"require-dev": { |
"require-dev": { |
||||
"phpunit/phpunit": "^9.0", |
"phpunit/phpunit": "^9.0", |
||||
"symfony/yaml": "^5.0" |
"symfony/yaml": "^5.0", |
||||
|
"guzzlehttp/guzzle": "^6.5", |
||||
|
"guzzlehttp/psr7": "^1.6" |
||||
} |
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue