2015-11-06 02:21:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-11-06 02:21:42 +01:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-11-06 02:21:42 +01:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
|
|
|
use finfo;
|
2024-01-28 01:46:21 +01:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2018-01-07 14:12:55 +01:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2015-11-06 02:21:42 +01:00
|
|
|
use SplFileInfo;
|
|
|
|
use SplFileObject;
|
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
#[Group('rule')]
|
|
|
|
#[CoversClass(Image::class)]
|
2018-07-22 23:18:49 +02:00
|
|
|
final class ImageTest extends RuleTestCase
|
2015-11-06 02:21:42 +01:00
|
|
|
{
|
2024-01-28 01:46:21 +01:00
|
|
|
#[Test]
|
2023-04-02 16:00:37 +02:00
|
|
|
public function shouldValidateWithDefinedInstanceOfFileInfo(): void
|
|
|
|
{
|
|
|
|
$input = self::fixture('valid-image.gif');
|
|
|
|
|
|
|
|
$finfo = $this->createMock(finfo::class);
|
|
|
|
$finfo
|
|
|
|
->expects(self::once())
|
|
|
|
->method('file')
|
|
|
|
->with($input)
|
2024-01-28 01:46:21 +01:00
|
|
|
->willReturn('image/gif');
|
2023-04-02 16:00:37 +02:00
|
|
|
|
|
|
|
$rule = new Image($finfo);
|
|
|
|
|
2024-03-25 09:18:05 +01:00
|
|
|
self::assertValidInput($rule, $input);
|
2023-04-02 16:00:37 +02:00
|
|
|
}
|
|
|
|
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{Image, mixed}> */
|
|
|
|
public static function providerForValidInput(): iterable
|
2015-11-06 02:21:42 +01:00
|
|
|
{
|
|
|
|
$rule = new Image();
|
|
|
|
|
|
|
|
return [
|
2023-04-02 14:33:29 +02:00
|
|
|
[$rule, self::fixture('valid-image.gif')],
|
|
|
|
[$rule, self::fixture('valid-image.jpg')],
|
|
|
|
[$rule, self::fixture('valid-image.png')],
|
|
|
|
[$rule, new SplFileInfo(self::fixture('valid-image.gif'))],
|
|
|
|
[$rule, new SplFileInfo(self::fixture('valid-image.jpg'))],
|
|
|
|
[$rule, new SplFileObject(self::fixture('valid-image.png'))],
|
2015-11-06 02:21:42 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{Image, mixed}> */
|
|
|
|
public static function providerForInvalidInput(): iterable
|
2015-11-06 02:21:42 +01:00
|
|
|
{
|
|
|
|
$rule = new Image();
|
|
|
|
|
|
|
|
return [
|
2023-04-02 14:33:29 +02:00
|
|
|
[$rule, self::fixture('invalid-image.png')],
|
2015-11-06 02:21:42 +01:00
|
|
|
[$rule, 'asdf'],
|
|
|
|
[$rule, 1],
|
|
|
|
[$rule, true],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|