From 433d033f726a7e495517e9fed6c242a85fc8b873 Mon Sep 17 00:00:00 2001 From: elizoller Date: Fri, 18 Dec 2020 04:42:54 +0000 Subject: [PATCH] attempt to reduce shared code in the FedoraAdapterTest --- tests/src/Kernel/FedoraAdapterTest.php | 87 +++++++++----------------- 1 file changed, 30 insertions(+), 57 deletions(-) diff --git a/tests/src/Kernel/FedoraAdapterTest.php b/tests/src/Kernel/FedoraAdapterTest.php index 224c0f28..7ba00232 100644 --- a/tests/src/Kernel/FedoraAdapterTest.php +++ b/tests/src/Kernel/FedoraAdapterTest.php @@ -17,6 +17,31 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; */ class FedoraAdapterTest extends IslandoraKernelTestBase { + /** + * Shared functionality for an adapter. + */ + protected function createAdapterBase() { + $prophecy = $this->prophesize(Response::class); + $prophecy->getStatusCode()->willReturn(200); + $prophecy->getHeader('Last-Modified') + ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); + $prophecy->getHeader('Link') + ->willReturn([ + ';rel="type"', + ';rel="type"', + ]); + $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); + $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); + // phpcs:disable + if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); + } else { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); + } + // phpcs:enable + return $prophecy; + } + /** * Mocks up an adapter for Fedora calls that return 404. */ @@ -40,25 +65,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { * Mocks up an adapter for Fedora LDP-NR response. */ protected function createAdapterForFile() { - $prophecy = $this->prophesize(Response::class); - $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified') - ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link') - ->willReturn([ - ';rel="type"', - ';rel="type"', - ]); - $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); - $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - // phpcs:disable - if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { - $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); - } - else { - $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); - } - // phpcs:enable + $prophecy = $this->createAdapterBase(); $response = $prophecy->reveal(); $prophecy = $this->prophesize(IFedoraApi::class); @@ -113,25 +120,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $fedora_prophecy->saveResource('', '', Argument::any()) ->willReturn($prophecy->reveal()); - $prophecy = $this->prophesize(Response::class); - $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified') - ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link') - ->willReturn([ - ';rel="type"', - ';rel="type"', - ]); - $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); - $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - // phpcs:disable - if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { - $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); - } - else { - $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); - } - // phpcs:enable + $prophecy = $this->createAdapterBase(); + $fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $api = $fedora_prophecy->reveal(); @@ -611,25 +601,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { * @covers \Drupal\islandora\Flysystem\Adapter\FedoraAdapter::copy */ public function testRename() { - $prophecy = $this->prophesize(Response::class); - $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified') - ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link') - ->willReturn([ - ';rel="type"', - ';rel="type"', - ]); - $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); - $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - // phpcs:disable - if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { - $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); - } - else { - $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); - } - // phpcs:enable + $prophecy = $this->createAdapterBase(); + $response = $prophecy->reveal(); $fedora_prophecy = $this->prophesize(IFedoraApi::class);