2013-01-11 09:13:15 +01:00
|
|
|
<?php
|
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2013-01-11 09:13:15 +01:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-09-30 18:30:40 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
|
|
use SplFileInfo;
|
|
|
|
use SplFileObject;
|
|
|
|
use stdClass;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2018-09-30 18:30:40 +02:00
|
|
|
use const PHP_INT_MAX;
|
2013-01-11 09:13:15 +01:00
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
2018-09-30 18:30:40 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\File
|
2018-09-30 18:30:40 +02:00
|
|
|
*
|
|
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
|
|
|
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2018-09-30 18:30:40 +02:00
|
|
|
final class FileTest extends RuleTestCase
|
2013-01-11 09:13:15 +01:00
|
|
|
{
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2013-01-11 09:13:15 +01:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2013-01-11 09:13:15 +01:00
|
|
|
{
|
2018-09-30 18:30:40 +02:00
|
|
|
$sut = new File();
|
2013-01-11 09:13:15 +01:00
|
|
|
|
2018-09-30 18:30:40 +02:00
|
|
|
return [
|
|
|
|
'filename' => [$sut, __FILE__],
|
2023-04-02 14:33:29 +02:00
|
|
|
'SplFileInfo' => [$sut, new SplFileInfo(self::fixture('valid-image.png'))],
|
|
|
|
'SplFileObject' => [$sut, new SplFileObject(self::fixture('invalid-image.png'))],
|
2018-09-30 18:30:40 +02:00
|
|
|
];
|
2013-01-11 09:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2013-01-11 09:13:15 +01:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2013-01-11 09:13:15 +01:00
|
|
|
{
|
2018-09-30 18:30:40 +02:00
|
|
|
$sut = new File();
|
2013-01-11 09:13:15 +01:00
|
|
|
|
2018-09-30 18:30:40 +02:00
|
|
|
return [
|
|
|
|
'directory' => [$sut, __DIR__],
|
|
|
|
'object' => [$sut, new stdClass()],
|
|
|
|
'array' => [$sut, []],
|
|
|
|
'invalid filename' => [$sut, 'not-a-file-at-all'],
|
|
|
|
'integer' => [$sut, PHP_INT_MAX],
|
|
|
|
'float' => [$sut, 1.222],
|
|
|
|
'boolean true' => [$sut, true],
|
|
|
|
'boolean false' => [$sut, false],
|
|
|
|
];
|
2013-01-11 09:13:15 +01:00
|
|
|
}
|
|
|
|
}
|