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

74 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.
*/
namespace Respect\Validation\Rules;
/**
* @group rule
* @covers Respect\Validation\Rules\ResourceType
* @covers Respect\Validation\Exceptions\ResourceTypeException
2015-08-20 05:55:32 +02:00
*/
class ResourceTypeTest extends \PHPUnit_Framework_TestCase
2015-08-20 05:55:32 +02:00
{
protected $rule;
protected function setUp()
{
$this->rule = new ResourceType();
2015-08-20 05:55:32 +02:00
}
/**
* @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
2015-08-20 05:55:32 +02:00
* @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),
);
}
}