2015-06-16 05:41:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-16 05:41:49 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-06-16 05:41:49 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
2018-09-20 04:07:43 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2015-06-16 05:41:49 +02:00
|
|
|
use SplFileInfo;
|
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
#[Group('rule')]
|
|
|
|
#[CoversClass(Extension::class)]
|
2018-09-20 04:07:43 +02:00
|
|
|
final class ExtensionTest extends RuleTestCase
|
2015-06-16 05:41:49 +02:00
|
|
|
{
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{Extension, mixed}> */
|
|
|
|
public static function providerForValidInput(): iterable
|
2015-06-16 05:41:49 +02:00
|
|
|
{
|
2018-09-20 04:07:43 +02:00
|
|
|
return [
|
|
|
|
'txt' => [new Extension('txt'), 'filename.txt'],
|
|
|
|
'jpg' => [new Extension('jpg'), 'filename.jpg'],
|
|
|
|
'inc' => [new Extension('inc'), 'filename.inc'],
|
|
|
|
'bz2' => [new Extension('bz2'), 'filename.foo.bar.bz2'],
|
|
|
|
'php' => [new Extension('php'), new SplFileInfo(__FILE__)],
|
2023-04-02 14:33:29 +02:00
|
|
|
'png' => [new Extension('png'), self::fixture('valid-image.png')],
|
|
|
|
'gif' => [new Extension('gif'), self::fixture('valid-image.gif')],
|
|
|
|
'file-invalid' => [new Extension('png'), self::fixture('invalid-image.png')],
|
2018-09-20 04:07:43 +02:00
|
|
|
];
|
2015-06-16 05:41:49 +02:00
|
|
|
}
|
|
|
|
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{Extension, mixed}> */
|
|
|
|
public static function providerForInvalidInput(): iterable
|
2015-06-16 05:41:49 +02:00
|
|
|
{
|
2018-09-20 04:07:43 +02:00
|
|
|
return [
|
|
|
|
'jpg' => [new Extension('jpg'), 'filename.txt'],
|
|
|
|
'txt' => [new Extension('txt'), 'filename.jpg'],
|
|
|
|
'bz2' => [new Extension('bz2'), 'filename.inc.php'],
|
|
|
|
'js' => [new Extension('js'), 'filename.foo.bar.bz2'],
|
|
|
|
'php' => [new Extension('php'), [__FILE__]],
|
|
|
|
'mp3' => [new Extension('mp3'), 999],
|
|
|
|
'gif' => [new Extension('gif'), ''],
|
|
|
|
'doc' => [new Extension('doc'), null],
|
|
|
|
];
|
2015-06-16 05:41:49 +02:00
|
|
|
}
|
|
|
|
}
|