diff --git a/CHANGELOG.md b/CHANGELOG.md index 25c3ad92..adbbebc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), For a full diff see [`2.1.0...main`][2.1.0...main]. +## Added + +- Added `Specification` ([#50]), by [@localheinz] + ## Removed - Removed `JsonPointers` ([#48]), by [@localheinz] @@ -67,5 +71,6 @@ For a full diff see [`a5ba52c...1.0.0`][a5ba52c...1.0.0]. [#9]: https://github.com/ergebnis/json-pointer/pull/9 [#17]: https://github.com/ergebnis/json-pointer/pull/17 [#48]: https://github.com/ergebnis/json-pointer/pull/48 +[#50]: https://github.com/ergebnis/json-pointer/pull/50 [@localheinz]: https://github.com/localheinz diff --git a/src/Specification.php b/src/Specification.php new file mode 100644 index 00000000..59c6c154 --- /dev/null +++ b/src/Specification.php @@ -0,0 +1,44 @@ +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); + }); + } +} diff --git a/test/Unit/SpecificationTest.php b/test/Unit/SpecificationTest.php new file mode 100644 index 00000000..b9f9ebd2 --- /dev/null +++ b/test/Unit/SpecificationTest.php @@ -0,0 +1,54 @@ +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)); + } +}