From b0b673dbaa522ef5a745f8e47f6c624771bbf562 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Fri, 27 Oct 2023 15:26:49 +0200 Subject: [PATCH] test: fix phpspec tests --- spec/Gaufrette/Adapter/ZipSpec.php | 3 ++- spec/Gaufrette/FilesystemSpec.php | 2 +- spec/Gaufrette/StreamWrapperSpec.php | 30 ++++++++++++++++------------ src/Gaufrette/Adapter/Zip.php | 2 +- src/Gaufrette/StreamWrapper.php | 5 ++++- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/spec/Gaufrette/Adapter/ZipSpec.php b/spec/Gaufrette/Adapter/ZipSpec.php index 76bb1c13a..ca7c1df28 100644 --- a/spec/Gaufrette/Adapter/ZipSpec.php +++ b/spec/Gaufrette/Adapter/ZipSpec.php @@ -2,6 +2,7 @@ namespace spec\Gaufrette\Adapter; +use Gaufrette\Adapter; use PhpSpec\ObjectBehavior; class ZipSpec extends ObjectBehavior @@ -13,6 +14,6 @@ function let() function it_is_adapter() { - $this->shouldHaveType('Gaufrette\Adapter'); + $this->shouldHaveType(Adapter::class); } } diff --git a/spec/Gaufrette/FilesystemSpec.php b/spec/Gaufrette/FilesystemSpec.php index 533b744f5..6924bad5f 100644 --- a/spec/Gaufrette/FilesystemSpec.php +++ b/spec/Gaufrette/FilesystemSpec.php @@ -322,7 +322,7 @@ function it_delegates_checksum_calculation_to_adapter_when_adapter_is_checksum_c $extendedAdapter->read('filename')->shouldNotBeCalled(); $extendedAdapter->checksum('filename')->shouldBeCalled()->willReturn(12); - $this->checksum('filename')->shouldReturn(12); + $this->checksum('filename')->shouldReturn("12"); } function it_delegates_mime_type_resolution_to_adapter_when_adapter_is_mime_type_provider(ExtendedAdapter $extendedAdapter) diff --git a/spec/Gaufrette/StreamWrapperSpec.php b/spec/Gaufrette/StreamWrapperSpec.php index 613d2b4b8..f8b6dd94a 100644 --- a/spec/Gaufrette/StreamWrapperSpec.php +++ b/spec/Gaufrette/StreamWrapperSpec.php @@ -5,6 +5,7 @@ use Gaufrette\FilesystemMap; use Gaufrette\Filesystem; use Gaufrette\Stream; +use Gaufrette\StreamWrapper; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -19,28 +20,31 @@ function let(FilesystemMap $map, Filesystem $filesystem, Stream $stream) function it_is_initializable() { - $this->shouldHaveType('Gaufrette\StreamWrapper'); + $this->shouldHaveType(StreamWrapper::class); } function it_opens_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); - $this->stream_open('gaufrette://some/filename', 'r+')->shouldReturn(true); + $this + ->stream_open('gaufrette://some/filename', 'r+', STREAM_REPORT_ERRORS) + ->shouldReturn(true) + ; } function it_does_not_open_stream_when_key_is_not_defined() { $this ->shouldThrow(new \InvalidArgumentException('The specified path (gaufrette://some) is invalid.')) - ->duringStream_open('gaufrette://some', 'r+'); + ->duringStream_open('gaufrette://some', 'r+', STREAM_REPORT_ERRORS); } function it_does_not_open_stream_when_host_is_not_defined() { $this ->shouldThrow(new \InvalidArgumentException('The specified path (gaufrette:///somefile) is invalid.')) - ->duringStream_open('gaufrette:///somefile', 'r+') + ->duringStream_open('gaufrette:///somefile', 'r+', STREAM_REPORT_ERRORS) ; } @@ -54,7 +58,7 @@ function it_does_not_read_from_stream(Stream $stream) $stream->open(Argument::any())->willReturn(true); $stream->read(4)->willReturn('some'); - $this->stream_open('gaufrette://some/filename', 'r+'); + $this->stream_open('gaufrette://some/filename', 'r+', STREAM_REPORT_ERRORS); $this->stream_read(4)->shouldReturn('some'); } @@ -68,7 +72,7 @@ function it_writes_to_stream(Stream $stream) $stream->open(Argument::any())->willReturn(true); $stream->write('some content')->shouldBeCalled()->willReturn(12); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_write('some content')->shouldReturn(12); } @@ -82,7 +86,7 @@ function it_closes_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); $stream->close()->shouldBeCalled(); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_close(); } @@ -96,7 +100,7 @@ function it_flushes_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); $stream->flush()->shouldBeCalled(); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_flush(); } @@ -110,7 +114,7 @@ function it_seeks_in_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); $stream->seek(12, SEEK_SET)->shouldBeCalled()->willReturn(true); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_seek(12, SEEK_SET)->shouldReturn(true); } @@ -124,7 +128,7 @@ function it_does_tell_about_position_in_stream(Stream $stream) { $stream->open(Argument::any())->willReturn(true); $stream->tell()->shouldBeCalled()->willReturn(12); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_tell()->shouldReturn(12); } @@ -137,7 +141,7 @@ function it_does_not_mark_as_eof_if_stream_is_not_opened(Stream $stream) function it_checks_if_eof(Stream $stream) { $stream->open(Argument::any())->willReturn(true); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $stream->eof()->willReturn(false); $this->stream_eof()->shouldReturn(false); @@ -171,7 +175,7 @@ function it_stats_file(Stream $stream) $stream->open(Argument::any())->willReturn(true); $stream->stat()->willReturn($stat); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_stat()->shouldReturn($stat); } @@ -230,7 +234,7 @@ function it_casts_stream(Stream $stream) $stream->open(Argument::any())->willReturn(true); $stream->cast(STREAM_CAST_FOR_SELECT)->willReturn('resource'); - $this->stream_open('gaufrette://some/filename', 'w+'); + $this->stream_open('gaufrette://some/filename', 'w+', STREAM_REPORT_ERRORS); $this->stream_cast(STREAM_CAST_FOR_SELECT)->shouldReturn('resource'); } } diff --git a/src/Gaufrette/Adapter/Zip.php b/src/Gaufrette/Adapter/Zip.php index 2a4b6f691..a4c90bc59 100644 --- a/src/Gaufrette/Adapter/Zip.php +++ b/src/Gaufrette/Adapter/Zip.php @@ -135,7 +135,7 @@ public function getStat(string $key): array public function __destruct() { - if ($this->zipArchive) { + if (isset($this->zipArchive)) { try { $this->zipArchive->close(); } catch (\Exception $e) { diff --git a/src/Gaufrette/StreamWrapper.php b/src/Gaufrette/StreamWrapper.php index 5eb052a9a..94e2cf284 100644 --- a/src/Gaufrette/StreamWrapper.php +++ b/src/Gaufrette/StreamWrapper.php @@ -81,7 +81,10 @@ protected static function streamWrapperRegister(string $scheme, string $classNam return stream_wrapper_register($scheme, $className); } - public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool + /** + * @param STREAM_USE_PATH|STREAM_REPORT_ERRORS|9 $options + */ + public function stream_open(string $path, string $mode, int $options, ?string &$opened_path = null): bool { $this->stream = $this->createStream($path);