mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 08:42:15 +02:00
74 lines
1.7 KiB
PHP
74 lines
1.7 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.
|
|
*/
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
/**
|
|
* @group rule
|
|
* @covers Respect\Validation\Rules\ResourceType
|
|
* @covers Respect\Validation\Exceptions\ResourceTypeException
|
|
*/
|
|
class ResourceTypeTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
protected $rule;
|
|
|
|
protected function setUp()
|
|
{
|
|
$this->rule = new ResourceType();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForResource
|
|
*/
|
|
public function testShouldValidateResourceNumbers($input)
|
|
{
|
|
$this->assertTrue($this->rule->validate($input));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForNonResource
|
|
*/
|
|
public function testShouldNotValidateNonResourceNumbers($input)
|
|
{
|
|
$this->assertFalse($this->rule->validate($input));
|
|
}
|
|
|
|
/**
|
|
* @expectedException Respect\Validation\Exceptions\ResourceTypeException
|
|
* @expectedExceptionMessage "Something" must be a resource
|
|
*/
|
|
public function testShouldThrowResourceExceptionWhenChecking()
|
|
{
|
|
$this->rule->check('Something');
|
|
}
|
|
|
|
public function providerForResource()
|
|
{
|
|
return array(
|
|
array(stream_context_create()),
|
|
array(tmpfile()),
|
|
array(xml_parser_create()),
|
|
);
|
|
}
|
|
|
|
public function providerForNonResource()
|
|
{
|
|
return array(
|
|
array('String'),
|
|
array(123),
|
|
array(array()),
|
|
array(function () {}),
|
|
array(new \stdClass()),
|
|
array(null),
|
|
);
|
|
}
|
|
}
|