diff --git a/composer.json b/composer.json index 42eaf476..6253680d 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,6 @@ "nyholm/psr7": "^1.1" }, "require-dev": { - "csa/guzzle-cache-middleware": "^1.0", "mockery/mockery": "^1.0", "phpunit/phpunit": "^7.5", "squizlabs/php_codesniffer": "^3.5", diff --git a/composer.lock b/composer.lock index 2315e177..49851b7c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3f0cd0f980a25a5e0bbc7ac31dfd7cfe", + "content-hash": "c58befbbc1693db9c1b08aff807256e9", "packages": [ { "name": "aws/aws-crt-php", @@ -5092,66 +5092,6 @@ } ], "packages-dev": [ - { - "name": "csa/guzzle-cache-middleware", - "version": "v1.0.1", - "source": { - "type": "git", - "url": "https://github.com/csarrazi/guzzle-cache-middleware.git", - "reference": "2ff242e660900ab6b8bcf64be2c76c0d6af61c8b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/csarrazi/guzzle-cache-middleware/zipball/2ff242e660900ab6b8bcf64be2c76c0d6af61c8b", - "reference": "2ff242e660900ab6b8bcf64be2c76c0d6af61c8b", - "shasum": "" - }, - "require": { - "guzzlehttp/guzzle": "^6.1", - "php": ">=5.6.0", - "symfony/filesystem": "^2.7|^3.0|^4.0|^5.0" - }, - "require-dev": { - "doctrine/cache": "^1.1", - "phpunit/phpunit": "^4.8", - "psr/cache": "^1.0", - "symfony/phpunit-bridge": "^2.7|^3.0|^4.0|^5.0" - }, - "suggest": { - "doctrine/cache": "Allows caching of responses", - "namshi/cuzzle": "Output command to repeat request in command line", - "psr/cache": "Allows caching of responses", - "tolerance/tolerance": "Allows retrying failed requests" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Csa\\GuzzleHttp\\Middleware\\Cache\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Charles Sarrazin", - "email": "charles@sarraz.in" - } - ], - "description": "A Cache middleware for GuzzleHttp >= 6.0", - "support": { - "issues": "https://github.com/csarrazi/guzzle-cache-middleware/issues", - "source": "https://github.com/csarrazi/guzzle-cache-middleware/tree/master" - }, - "abandoned": "kevinrob/guzzle-cache-middleware", - "time": "2019-11-26T09:34:53+00:00" - }, { "name": "hamcrest/hamcrest-php", "version": "v2.0.1", @@ -7002,70 +6942,6 @@ ], "time": "2024-09-11T06:50:28+00:00" }, - { - "name": "symfony/filesystem", - "version": "v5.4.13", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "ac09569844a9109a5966b9438fc29113ce77cf51" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/ac09569844a9109a5966b9438fc29113ce77cf51", - "reference": "ac09569844a9109a5966b9438fc29113ce77cf51", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8", - "symfony/polyfill-php80": "^1.16" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Filesystem\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides basic utilities for the filesystem", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.4.13" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-09-21T19:53:16+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.3", @@ -7190,6 +7066,6 @@ "platform": { "php": "^7.4" }, - "platform-dev": {}, - "plugin-api-version": "2.6.0" + "platform-dev": [], + "plugin-api-version": "2.2.0" } diff --git a/tests/src/Search/HttpClient.php b/tests/src/Search/HttpClient.php index 18d6872b..326e8d90 100644 --- a/tests/src/Search/HttpClient.php +++ b/tests/src/Search/HttpClient.php @@ -13,24 +13,11 @@ trait HttpClient { - /** @var ValidatingStorageAdapter */ - public $storage; public $httpClient; final protected function getHttpClient() : \eLife\ApiClient\HttpClient { if (null === $this->httpClient) { - $storage = new InMemoryStorageAdapter(); - $validator = new JsonMessageValidator( - new PathBasedSchemaFinder(ComposerLocator::getPath('elife/api').'/dist/model'), - new Validator() - ); - - $this->storage = new ValidatingStorageAdapter($storage, $validator); - - $stack = HandlerStack::create(); - $stack->push(new MockMiddleware($this->storage, 'replay')); - $this->httpClient = new Guzzle6HttpClient(new Client([ 'base_uri' => 'http://api.elifesciences.org', 'handler' => $stack, diff --git a/tests/src/Search/HttpMocks.php b/tests/src/Search/HttpMocks.php deleted file mode 100644 index ed58036a..00000000 --- a/tests/src/Search/HttpMocks.php +++ /dev/null @@ -1,68 +0,0 @@ - 'subject1', - 'name' => 'Subject id name', - 'impactStatement' => 'Subject id impact statement', - 'image' => [ - 'banner' => [ - 'alt' => '', - 'uri' => 'https://iiif.elifesciences.org/banner.jpg', - 'source' => [ - 'mediaType' => 'image/jpeg', - 'uri' => 'https://iiif.elifesciences.org/banner.jpg/full/full/0/default.jpg', - 'filename' => 'banner.jpg', - ], - 'size' => [ - 'width' => 800, - 'height' => 400, - ], - ], - 'thumbnail' => [ - 'alt' => '', - 'uri' => 'https://iiif.elifesciences.org/thumbnail.jpg', - 'source' => [ - 'mediaType' => 'image/jpeg', - 'uri' => 'https://iiif.elifesciences.org/thumbnail.jpg/full/full/0/default.jpg', - 'filename' => 'thumbnail.jpg', - ], - 'size' => [ - 'width' => 140, - 'height' => 140, - ], - ], - ], - ]; - } - - private function mockSubjects() - { - if (!isset($this->storage)) { - throw new LogicException('You need to include the HttpClient trait to mock Http Requests.'); - } - $this->storage->save( - new Request( - 'GET', - 'http://api.elifesciences.org/subjects/subject1', - ['Accept' => (string) new MediaType(SubjectsClient::TYPE_SUBJECT, 1)] - ), - new Response( - 200, - ['Content-Type' => (string) new MediaType(SubjectsClient::TYPE_SUBJECT, 1)], - json_encode($this->createSubjectJson()) - ) - ); - } -} diff --git a/tests/src/Search/Indexer/ModelIndexer/BlogArticleIndexerTest.php b/tests/src/Search/Indexer/ModelIndexer/BlogArticleIndexerTest.php index 82af4fde..0a25cd18 100644 --- a/tests/src/Search/Indexer/ModelIndexer/BlogArticleIndexerTest.php +++ b/tests/src/Search/Indexer/ModelIndexer/BlogArticleIndexerTest.php @@ -5,14 +5,12 @@ use PHPUnit\Framework\TestCase; use eLife\ApiSdk\Model\BlogArticle; use eLife\Search\Indexer\ModelIndexer\BlogArticleIndexer; -use tests\eLife\Search\HttpMocks; final class BlogArticleIndexerTest extends TestCase { use GetSerializer; use CallSerializer; use ModelProvider; - use HttpMocks; /** * @var BlogArticleIndexer @@ -38,9 +36,6 @@ protected function getModelDefinitions(): array */ public function testSerializationSmokeTest(BlogArticle $blogArticle) { - // Mock the HTTP call that's made for subjects. - $this->mockSubjects(); - // Check A to B $serialized = $this->callSerialize($this->indexer, $blogArticle); /** @var BlogArticle $deserialized */ diff --git a/tests/src/Search/Indexer/ModelIndexer/CollectionIndexerTest.php b/tests/src/Search/Indexer/ModelIndexer/CollectionIndexerTest.php index b80a69b3..56cd78ce 100644 --- a/tests/src/Search/Indexer/ModelIndexer/CollectionIndexerTest.php +++ b/tests/src/Search/Indexer/ModelIndexer/CollectionIndexerTest.php @@ -5,14 +5,12 @@ use PHPUnit\Framework\TestCase; use eLife\ApiSdk\Model\Collection; use eLife\Search\Indexer\ModelIndexer\CollectionIndexer; -use tests\eLife\Search\HttpMocks; final class CollectionIndexerTest extends TestCase { use GetSerializer; use CallSerializer; use ModelProvider; - use HttpMocks; /** * @var CollectionIndexer @@ -37,8 +35,6 @@ protected function getModelDefinitions(): array */ public function testSerializationSmokeTest(Collection $collection) { - // Mock the HTTP call that's made for subjects. - $this->mockSubjects(); // Check A to B $serialized = $this->callSerialize($this->indexer, $collection); /** @var Collection $deserialized */ diff --git a/tests/src/Search/Indexer/ModelIndexer/InterviewIndexerTest.php b/tests/src/Search/Indexer/ModelIndexer/InterviewIndexerTest.php index b80079ef..cb1de7b3 100644 --- a/tests/src/Search/Indexer/ModelIndexer/InterviewIndexerTest.php +++ b/tests/src/Search/Indexer/ModelIndexer/InterviewIndexerTest.php @@ -5,14 +5,12 @@ use PHPUnit\Framework\TestCase; use eLife\ApiSdk\Model\Interview; use eLife\Search\Indexer\ModelIndexer\InterviewIndexer; -use tests\eLife\Search\HttpMocks; final class InterviewIndexerTest extends TestCase { use GetSerializer; use CallSerializer; use ModelProvider; - use HttpMocks; /** * @var InterviewIndexer @@ -37,8 +35,6 @@ protected function getModelDefinitions(): array */ public function testSerializationSmokeTest(Interview $interview) { - // Mock the HTTP call that's made for subjects. - $this->mockSubjects(); // Check A to B $serialized = $this->callSerialize($this->indexer, $interview); /** @var Interview $deserialized */ diff --git a/tests/src/Search/Indexer/ModelIndexer/LabsPostIndexerTest.php b/tests/src/Search/Indexer/ModelIndexer/LabsPostIndexerTest.php index 891c73b1..ede7343c 100644 --- a/tests/src/Search/Indexer/ModelIndexer/LabsPostIndexerTest.php +++ b/tests/src/Search/Indexer/ModelIndexer/LabsPostIndexerTest.php @@ -5,14 +5,12 @@ use PHPUnit\Framework\TestCase; use eLife\ApiSdk\Model\LabsPost; use eLife\Search\Indexer\ModelIndexer\LabsPostIndexer; -use tests\eLife\Search\HttpMocks; final class LabsPostIndexerTest extends TestCase { use GetSerializer; use CallSerializer; use ModelProvider; - use HttpMocks; /** * @var LabsPostIndexer @@ -37,8 +35,6 @@ protected function getModelDefinitions(): array */ public function testSerializationSmokeTest(LabsPost $labsPost) { - // Mock the HTTP call that's made for subjects. - $this->mockSubjects(); // Check A to B $serialized = $this->callSerialize($this->indexer, $labsPost); /** @var LabsPost $deserialized */ diff --git a/tests/src/Search/Indexer/ModelIndexer/PodcastEpisodeIndexerTest.php b/tests/src/Search/Indexer/ModelIndexer/PodcastEpisodeIndexerTest.php index de4225eb..2e53418a 100644 --- a/tests/src/Search/Indexer/ModelIndexer/PodcastEpisodeIndexerTest.php +++ b/tests/src/Search/Indexer/ModelIndexer/PodcastEpisodeIndexerTest.php @@ -5,14 +5,12 @@ use PHPUnit\Framework\TestCase; use eLife\ApiSdk\Model\PodcastEpisode; use eLife\Search\Indexer\ModelIndexer\PodcastEpisodeIndexer; -use tests\eLife\Search\HttpMocks; final class PodcastEpisodeIndexerTest extends TestCase { use GetSerializer; use CallSerializer; use ModelProvider; - use HttpMocks; /** * @var PodcastEpisodeIndexer @@ -37,8 +35,6 @@ protected function getModelDefinitions(): array */ public function testSerializationSmokeTest(PodcastEpisode $podcastEpisode) { - // Mock the HTTP call that's made for subjects. - $this->mockSubjects(); // Check A to B $serialized = $this->callSerialize($this->indexer, $podcastEpisode); /** @var PodcastEpisode $deserialized */ diff --git a/tests/src/Search/Indexer/ModelIndexer/ResearchArticleIndexerTest.php b/tests/src/Search/Indexer/ModelIndexer/ResearchArticleIndexerTest.php index 90aaec27..148b83d5 100644 --- a/tests/src/Search/Indexer/ModelIndexer/ResearchArticleIndexerTest.php +++ b/tests/src/Search/Indexer/ModelIndexer/ResearchArticleIndexerTest.php @@ -9,15 +9,12 @@ use eLife\ApiSdk\Model\ArticleVersion; use eLife\Search\Api\Elasticsearch\MappedElasticsearchClient; use eLife\Search\Indexer\ModelIndexer\ResearchArticleIndexer; -use tests\eLife\Search\HttpMocks; -use Traversable; final class ResearchArticleIndexerTest extends TestCase { use GetSerializer; use CallSerializer; use ModelProvider; - use HttpMocks; /** * @var MockInterface @@ -49,8 +46,6 @@ protected function getModelDefinitions(): array */ public function testSerializationSmokeTest(ArticleVersion $researchArticle) { - // Mock the HTTP call that's made for subjects. - $this->mockSubjects(); // Check A to B $serialized = $this->callSerialize($this->indexer, $researchArticle); /** @var ArticlePoA $deserialized */ diff --git a/tests/src/Search/Indexer/ModelIndexer/ReviewedPreprintIndexerTest.php b/tests/src/Search/Indexer/ModelIndexer/ReviewedPreprintIndexerTest.php index ca60482e..8ab402dc 100644 --- a/tests/src/Search/Indexer/ModelIndexer/ReviewedPreprintIndexerTest.php +++ b/tests/src/Search/Indexer/ModelIndexer/ReviewedPreprintIndexerTest.php @@ -7,14 +7,12 @@ use eLife\Search\Api\Elasticsearch\MappedElasticsearchClient; use eLife\Search\Indexer\ModelIndexer\ReviewedPreprintIndexer; use Mockery; -use tests\eLife\Search\HttpMocks; final class ReviewedPreprintIndexerTest extends TestCase { use GetSerializer; use CallSerializer; use ModelProvider; - use HttpMocks; /** * @var MockInterface @@ -45,8 +43,6 @@ protected function getModelDefinitions(): array */ public function testSerializationSmokeTest(ReviewedPreprint $reviewedPreprint) { - // Mock the HTTP call that's made for subjects. - $this->mockSubjects(); // Check A to B $serialized = $this->callSerialize($this->indexer, $reviewedPreprint); /** @var ReviewedPreprint $deserialized */ diff --git a/tests/src/Search/ValidatingStorageAdapter.php b/tests/src/Search/ValidatingStorageAdapter.php deleted file mode 100644 index 4e92823d..00000000 --- a/tests/src/Search/ValidatingStorageAdapter.php +++ /dev/null @@ -1,51 +0,0 @@ -storageAdapter = $storageAdapter; - $this->validator = $validator; - } - - public function fetch(RequestInterface $request) - { - return $this->storageAdapter->fetch($request); - } - - public function save(RequestInterface $request, ResponseInterface $response) - { - try { - $this->validator->validate($request); - } catch (InvalidMessage $e) { - throw new RuntimeException('Request JSON schema validation failed: '.$this->dumpJsonBody($request), -1, $e); - } - try { - $this->validator->validate($response); - } catch (InvalidMessage $e) { - throw new RuntimeException('Response JSON schema validation failed: '.$this->dumpJsonBody($response), -1, $e); - } - - $this->storageAdapter->save($request, $response); - } - - private function dumpJsonBody(MessageInterface $message) : string - { - return json_encode(json_decode($message->getBody(), true), JSON_PRETTY_PRINT); - } -}