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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2015-10-07 17:33:39 +02:00
|
|
|
$this->rule = new ResourceType();
|
2015-08-20 05:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForResource
|
|
|
|
*/
|
|
|
|
public function testShouldValidateResourceNumbers($input)
|
|
|
|
{
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertTrue($this->rule->validate($input));
|
2015-08-20 05:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForNonResource
|
|
|
|
*/
|
|
|
|
public function testShouldNotValidateNonResourceNumbers($input)
|
|
|
|
{
|
2017-11-12 14:33:39 +01: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()
|
|
|
|
{
|
|
|
|
$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],
|
|
|
|
[[]],
|
2016-10-30 10:39:23 +01:00
|
|
|
[function () {
|
|
|
|
}],
|
2015-10-18 03:44:47 +02:00
|
|
|
[new \stdClass()],
|
|
|
|
[null],
|
|
|
|
];
|
2015-08-20 05:55:32 +02:00
|
|
|
}
|
|
|
|
}
|