respect-validation/tests/unit/Rules/ResourceTypeTest.php

79 lines
1.7 KiB
PHP
Raw Normal View History

2015-08-20 05:55:32 +02:00
<?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);
2015-08-20 05:55:32 +02:00
namespace Respect\Validation\Rules;
2017-11-04 11:21:40 +01:00
use PHPUnit\Framework\TestCase;
2015-08-20 05:55:32 +02:00
/**
* @group rule
2017-02-04 14:01:14 +01:00
* @covers \Respect\Validation\Rules\ResourceType
* @covers \Respect\Validation\Exceptions\ResourceTypeException
2015-08-20 05:55:32 +02:00
*/
2017-11-04 11:21:40 +01:00
class ResourceTypeTest extends TestCase
2015-08-20 05:55:32 +02:00
{
protected $rule;
protected function setUp(): void
2015-08-20 05:55:32 +02:00
{
$this->rule = new ResourceType();
2015-08-20 05:55:32 +02:00
}
/**
* @dataProvider providerForResource
*/
public function testShouldValidateResourceNumbers($input): void
2015-08-20 05:55:32 +02:00
{
self::assertTrue($this->rule->validate($input));
2015-08-20 05:55:32 +02:00
}
/**
* @dataProvider providerForNonResource
*/
public function testShouldNotValidateNonResourceNumbers($input): void
2015-08-20 05:55:32 +02:00
{
self::assertFalse($this->rule->validate($input));
2015-08-20 05:55:32 +02:00
}
/**
2017-02-04 14:01:14 +01:00
* @expectedException \Respect\Validation\Exceptions\ResourceTypeException
2015-08-20 05:55:32 +02:00
* @expectedExceptionMessage "Something" must be a resource
*/
public function testShouldThrowResourceExceptionWhenChecking(): void
2015-08-20 05:55:32 +02:00
{
$this->rule->check('Something');
}
public function providerForResource()
{
2015-10-18 03:44:47 +02:00
return [
[stream_context_create()],
[tmpfile()],
[xml_parser_create()],
];
2015-08-20 05:55:32 +02:00
}
public function providerForNonResource()
{
2015-10-18 03:44:47 +02:00
return [
['String'],
[123],
[[]],
[function (): void {
2016-10-30 10:39:23 +01:00
}],
2015-10-18 03:44:47 +02:00
[new \stdClass()],
[null],
];
2015-08-20 05:55:32 +02:00
}
}