createStreamFromResource($resource); } /** * Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` method prophecy. * * @param string $argKey Argument for the method prophecy. * @param mixed $returnValue Return value of the `getMetadata` method. * * @return StreamInterface */ protected function prophesizeStreamInterfaceWithGetMetadataMethod(string $argKey, $returnValue): StreamInterface { $streamProphecy = $this->prophesize(StreamInterface::class); /** @noinspection PhpUndefinedMethodInspection */ $streamProphecy ->getMetadata($argKey) ->willReturn($returnValue) ->shouldBeCalled(); /** @var StreamInterface $stream */ $stream = $streamProphecy->reveal(); return $stream; } public function testCreateUploadedFileWithInvalidUri() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('File is not readable.'); // Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` method prophecy. $streamProphecy = $this->prophesize(StreamInterface::class); /** @noinspection PhpUndefinedMethodInspection */ $streamProphecy ->getMetadata('uri') ->willReturn(null) ->shouldBeCalled(); /** @var StreamInterface $stream */ $stream = $streamProphecy->reveal(); $this->factory->createUploadedFile($stream); } public function testCreateUploadedFileWithNonReadableFile() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('File is not readable.'); // Prophesize a `\Psr\Http\Message\StreamInterface` with a `getMetadata` and `isReadable` method prophecies. $streamProphecy = $this->prophesize(StreamInterface::class); /** @noinspection PhpUndefinedMethodInspection */ $streamProphecy ->getMetadata('uri') ->willReturn('non-readable') ->shouldBeCalled(); /** @noinspection PhpUndefinedMethodInspection */ $streamProphecy ->isReadable() ->willReturn(false) ->shouldBeCalled(); /** @var StreamInterface $stream */ $stream = $streamProphecy->reveal(); $this->factory->createUploadedFile($stream); } }