Browse Source

attempt to reduce shared code in the FedoraAdapterTest

d9_islandora
elizoller 4 years ago
parent
commit
433d033f72
  1. 87
      tests/src/Kernel/FedoraAdapterTest.php

87
tests/src/Kernel/FedoraAdapterTest.php

@ -17,6 +17,31 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
*/ */
class FedoraAdapterTest extends IslandoraKernelTestBase { 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([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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. * 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. * Mocks up an adapter for Fedora LDP-NR response.
*/ */
protected function createAdapterForFile() { protected function createAdapterForFile() {
$prophecy = $this->prophesize(Response::class); $prophecy = $this->createAdapterBase();
$prophecy->getStatusCode()->willReturn(200);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')
->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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
$response = $prophecy->reveal(); $response = $prophecy->reveal();
$prophecy = $this->prophesize(IFedoraApi::class); $prophecy = $this->prophesize(IFedoraApi::class);
@ -113,25 +120,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$fedora_prophecy->saveResource('', '', Argument::any()) $fedora_prophecy->saveResource('', '', Argument::any())
->willReturn($prophecy->reveal()); ->willReturn($prophecy->reveal());
$prophecy = $this->prophesize(Response::class); $prophecy = $this->createAdapterBase();
$prophecy->getStatusCode()->willReturn(200);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')
->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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
$fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); $fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal());
$api = $fedora_prophecy->reveal(); $api = $fedora_prophecy->reveal();
@ -611,25 +601,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
* @covers \Drupal\islandora\Flysystem\Adapter\FedoraAdapter::copy * @covers \Drupal\islandora\Flysystem\Adapter\FedoraAdapter::copy
*/ */
public function testRename() { public function testRename() {
$prophecy = $this->prophesize(Response::class); $prophecy = $this->createAdapterBase();
$prophecy->getStatusCode()->willReturn(200);
$prophecy->getHeader('Last-Modified')
->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]);
$prophecy->getHeader('Link')
->willReturn([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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
$response = $prophecy->reveal(); $response = $prophecy->reveal();
$fedora_prophecy = $this->prophesize(IFedoraApi::class); $fedora_prophecy = $this->prophesize(IFedoraApi::class);

Loading…
Cancel
Save