|
5 | 5 |
|
6 | 6 | use PHPUnit\Framework\TestCase;
|
7 | 7 | use Remorhaz\JSON\Pointer\Locator\ListedReferenceInterface;
|
| 8 | +use Remorhaz\JSON\Pointer\Locator\ReferenceFactory; |
8 | 9 | use Remorhaz\JSON\Pointer\Locator\ReferenceFactoryInterface;
|
9 | 10 | use Remorhaz\JSON\Pointer\Locator\ReferenceInterface;
|
10 | 11 | use Remorhaz\JSON\Pointer\Locator\Exception\LocatorAlreadyBuiltException;
|
@@ -44,6 +45,14 @@ public function testAddReference_GetLocatorCalled_ThrowsException(): void
|
44 | 45 | $builder->addReference('a');
|
45 | 46 | }
|
46 | 47 |
|
| 48 | + public function testAddReference_ExportCalled_ThrowsException(): void |
| 49 | + { |
| 50 | + $builder = new LocatorBuilder($this->createMock(ReferenceFactoryInterface::class)); |
| 51 | + $builder->export(); |
| 52 | + $this->expectException(LocatorAlreadyBuiltException::class); |
| 53 | + $builder->addReference('a'); |
| 54 | + } |
| 55 | + |
47 | 56 | public function testAddReference_ConstructedWithReferenceFactory_PassesTextToSameInstance(): void
|
48 | 57 | {
|
49 | 58 | $referenceFactory = $this->createMock(ReferenceFactoryInterface::class);
|
@@ -80,4 +89,41 @@ function (ListedReferenceInterface $listedReference): ReferenceInterface {
|
80 | 89 | );
|
81 | 90 | self::assertSame([$firstReference, $secondReference], $actualValue);
|
82 | 91 | }
|
| 92 | + |
| 93 | + public function testExport_NoReferencesAdded_ReturnsEmptyPointer(): void |
| 94 | + { |
| 95 | + $referenceFactory = $this->createMock(ReferenceFactoryInterface::class); |
| 96 | + $builder = new LocatorBuilder($referenceFactory); |
| 97 | + self::assertSame('', $builder->export()); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @param string $text |
| 102 | + * @param string $expectedValue |
| 103 | + * @dataProvider providerExportSingleReference |
| 104 | + */ |
| 105 | + public function testExport_SingleReferenceAdded_ReturnsMatchingPointer(string $text, string $expectedValue): void |
| 106 | + { |
| 107 | + $builder = new LocatorBuilder(new ReferenceFactory); |
| 108 | + $builder->addReference($text); |
| 109 | + self::assertSame($expectedValue, $builder->export()); |
| 110 | + } |
| 111 | + public function providerExportSingleReference(): array |
| 112 | + { |
| 113 | + return [ |
| 114 | + 'ASCII string' => ['a', '/a'], |
| 115 | + 'Tilde' => ['~', '/~0'], |
| 116 | + 'Slash' => ['/', '/~1'], |
| 117 | + 'Tilde after slash' => ['/~', '/~1~0'], |
| 118 | + 'Slash after tilde' => ['~/', '/~0~1'], |
| 119 | + ]; |
| 120 | + } |
| 121 | + |
| 122 | + public function testExport_TwoReferencesAdded_ReturnsMatchingPointer(): void |
| 123 | + { |
| 124 | + $builder = new LocatorBuilder(new ReferenceFactory); |
| 125 | + $builder->addReference('a'); |
| 126 | + $builder->addReference('b'); |
| 127 | + self::assertSame('/a/b', $builder->export()); |
| 128 | + } |
83 | 129 | }
|
0 commit comments