1<?php 2 3/* 4 * This file is part of Respect/Validation. 5 * 6 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net> 7 * 8 * For the full copyright and license information, please view the "LICENSE.md" 9 * file that was distributed with this source code. 10 */ 11 12namespace Respect\Validation\Rules; 13 14/** 15 * @group rule 16 * @covers Respect\Validation\Rules\OneOf 17 * @covers Respect\Validation\Exceptions\OneOfException 18 */ 19class OneOfTest extends \PHPUnit_Framework_TestCase 20{ 21 public function testValid() 22 { 23 $valid1 = new Callback(function () { 24 return false; 25 }); 26 $valid2 = new Callback(function () { 27 return true; 28 }); 29 $valid3 = new Callback(function () { 30 return false; 31 }); 32 $o = new OneOf($valid1, $valid2, $valid3); 33 $this->assertTrue($o->validate('any')); 34 $this->assertTrue($o->assert('any')); 35 $this->assertTrue($o->check('any')); 36 } 37 38 /** 39 * @expectedException Respect\Validation\Exceptions\OneOfException 40 */ 41 public function testInvalid() 42 { 43 $valid1 = new Callback(function () { 44 return false; 45 }); 46 $valid2 = new Callback(function () { 47 return false; 48 }); 49 $valid3 = new Callback(function () { 50 return false; 51 }); 52 $o = new OneOf($valid1, $valid2, $valid3); 53 $this->assertFalse($o->validate('any')); 54 $this->assertFalse($o->assert('any')); 55 } 56 57 /** 58 * @expectedException Respect\Validation\Exceptions\XdigitException 59 */ 60 public function testInvalidCheck() 61 { 62 $o = new OneOf(new Xdigit(), new Alnum()); 63 $this->assertFalse($o->validate(-10)); 64 $this->assertFalse($o->check(-10)); 65 } 66} 67