File: RelativeReferenceValidatorTest.php

package info (click to toggle)
php-json-schema 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,248 kB
  • sloc: php: 9,635; makefile: 153; python: 28; sh: 13
file content (41 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

declare(strict_types=1);

namespace Tool\Validator;

use JsonSchema\Tool\Validator\RelativeReferenceValidator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class RelativeReferenceValidatorTest extends TestCase
{
    #[DataProvider('validRelativeReferenceDataProvider')]
    public function testValidRelativeReferencesAreValidatedAsSuch(string $ref): void
    {
        self::assertTrue(RelativeReferenceValidator::isValid($ref));
    }

    #[DataProvider('invalidRelativeReferenceDataProvider')]
    public function testInvalidRelativeReferencesAreValidatedAsSuch(string $ref): void
    {
        self::assertFalse(RelativeReferenceValidator::isValid($ref));
    }

    public function validRelativeReferenceDataProvider(): \Generator
    {
        yield 'Relative path from root' => ['ref' => '/relative/path'];
        yield 'Relative path up one level' => ['ref' => '../up-one-level'];
        yield 'Relative path from current' => ['ref' => 'foo/bar'];
    }

    public function invalidRelativeReferenceDataProvider(): \Generator
    {
        yield 'Absolute URI' => ['ref' => 'http://example.com'];
        yield 'Three slashes' => ['ref' => '///three/slashes'];
        yield 'Path with spaces' => ['ref' => '/path with spaces'];
        yield 'No path having query and fragment' => ['ref' => '?#invalid'];
        yield 'Missing path having fragment' => ['ref' => '#'];
        yield 'Missing path having query' => ['ref' => '?'];
    }
}