Skip to content

Commit

Permalink
test: fix phpspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Oct 27, 2023
1 parent 4fbaebf commit b0b673d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
3 changes: 2 additions & 1 deletion spec/Gaufrette/Adapter/ZipSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace spec\Gaufrette\Adapter;

use Gaufrette\Adapter;
use PhpSpec\ObjectBehavior;

class ZipSpec extends ObjectBehavior
Expand All @@ -13,6 +14,6 @@ function let()

function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
$this->shouldHaveType(Adapter::class);
}
}
2 changes: 1 addition & 1 deletion spec/Gaufrette/FilesystemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 17 additions & 13 deletions spec/Gaufrette/StreamWrapperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Gaufrette\FilesystemMap;
use Gaufrette\Filesystem;
use Gaufrette\Stream;
use Gaufrette\StreamWrapper;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

Expand All @@ -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)
;
}

Expand All @@ -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');
}

Expand All @@ -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);
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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');
}
}
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/Gaufrette/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b0b673d

Please sign in to comment.