respect-validation/tests/library/Stubs/UploadedFileStub.php
Henrique Moody 07c4095f11
Create stubs for PSR-7 interfaces
When we write tests requiring those interfaces, we create mocks. Those
new stubs will make those tests easier to read and allow us to reduce
the number of mocks we write with PHPUnit, making the code in the tests
a bit less complex.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2023-04-03 16:28:37 +02:00

66 lines
1.1 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Test\Stubs;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use const UPLOAD_ERR_OK;
final class UploadedFileStub implements UploadedFileInterface
{
private ?int $size = null;
public static function create(): self
{
return new self();
}
public static function createWithSize(int $size): self
{
$stub = new self();
$stub->size = $size;
return $stub;
}
public function getStream(): StreamInterface
{
return StreamStub::create();
}
/**
* {@inheritDoc}
*/
public function moveTo($targetPath): void
{
}
public function getSize(): ?int
{
return $this->size;
}
public function getError(): int
{
return UPLOAD_ERR_OK;
}
public function getClientFilename(): ?string
{
return null;
}
public function getClientMediaType(): ?string
{
return null;
}
}