mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
One this method should throw an exception when the input is not valid, returning `TRUE` when it succeeds is not really consistent.
68 lines
1.8 KiB
PHP
68 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;
|
|
|
|
/**
|
|
* @group rule
|
|
* @covers \Respect\Validation\Rules\Instance
|
|
* @covers \Respect\Validation\Exceptions\InstanceException
|
|
*/
|
|
class InstanceTest extends TestCase
|
|
{
|
|
protected $instanceValidator;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->instanceValidator = new Instance('ArrayObject');
|
|
}
|
|
|
|
public function testInstanceValidationShouldReturnFalseForEmpty(): void
|
|
{
|
|
self::assertFalse($this->instanceValidator->__invoke(''));
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Respect\Validation\Exceptions\InstanceException
|
|
*/
|
|
public function testInstanceValidationShouldNotAssertEmpty(): void
|
|
{
|
|
$this->instanceValidator->assert('');
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Respect\Validation\Exceptions\InstanceException
|
|
*/
|
|
public function testInstanceValidationShouldNotCheckEmpty(): void
|
|
{
|
|
$this->instanceValidator->check('');
|
|
}
|
|
|
|
public function testInstanceValidationShouldReturnTrueForValidInstances(): void
|
|
{
|
|
self::assertTrue($this->instanceValidator->__invoke(new \ArrayObject()));
|
|
$this->instanceValidator->assert(new \ArrayObject());
|
|
$this->instanceValidator->check(new \ArrayObject());
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Respect\Validation\Exceptions\InstanceException
|
|
*/
|
|
public function testInvalidInstancesShouldThrowInstanceException(): void
|
|
{
|
|
self::assertFalse($this->instanceValidator->validate(new \stdClass()));
|
|
$this->instanceValidator->assert(new \stdClass());
|
|
}
|
|
}
|