Skip to content

Commit 7de8d70

Browse files
committed
Acceptance test added
1 parent a64a81c commit 7de8d70

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/AcceptanceTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Remorhaz\JSON\Pointer\Test;
5+
6+
use PHPUnit\Framework\TestCase;
7+
use Remorhaz\JSON\Data\Value\EncodedJson\NodeValueFactory;
8+
use Remorhaz\JSON\Pointer\Processor\Processor;
9+
use Remorhaz\JSON\Pointer\Query\QueryFactory;
10+
11+
/**
12+
* Examples from RFC-6901
13+
*
14+
* @see https://tools.ietf.org/html/rfc6901
15+
* @coversNothing
16+
*/
17+
class AcceptanceTest extends TestCase
18+
{
19+
20+
/**
21+
* @param string $document
22+
* @param string $pointer
23+
* @param string $expectedValue
24+
* @dataProvider providerSelect
25+
*/
26+
public function testSelect(string $document, string $pointer, string $expectedValue): void
27+
{
28+
$rootNode = NodeValueFactory::create()->createValue($document);
29+
$query = QueryFactory::create()->createQuery($pointer);
30+
$selection = Processor::create()
31+
->select($query, $rootNode)
32+
->encode();
33+
self::assertSame($expectedValue, $selection);
34+
}
35+
36+
public function providerSelect(): array
37+
{
38+
$document = '{"foo":["bar","baz"],"":0,"a/b":1,"c%d":2,"e^f":3,"g|h":4,"i\\\\j":5,"k\\"l":6," ":7,"m~n":8}';
39+
40+
return [
41+
[$document, "", $document],
42+
[$document, "/foo", '["bar","baz"]'],
43+
[$document, "/foo/0", '"bar"'],
44+
[$document, "/", '0'],
45+
[$document, "/a~1b", '1'],
46+
[$document, "/c%d", '2'],
47+
[$document, "/e^f", '3'],
48+
[$document, "/g|h", '4'],
49+
[$document, "/i\\j", '5'],
50+
[$document, "/k\"l", '6'],
51+
[$document, "/ ", '7'],
52+
[$document, "/m~0n", '8'],
53+
];
54+
}
55+
}

0 commit comments

Comments
 (0)