Location: PHPKode > projects > GnomePHP > peec-GnomePHP-b5a360b/gnomephp/testsuite/TestValue.php
<?php
namespace gnomephp\testsuite;

class TestValue{
	
	private $value;
	private $name;
	
	private $result=array();
	
	public function __construct($value, $name){
		$this->value =$value;
		$this->name = $name;
	}
	
	public function getValue(){
		return $this->value;
	}
	public function getName(){
		return $this->name;
	}
	
	/**
	 * Tests if $var is a object.
	 * @param mixed $var
	 */
	public function assertObject(){
		$this->result[] = array(__METHOD__, is_object($this->value));
		return $this;
	}
	/**
	 * Tests if $var is a string.
	 * @param mixed $var
	 */
	public function assertString(){
		$this->result[] = array(__METHOD__, is_string($this->value));
		return $this;
	}
	/**
	 * Tests if $var is a boolean.
	 * @param mixed $var
	 */
	public function assertBool(){
		$this->result[] = array(__METHOD__, is_bool($this->value));
		return $this;
	}
	/**
	 * Tests if $var is true.
	 * @param mixed $var
	 */
	public function assertTrue(){
		$this->result[] = array(__METHOD__,(bool)$this->value);
		return $this;
	}
	
	/**
	 * Tests if $var is false.
	 * @param mixed $var
	 */
	public function assertFalse(){
		$this->result[] = array(__METHOD__,!((bool)$this->value));
		return $this;
	}
	/**
	 * Tests if $var is a integer.
	 * @param mixed $var
	 */
	public function assertInt(){
		$this->result[] = array(__METHOD__,is_int($this->value));
		return $this;
	}
	/**
	 * Tests if $var is a numeric value.
	 * @param mixed $var
	 */
	public function assertNumeric(){
		$this->result[] = array(__METHOD__,is_numeric($this->value));
		return $this;
	}
	
	/**
	 * Tests if $var is a float.
	 * @param mixed $var
	 */
	public function assertFloat(){
		$this->result[] = array(__METHOD__,is_float($this->value));
		return $this;
	}
	
	/**
	 * Tests if $var is a double.
	 * @param mixed $var
	 */
	public function assertDouble(){
		$this->result[] = array(__METHOD__,is_double($this->value));
		return $this;
	}
	
	/**
	 * Tests if $var is a array.
	 * @param mixed $var
	 */
	public function assertArray(){
		$this->result[] = array(__METHOD__,is_array($this->value));
		return $this;
	}
	/**
	 * Tests if $var is null.
	 * @param mixed $var
	 */
	public function assertNull(){
		$this->result[] = array(__METHOD__,is_null($this->value));
		return $this;
	}
	/**
	 * Tests if $var is NOT null.
	 * @param mixed $var
	 */
	public function assertNotNull(){
		$this->result[] = array(__METHOD__,!is_null($this->value));
		return $this;
	}
	/**
	 * Tests if $var is instanceof $class
	 * @param mixed $var
	 */
	public function assertInstanceOf($class){
		$this->result[] = array(__METHOD__,($this->value instanceof $class));
		return $this;
	}
	/**
	 * Tests if $var is equal to $compare.
	 * @param mixed $var
	 */
	public function assertEqual($compare){
		$this->result[] = array(__METHOD__,$this->value == $compare);
		return $this;
	}
	/**
	 * Tests if $var is not equal to $compare.
	 * @param mixed $var
	 */
	public function assertNotEqual($compare){
		$this->result[] = array(__METHOD__,$this->value != $compare);
		return $this;
	}
	/**
	 * Tests if $var is IDENTICAL (===) to $compare.
	 * @param mixed $var
	 */
	public function assertIdentical($compare){
		$this->result[] = array(__METHOD__,$this->value === $compare);
		return $this;
	}
	/**
	 * Tests if $var is regexp compared to $compare.
	 * @param mixed $var
	 */
	public function assertPattern($pattern){
		$this->result[] = array(__METHOD__,preg_match($pattern, $this->value));
		return $this;
	}
	
	
	/**
	 * Validates all the asserts.
	 * Returns false if one of the asserts failed.
	 */
	public function validate(){
		foreach($this->result as $res){
			if (!$res[1])return false;
		}
		return true;
	}
	/**
	 * Gets all the failed assertions.
	 */
	public function getFailedAsserts(){
		$array = array();
		foreach($this->result as $res){
			if (!$res[1])$array[] = $res;
		}
		return $array;
	}
}
Return current item: GnomePHP