respect-validation/tests/unit/Rules/FileTest.php
Henrique Moody 258a456eec
Setup PHPStan (PHP Static Analysis Tool)
Require "phpstan/phpstan" for development and add to the Travis CI
configuration file to execute the analysis when Travis executes the
build with the version 7.2 of PHP.

The level of the configuration is very week for now (just "1") and still
quite some changes had to be made in order to make the analysis pass. I
hope it does not take much time to increase the level of the strictness
of the analyses.

I tried to configure that before but because of dependencies with
"symfony/validator" it was not possible.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-22 19:10:20 +02:00

81 lines
1.8 KiB
PHP

<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use PHPUnit\Framework\TestCase;
$GLOBALS['is_file'] = null;
function is_file($file)
{
$return = \is_file($file); // Running the real function
if (null !== $GLOBALS['is_file']) {
$return = $GLOBALS['is_file'];
$GLOBALS['is_file'] = null;
}
return $return;
}
/**
* @group rule
* @covers \Respect\Validation\Exceptions\FileException
* @covers \Respect\Validation\Rules\File
*/
class FileTest extends TestCase
{
/**
* @covers \Respect\Validation\Rules\File::validate
*
* @test
*/
public function validFileShouldReturnTrue(): void
{
$GLOBALS['is_file'] = true;
$rule = new File();
$input = '/path/of/a/valid/file.txt';
self::assertTrue($rule->validate($input));
}
/**
* @covers \Respect\Validation\Rules\File::validate
*
* @test
*/
public function invalidFileShouldReturnFalse(): void
{
$GLOBALS['is_file'] = false;
$rule = new File();
$input = '/path/of/an/invalid/file.txt';
self::assertFalse($rule->validate($input));
}
/**
* @covers \Respect\Validation\Rules\File::validate
*
* @test
*/
public function shouldValidateObjects(): void
{
$rule = new File();
$object = $this->createMock('SplFileInfo');
$object->expects(self::once())
->method('isFile')
->will(self::returnValue(true));
self::assertTrue($rule->validate($object));
}
}