1<?php 2/* 3 * This file is part of PHPUnit. 4 * 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11abstract class PHPUnit_Framework_Constraint_Composite extends PHPUnit_Framework_Constraint 12{ 13 /** 14 * @var PHPUnit_Framework_Constraint 15 */ 16 protected $innerConstraint; 17 18 /** 19 * @param PHPUnit_Framework_Constraint $innerConstraint 20 */ 21 public function __construct(PHPUnit_Framework_Constraint $innerConstraint) 22 { 23 parent::__construct(); 24 $this->innerConstraint = $innerConstraint; 25 } 26 27 /** 28 * Evaluates the constraint for parameter $other 29 * 30 * If $returnResult is set to false (the default), an exception is thrown 31 * in case of a failure. null is returned otherwise. 32 * 33 * If $returnResult is true, the result of the evaluation is returned as 34 * a boolean value instead: true in case of success, false in case of a 35 * failure. 36 * 37 * @param mixed $other Value or object to evaluate. 38 * @param string $description Additional information about the test 39 * @param bool $returnResult Whether to return a result or throw an exception 40 * 41 * @return mixed 42 * 43 * @throws PHPUnit_Framework_ExpectationFailedException 44 */ 45 public function evaluate($other, $description = '', $returnResult = false) 46 { 47 try { 48 return $this->innerConstraint->evaluate( 49 $other, 50 $description, 51 $returnResult 52 ); 53 } catch (PHPUnit_Framework_ExpectationFailedException $e) { 54 $this->fail($other, $description); 55 } 56 } 57 58 /** 59 * Counts the number of constraint elements. 60 * 61 * @return int 62 */ 63 public function count() 64 { 65 return count($this->innerConstraint); 66 } 67} 68