generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json-pointer | ||
*/ | ||
|
||
namespace Ergebnis\Json\Pointer; | ||
|
||
final class Specification | ||
{ | ||
/** | ||
* @psalm-var \Closure(JsonPointer):bool | ||
*/ | ||
private \Closure $closure; | ||
|
||
/** | ||
* @param \Closure(JsonPointer):bool $closure | ||
*/ | ||
private function __construct(\Closure $closure) | ||
{ | ||
$this->closure = $closure; | ||
} | ||
|
||
public function isSatisfiedBy(JsonPointer $jsonPointer): bool | ||
{ | ||
$closure = $this->closure; | ||
|
||
return $closure($jsonPointer); | ||
} | ||
|
||
public static function equals(JsonPointer $other): self | ||
{ | ||
return new self(static function (JsonPointer $jsonPointer) use ($other) { | ||
return $jsonPointer->equals($other); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json-pointer | ||
*/ | ||
|
||
namespace Ergebnis\Json\Pointer\Test\Unit; | ||
|
||
use Ergebnis\Json\Pointer\JsonPointer; | ||
use Ergebnis\Json\Pointer\Specification; | ||
use Ergebnis\Json\Pointer\Test; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Ergebnis\Json\Pointer\Specification | ||
* | ||
* @uses \Ergebnis\Json\Pointer\JsonPointer | ||
* @uses \Ergebnis\Json\Pointer\ReferenceToken | ||
*/ | ||
final class SpecificationTest extends Framework\TestCase | ||
{ | ||
use Test\Util\Helper; | ||
|
||
public function testEqualsIsNotSatisifedByJsonPointerWhenJsonPointerDoesNotEqualOther(): void | ||
{ | ||
$jsonPointer = JsonPointer::fromJsonString('/foo/bar/baz'); | ||
|
||
$other = JsonPointer::fromJsonString('/foo/bar'); | ||
|
||
$specification = Specification::equals($other); | ||
|
||
self::assertFalse($specification->isSatisfiedBy($jsonPointer)); | ||
} | ||
|
||
public function testEqualsIsSatisifedByJsonPointerWhenJsonPointerEqualsOther(): void | ||
{ | ||
$jsonPointer = JsonPointer::fromJsonString('/foo/bar'); | ||
|
||
$other = JsonPointer::fromJsonString('/foo/bar'); | ||
|
||
$specification = Specification::equals($other); | ||
|
||
self::assertTrue($specification->isSatisfiedBy($jsonPointer)); | ||
} | ||
} |