Start on parser helper tests

This commit is contained in:
J. King 2020-06-14 10:17:19 -04:00
parent 8d14729797
commit da93bdc18d
5 changed files with 367 additions and 248 deletions

View file

@ -55,4 +55,8 @@ class HttpClient implements RequestFactoryInterface, ClientInterface {
}
throw new Exception("tooManyRedirects");
}
public function createRequest(string $method, $uri): RequestInterface {
return $this->requestFactory->createRequest($method, $uri);
}
}

View file

View file

@ -0,0 +1,53 @@
<?php
/** @license MIT
* Copyright 2018 J. King
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace MensBeam\Lax\TestCase\Parser;
use MensBeam\Lax\Parser\Parser;
use MensBeam\Lax\Parser\Exception;
use MensBeam\Lax\Parser\XML\Feed as XMLParser;
use MensBeam\Lax\Parser\JSON\Feed as JSONParser;
/** @covers MensBeam\Lax\Parser\Parser */
class ParserTest extends \PHPUnit\Framework\TestCase {
/** @dataProvider provideContentTypes */
public function testFindCorrectParserForContentType(string $in, $exp): void {
if ($exp instanceof \Throwable) {
$this->expectExceptionObject($exp);
Parser::findParserForType($in);
} else {
$this->assertSame($exp, Parser::findParserForType($in));
}
}
public function provideContentTypes(): iterable {
return [
["application/feed+json", JSONParser::class],
["application/json", JSONParser::class],
["text/json", JSONParser::class],
["application/atom+xml", XMLParser::class],
["application/rss+xml", XMLParser::class],
["application/rdf+xml", XMLParser::class],
["application/xml", XMLParser::class],
["text/xml", XMLParser::class],
["text/plain", new Exception("notSupportedType")],
["not a type", null],
["text/json; charset=utf-8", JSONParser::class],
];
}
/** @dataProvider provideDetectableContent */
public function testFindCorrectTypeForContent(string $in, string $exp): void {
$this->assertSame($exp, Parser::findTypeForContent($in));
}
public function provideDetectableContent(): iterable {
return [
['{""}', "application/json"],
[" \n {\"v", "application/json"],
];
}
}

View file

@ -4,5 +4,8 @@
"symfony/yaml": "^5.0",
"guzzlehttp/guzzle": "^6.5",
"guzzlehttp/psr7": "^1.6"
},
"require": {
"phake/phake": "^3.1"
}
}

View file

