From 8bae23fef3e1e52c97728da09c30c7bd50758cb0 Mon Sep 17 00:00:00 2001 From: bereza Date: Tue, 13 May 2025 13:46:24 +0300 Subject: [PATCH] IDBTECH-144 ENSITECH-274 ensi/openapi-psr7-validator update --- composer.json | 2 +- tests/ValidatorBuilderTest.php | 38 +++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index e5a94b1..da5bfb6 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require": { "php": "^8.0", "ext-json": "*", - "ensi/openapi-psr7-validator": "^0.0.2", + "ensi/openapi-psr7-validator": "^0.0", "league/openapi-psr7-validator": "^0.22", "nyholm/psr7": "^1.3.1", "psr/cache": "^1.0 || ^2.0 || ^3.0", diff --git a/tests/ValidatorBuilderTest.php b/tests/ValidatorBuilderTest.php index 88a0597..48c0858 100644 --- a/tests/ValidatorBuilderTest.php +++ b/tests/ValidatorBuilderTest.php @@ -5,9 +5,11 @@ namespace Osteel\OpenApi\Testing\Tests; use InvalidArgumentException; -use Osteel\OpenApi\Testing\Adapters\AdapterInterface; +use Osteel\OpenApi\Testing\Adapters\MessageAdapterInterface; +use Osteel\OpenApi\Testing\Cache\CacheAdapterInterface; use Osteel\OpenApi\Testing\Validator; use Osteel\OpenApi\Testing\ValidatorBuilder; +use stdClass; class ValidatorBuilderTest extends TestCase { @@ -28,7 +30,7 @@ public static function definitionProvider(): array /** * @dataProvider definitionProvider */ - public function testItBuildsAValidator(string $method, string $definition) + public function testItBuildsAValidator(string $method, string $definition): void { $result = ValidatorBuilder::$method($definition)->getValidator(); @@ -42,24 +44,44 @@ public function testItBuildsAValidator(string $method, string $definition) $this->assertTrue($result->get($response, static::PATH)); } - public function testItDoesNotSetTheAdapterBecauseItsTypeIsInvalid() + public function testItDoesNotSetTheAdapterBecauseItsTypeIsInvalid(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage(sprintf( 'Class %s does not implement the %s interface', - InvalidArgumentException::class, - AdapterInterface::class + stdClass::class, + MessageAdapterInterface::class )); - ValidatorBuilder::fromYaml(self::$yamlDefinition)->setAdapter(InvalidArgumentException::class); + ValidatorBuilder::fromYaml(self::$yamlDefinition)->setMessageAdapter(stdClass::class); } - public function testItSetsTheAdapter() + public function testItSetsTheAdapter(): void { ValidatorBuilder::fromYaml(self::$yamlDefinition) - ->setAdapter(get_class($this->createMock(AdapterInterface::class))); + ->setMessageAdapter($this->createMock(MessageAdapterInterface::class)::class); // No exception means the test was successful. $this->assertTrue(true); } + + public function testItDoesNotSetTheCacheAdapterBecauseItsTypeIsInvalid(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage(sprintf( + 'Class %s does not implement the %s interface', + stdClass::class, + CacheAdapterInterface::class + )); + + ValidatorBuilder::fromYaml(self::$yamlDefinition)->setCacheAdapter(stdClass::class); + } + + public function testItSetsTheCacheAdapter(): void + { + ValidatorBuilder::fromYaml(self::$yamlDefinition) + ->setCacheAdapter($this->createMock(CacheAdapterInterface::class)::class); + + $this->addToAssertionCount(1); + } }