* * For the full copyright and license information, please view the "LICENSE.md" * file that was distributed with this source code. */ namespace Respect\Validation\Rules; use PHPUnit\Framework\TestCase; /** * @group rule * @covers \Respect\Validation\Rules\AnyOf * @covers \Respect\Validation\Exceptions\AnyOfException */ class AnyOfTest extends TestCase { public function testValid() { $valid1 = new Callback(function () { return false; }); $valid2 = new Callback(function () { return true; }); $valid3 = new Callback(function () { return false; }); $o = new AnyOf($valid1, $valid2, $valid3); $this->assertTrue($o->validate('any')); $this->assertTrue($o->assert('any')); $this->assertTrue($o->check('any')); } /** * @expectedException \Respect\Validation\Exceptions\AnyOfException */ public function testInvalid() { $valid1 = new Callback(function () { return false; }); $valid2 = new Callback(function () { return false; }); $valid3 = new Callback(function () { return false; }); $o = new AnyOf($valid1, $valid2, $valid3); $this->assertFalse($o->validate('any')); $this->assertFalse($o->assert('any')); } /** * @expectedException \Respect\Validation\Exceptions\XdigitException */ public function testInvalidCheck() { $o = new AnyOf(new Xdigit(), new Alnum()); $this->assertFalse($o->validate(-10)); $this->assertFalse($o->check(-10)); } }