mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 16:52:16 +02:00
e8fcdb661f
We had a method that returned the full path of the fixture directory, and we frequently would concatenate that path with a file we needed. I changed it to include the file's path inside the fixture directory. That way, we avoid repeating the same patter over and over. I made the method static because we use it in data providers, which need to be static. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use Psr\Http\Message\StreamInterface;
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
use SplFileInfo;
|
|
use stdClass;
|
|
|
|
/**
|
|
* @group rule
|
|
*
|
|
* @covers \Respect\Validation\Rules\Readable
|
|
*
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
final class ReadableTest extends RuleTestCase
|
|
{
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function providerForValidInput(): array
|
|
{
|
|
$file = self::fixture('valid-image.gif');
|
|
$rule = new Readable();
|
|
|
|
return [
|
|
[$rule, $file],
|
|
[$rule, new SplFileInfo($file)],
|
|
[$rule, $this->createPsr7Stream(true)],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function providerForInvalidInput(): array
|
|
{
|
|
$file = self::fixture('invalid-image.gif');
|
|
$rule = new Readable();
|
|
|
|
return [
|
|
[$rule, $file],
|
|
[$rule, new SplFileInfo($file)],
|
|
[$rule, new stdClass()],
|
|
[$rule, $this->createPsr7Stream(false)],
|
|
];
|
|
}
|
|
|
|
private function createPsr7Stream(bool $isReadable): StreamInterface
|
|
{
|
|
$stream = $this->createMock(StreamInterface::class);
|
|
$stream->expects(self::any())->method('isReadable')->willReturn($isReadable);
|
|
|
|
return $stream;
|
|
}
|
|
}
|