@ -4,8 +4,313 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4259aa457f6935c16ad776bc1a3897ea",
"packages": [],
"content-hash": "e0a0f1836101660ee1eef229e3f7b95f",
"packages": [
{
"name": "phake/phake",
"version": "v3.1.8",
"source": {
"type": "git",
"url": "https://github.com/mlively/Phake.git",
"reference": "9f9dfb12c9ce6e38c73de9631ea2ab0f0ea36a65"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mlively/Phake/zipball/9f9dfb12c9ce6e38c73de9631ea2ab0f0ea36a65",
"reference": "9f9dfb12c9ce6e38c73de9631ea2ab0f0ea36a65",
"shasum": ""
},
"require": {
"php": ">=7",
"sebastian/comparator": "^1.1|^2.0|^3.0|^4.0"
},
"require-dev": {
"codeclimate/php-test-reporter": "dev-master",
"doctrine/common": "2.3.*",
"ext-soap": "*",
"hamcrest/hamcrest-php": "1.1.*",
"phpunit/phpunit": "^7.0"
},
"suggest": {
"doctrine/common": "Allows mock annotations to use import statements for classes.",
"hamcrest/hamcrest-php": "Use Hamcrest matchers."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0.0-dev"
}
},
"autoload": {
"psr-0": {
"Phake": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Mike Lively",
"email": "m@digitalsandwich.com"
}
],
"description": "The Phake mock testing library",
"homepage": "https://github.com/mlively/Phake",
"keywords": [
"mock",
"testing"
],
"time": "2020-05-11T18:43:26+00:00"
},
{
"name": "sebastian/comparator",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "85b3435da967696ed618ff745f32be3ff4a2b8e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/85b3435da967696ed618ff745f32be3ff4a2b8e8",
"reference": "85b3435da967696ed618ff745f32be3ff4a2b8e8",
"shasum": ""
},
"require": {
"php": "^7.3",
"sebastian/diff": "^4.0",
"sebastian/exporter": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
}
],
"description": "Provides the functionality to compare PHP values for equality",
"homepage": "https://github.com/sebastianbergmann/comparator",
"keywords": [
"comparator",
"compare",
"equality"
],
"time": "2020-02-07T06:08:51+00:00"
},
{
"name": "sebastian/diff",
"version": "4.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "3e523c576f29dacecff309f35e4cc5a5c168e78a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3e523c576f29dacecff309f35e4cc5a5c168e78a",
"reference": "3e523c576f29dacecff309f35e4cc5a5c168e78a",
"shasum": ""
},
"require": {
"php": "^7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"symfony/process": "^4.2 || ^5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Kore Nordmann",
"email": "mail@kore-nordmann.de"
}
],
"description": "Diff implementation",
"homepage": "https://github.com/sebastianbergmann/diff",
"keywords": [
"diff",
"udiff",
"unidiff",
"unified diff"
],
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-05-08T05:01:12+00:00"
},
{
"name": "sebastian/exporter",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "80c26562e964016538f832f305b2286e1ec29566"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/80c26562e964016538f832f305b2286e1ec29566",
"reference": "80c26562e964016538f832f305b2286e1ec29566",
"shasum": ""
},
"require": {
"php": "^7.3",
"sebastian/recursion-context": "^4.0"
},
"require-dev": {
"ext-mbstring": "*",
"phpunit/phpunit": "^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
}
],
"description": "Provides the functionality to export PHP variables for visualization",
"homepage": "http://www.github.com/sebastianbergmann/exporter",
"keywords": [
"export",
"exporter"
],
"time": "2020-02-07T06:10:52+00:00"
},
{
"name": "sebastian/recursion-context",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
"reference": "cdd86616411fc3062368b720b0425de10bd3d579"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cdd86616411fc3062368b720b0425de10bd3d579",
"reference": "cdd86616411fc3062368b720b0425de10bd3d579",
"shasum": ""
},
"require": {
"php": "^7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
}
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
"time": "2020-02-07T06:18:20+00:00"
}
],
"packages-dev": [
{
"name": "doctrine/instantiator",
@ -1247,132 +1552,6 @@
"homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
"time": "2020-02-07T06:20:13+00:00"
},
{
"name": "sebastian/comparator",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "85b3435da967696ed618ff745f32be3ff4a2b8e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/85b3435da967696ed618ff745f32be3ff4a2b8e8",
"reference": "85b3435da967696ed618ff745f32be3ff4a2b8e8",
"shasum": ""
},
"require": {
"php": "^7.3",
"sebastian/diff": "^4.0",
"sebastian/exporter": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
}
],
"description": "Provides the functionality to compare PHP values for equality",
"homepage": "https://github.com/sebastianbergmann/comparator",
"keywords": [
"comparator",
"compare",
"equality"
],
"time": "2020-02-07T06:08:51+00:00"
},
{
"name": "sebastian/diff",
"version": "4.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "3e523c576f29dacecff309f35e4cc5a5c168e78a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3e523c576f29dacecff309f35e4cc5a5c168e78a",
"reference": "3e523c576f29dacecff309f35e4cc5a5c168e78a",
"shasum": ""
},
"require": {
"php": "^7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"symfony/process": "^4.2 || ^5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Kore Nordmann",
"email": "mail@kore-nordmann.de"
}
],
"description": "Diff implementation",
"homepage": "https://github.com/sebastianbergmann/diff",
"keywords": [
"diff",
"udiff",
"unidiff",
"unified diff"
],
"funding": [
{
"url": "https://github.com/sebastianbergmann",
"type": "github"
}
],
"time": "2020-05-08T05:01:12+00:00"
},
{
"name": "sebastian/environment",
"version": "5.1.0",
@ -1426,73 +1605,6 @@
],
"time": "2020-04-14T13:36:52+00:00"
},
{
"name": "sebastian/exporter",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "80c26562e964016538f832f305b2286e1ec29566"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/80c26562e964016538f832f305b2286e1ec29566",
"reference": "80c26562e964016538f832f305b2286e1ec29566",
"shasum": ""
},
"require": {
"php": "^7.3",
"sebastian/recursion-context": "^4.0"
},
"require-dev": {
"ext-mbstring": "*",
"phpunit/phpunit": "^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
}
],
"description": "Provides the functionality to export PHP variables for visualization",
"homepage": "http://www.github.com/sebastianbergmann/exporter",
"keywords": [
"export",
"exporter"
],
"time": "2020-02-07T06:10:52+00:00"
},
{
"name": "sebastian/global-state",
"version": "4.0.0",
@ -1639,59 +1751,6 @@
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
"time": "2020-02-07T06:19:40+00:00"
},
{
"name": "sebastian/recursion-context",
"version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
"reference": "cdd86616411fc3062368b720b0425de10bd3d579"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cdd86616411fc3062368b720b0425de10bd3d579",
"reference": "cdd86616411fc3062368b720b0425de10bd3d579",
"shasum": ""
},
"require": {
"php": "^7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
}
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
"time": "2020-02-07T06:18:20+00:00"
},
{
"name": "sebastian/resource-operations",
"version": "3.0.0",