From 64a02f3ee2bfecefc147b1409d9a1e79131c64f5 Mon Sep 17 00:00:00 2001 From: Blaine Schmeisser Date: Fri, 18 Jan 2013 15:52:36 -0600 Subject: [PATCH] Port assertion methods from li3_unit to core. --- test/Unit.php | 956 ++++++++++++++++++++++++++++++++++ tests/cases/test/UnitTest.php | 934 +++++++++++++++++++++++++++++++++ 2 files changed, 1890 insertions(+) diff --git a/test/Unit.php b/test/Unit.php index ea906566e9..b59ddbbc2e 100644 --- a/test/Unit.php +++ b/test/Unit.php @@ -9,6 +9,8 @@ namespace lithium\test; use Exception; +use ReflectionClass; +use InvalidArgumentException; use lithium\util\String; use lithium\core\Libraries; use lithium\util\Validator; @@ -55,6 +57,29 @@ class Unit extends \lithium\core\Object { */ protected $_expected = array(); + /** + * Internal types and how to test for them + * + * @var array + */ + protected static $_internalTypes = array( + 'array' => 'is_array', + 'bool' => 'is_bool', + 'callable' => 'is_callable', + 'double' => 'is_double', + 'float' => 'is_float', + 'int' => 'is_int', + 'integer' => 'is_integer', + 'long' => 'is_long', + 'null' => 'is_null', + 'numeric' => 'is_numeric', + 'object' => 'is_object', + 'real' => 'is_real', + 'resource' => 'is_resource', + 'scalar' => 'is_scalar', + 'string' => 'is_string' + ); + /** * Finds the test case for the corresponding class name. * @@ -1095,6 +1120,937 @@ protected function _hasNetwork($config = array()) { restore_error_handler(); return !$failed; } + + /** + * Will mark the test `true` if `$count` and `count($arr)` are equal. + * + * {{{ + * $this->assertCount(1, array('foo')); + * }}} + * + * {{{ + * $this->assertCount(2, array('foo', 'bar', 'bar')); + * }}} + * + * @param int $expected Expected count + * @param array $array Result + * @param string $message optional + * @return bool + */ + public function assertCount($expected, $array, $message = '{:message}') { + return $this->assert($expected === ($result = count($array)), $message, array( + 'expected' => $expected, + 'result' => $result, + )); + } + + /** + * Will mark the test `true` if `$count` and `count($arr)` are not equal. + * + * {{{ + * $this->assertNotCount(2, array('foo', 'bar', 'bar')); + * }}} + * + * {{{ + * $this->assertNotCount(1, array('foo')); + * }}} + * + * @param int $expected Expected count + * @param array $array Result + * @param string $message optional + * @return bool + */ + public function assertNotCount($expected, $array, $message = '{:message}') { + return $this->assert($expected !== ($result = count($array)), $message, array( + 'expected' => $expected, + 'result' => $result, + )); + } + + /** + * Will mark the test `true` if `$array` has key `$expected`. + * + * {{{ + * $this->assertArrayHasKey('foo', array('bar' => 'baz')); + * }}} + * + * {{{ + * $this->assertArrayHasKey('bar', array('bar' => 'baz')); + * }}} + * + * @param string $key Key you are looking for + * @param array $array Array to search through + * @param string $message optional + * @return bool + */ + public function assertArrayHasKey($key, $array, $message = '{:message}') { + return $this->assert(isset($array[$key]), $message, array( + 'expected' => $key, + 'result' => $array + )); + } + + /** + * Will mark the test `true` if `$array` does not have key `$expected`. + * + * {{{ + * $this->assertArrayNotHasKey('foo', array('bar' => 'baz')); + * }}} + * + * {{{ + * $this->assertArrayNotHasKey('bar', array('bar' => 'baz')); + * }}} + * + * @param int $key Expected count + * @param array $array Array to search through + * @param string $message optional + * @return bool + */ + public function assertArrayNotHasKey($key, $array, $message = '{:message}') { + return $this->assert(!isset($array[$key]), $message, array( + 'expected' => $key, + 'result' => $array + )); + } + + /** + * Will mark the test `true` if `$class` has an attribute `$attributeName`. + * + * {{{ + * $this->assertClassHasAttribute('name', '\ReflectionClass'); + * }}} + * + * {{{ + * $this->assertClassHasAttribute('__construct', '\ReflectionClass'); + * }}} + * + * @see lithium\test\Unit::assertObjectHasAttribute() + * @throws InvalidArgumentException When $object is not an object + * @throws ReflectionException If the given class does not exist + * @param string $attributeName Attribute you wish to look for + * @param string $class Class name + * @param string $message optional + * @return bool + */ + public function assertClassHasAttribute($attributeName, $class, $message = '{:message}') { + if(!is_string($class)) { + throw new InvalidArgumentException('Argument $class must be a string'); + } + $object = new ReflectionClass($class); + return $this->assert($object->hasProperty($attributeName), $message, array( + 'expected' => $attributeName, + 'result' => $object->getProperties() + )); + } + + /** + * Will mark the test `true` if `$class` has an attribute `$attributeName`. + * + * {{{ + * $this->assertClassNotHasAttribute('__construct', '\ReflectionClass'); + * }}} + * + * {{{ + * $this->assertClassNotHasAttribute('name', '\ReflectionClass'); + * }}} + * + * @see lithium\test\Unit::assertObjectNotHasAttribute() + * @throws InvalidArgumentException When $object is not an object + * @throws ReflectionException If the given class does not exist + * @param string $attributeName Attribute you wish to look for + * @param string $class Class name + * @param string $message optional + * @return bool + */ + public function assertClassNotHasAttribute($attributeName, $class, $message = '{:message}') { + if(!is_string($class)) { + throw new InvalidArgumentException('Argument $class must be a string.'); + } + $object = new ReflectionClass($class); + return $this->assert(!$object->hasProperty($attributeName), $message, array( + 'expected' => $attributeName, + 'result' => $object->getProperties() + )); + } + + /** + * Will mark the test `true` if `$class` has a static property `$attributeName`. + * + * {{{ + * $this->assertClassHasStaticAttribute('foobar', '\lithium\core\StaticObject'); + * }}} + * + * {{{ + * $this->assertClassHasStaticAttribute('_methodFilters', '\lithium\core\StaticObject'); + * }}} + * + * @throws ReflectionException If the given class does not exist + * @param string $attributeName Attribute you wish to look for + * @param string|object $class Class name or object + * @param string $message optional + * @return bool + */ + public function assertClassHasStaticAttribute($attributeName, $class, $message = '{:message}') { + $object = new ReflectionClass($class); + if ($object->hasProperty($attributeName)) { + $attribute = $object->getProperty($attributeName); + return $this->assert($attribute->isStatic(), $message, array( + 'expected' => $attributeName, + 'result' => $object->getProperties() + )); + } + return $this->assert(false, $message, array( + 'expected' => $attributeName, + 'result' => $object->getProperties() + )); + } + + /** + * Will mark the test `true` if `$class` does not have a static property `$attrName`. + * + * {{{ + * $this->assertClassNotHasStaticAttribute('_methodFilters', '\lithium\core\StaticObject'); + * }}} + * + * {{{ + * $this->assertClassNotHasStaticAttribute('foobar', '\lithium\core\StaticObject') + * }}} + * + * @throws ReflectionException If the given class does not exist + * @param string $attrName Attribute you wish to look for + * @param string|object $class Class name or object + * @param string $message optional + * @return bool + */ + public function assertClassNotHasStaticAttribute($attrName, $class, $message = '{:message}') { + $object = new ReflectionClass($class); + if ($object->hasProperty($attrName)) { + $attribute = $object->getProperty($attrName); + return $this->assert(!$attribute->isStatic(), $message, array( + 'expected' => $attrName, + 'result' => $object->getProperties() + )); + } + return $this->assert(true, $message, array( + 'expected' => $attrName, + 'result' => $object->getProperties() + )); + } + + /** + * Will mark the test `true` if `$haystack` contains `$needle` as a value. + * + * {{{ + * $this->assertContains('foo', array('foo', 'bar', 'baz')); + * }}} + * + * {{{ + * $this->assertContains(4, array(1,2,3)); + * }}} + * + * @param string $needle The needle you are looking for + * @param mixed $haystack An array, iterable object, or string + * @param string $message optional + * @return bool + */ + public function assertContains($needle, $haystack, $message = '{:message}') { + if (is_string($haystack)) { + return $this->assert(strpos($haystack, $needle) !== false, $message, array( + 'expected' => $needle, + 'result' => $haystack + )); + } + foreach ($haystack as $key => $value) { + if ($value === $needle) { + return $this->assert(true, $message, array( + 'expected' => $needle, + 'result' => $haystack + )); + } + } + return $this->assert(false, $message, array( + 'expected' => $needle, + 'result' => $haystack + )); + } + + /** + * Will mark the test `true` if `$haystack` does not contain `$needle` as a value. + * + * {{{ + * $this->assertNotContains(4, array(1,2,3)); + * }}} + * + * {{{ + * $this->assertNotContains('foo', array('foo', 'bar', 'baz')); + * }}} + * + * @param string $needle Needle you are looking for + * @param mixed $haystack Array, iterable object, or string + * @param string $message optional + * @return bool + */ + public function assertNotContains($needle, $haystack, $message = '{:message}') { + if(is_string($haystack)) { + return $this->assert(strpos($haystack, $needle) === false, $message, array( + 'expected' => $needle, + 'result' => $haystack + )); + } + foreach($haystack as $key => $value) { + if($value === $needle) { + return $this->assert(false, $message, array( + 'expected' => $needle, + 'result' => $haystack + )); + } + } + return $this->assert(true, $message, array( + 'expected' => $needle, + 'result' => $haystack + )); + } + + /** + * Will mark the test `true` if `$haystack` contains only items of `$type`. + * + * {{{ + * $this->assertContainsOnly('int', array(1,2,3)); + * }}} + * + * {{{ + * $this->assertContainsOnly('int', array('foo', 'bar', 'baz')); + * }}} + * + * @param string $type Data type to check for + * @param mixed $haystack Array or iterable object + * @param string $message optional + * @return bool + */ + public function assertContainsOnly($type, $haystack, $message = '{:message}') { + $method = self::$_internalTypes[$type]; + foreach($haystack as $key => $value) { + if(!$method($value)) { + return $this->assert(false, $message, array( + 'expected' => $type, + 'result' => $haystack + )); + } + } + return $this->assert(true, $message, array( + 'expected' => $type, + 'result' => $haystack + )); + } + + /** + * Will mark the test `true` if `$haystack` does not have any of `$type`. + * + * {{{ + * $this->assertNotContainsOnly('int', array('foo', 'bar', 'baz')); + * }}} + * + * {{{ + * $this->assertNotContainsOnly('int', array(1,2,3)); + * }}} + * + * @param string $type Data type to check for + * @param mixed $haystack Array or iterable object + * @param string $message optional + * @return bool + */ + public function assertNotContainsOnly($type, $haystack, $message = '{:message}') { + $method = self::$_internalTypes[$type]; + foreach ($haystack as $key => $value) { + if (!$method($value)) { + return $this->assert(true, $message, array( + 'expected' => $type, + 'result' => $haystack + )); + } + } + return $this->assert(false, $message, array( + 'expected' => $type, + 'result' => $haystack + )); + } + + /** + * Will mark the test `true` if `$haystack` contains only items of `$type`. + * + * {{{ + * $this->assertContainsOnlyInstancesOf('stdClass', array(new \stdClass)); + * }}} + * + * {{{ + * $this->assertContainsOnlyInstancesOf('stdClass', array(new \lithium\test\Unit)); + * }}} + * + * @param string $class Fully namespaced class name + * @param mixed $haystack Array or iterable object + * @param string $message optional + * @return bool + */ + public function assertContainsOnlyInstancesOf($class, $haystack, $message = '{:message}') { + $result = array(); + foreach($haystack as $key => &$value) { + if(!is_a($value, $class)) { + $result[$key] =& $value; + break; + } + } + return $this->assert(empty($result), $message, array( + 'expected' => $class, + 'result' => $result + )); + } + + /** + * Will mark the test `true` if `$actual` is empty. + * + * {{{ + * $this->assertEmpty(1); + * }}} + * + * {{{ + * $this->assertEmpty(array()); + * }}} + * + * @param string $actual Variable to check + * @param string $message optional + * @return bool + */ + public function assertEmpty($actual, $message = '{:message}') { + return $this->assert(empty($actual), $message, array( + 'expected' => $actual, + 'result' => empty($actual) + )); + } + + /** + * Will mark the test `true` if `$actual` is not empty. + * + * {{{ + * $this->assertNotEmpty(array()); + * }}} + * + * {{{ + * $this->assertNotEmpty(1); + * }}} + * + * @param string $actual Variable to check + * @param string $message optional + * @return bool + */ + public function assertNotEmpty($actual, $message = '{:message}') { + return $this->assert(!empty($actual), $message, array( + 'expected' => $actual, + 'result' => !empty($actual) + )); + } + + /** + * Will mark the test `true` if the contents of `$expected` are equal to the + * contents of `$actual`. + * + * {{{ + * $file1 = LITHIUM_APP_PATH . '/tests/mocks/md/file_1.md'; + * $file2 = LITHIUM_APP_PATH . '/tests/mocks/md/file_1.md.copy'; + * $this->assertFileEquals($file1, $file2); + * }}} + * + * {{{ + * $file1 = LITHIUM_APP_PATH . '/tests/mocks/md/file_1.md'; + * $file2 = LITHIUM_APP_PATH . '/tests/mocks/md/file_2.md'; + * $this->assertFileEquals($file1, $file2); + * }}} + * + * @param string $expected Path to the expected file + * @param string $actual Path to the actual file + * @param string $message optional + * @return bool + */ + public function assertFileEquals($expected, $actual, $message = '{:message}') { + $expected = md5_file($expected); + $result = md5_file($actual); + return $this->assert($expected === $result, $message, compact('expected', 'result')); + } + + /** + * Will mark the test `true` if the contents of `$expected` are not equal to + * the contents of `$actual`. + * + * {{{ + * $file1 = LITHIUM_APP_PATH . '/tests/mocks/md/file_1.md'; + * $file2 = LITHIUM_APP_PATH . '/tests/mocks/md/file_2.md'; + * $this->assertFileNotEquals($file1, $file2); + * }}} + * + * {{{ + * $file1 = LITHIUM_APP_PATH . '/tests/mocks/md/file_1.md'; + * $file2 = LITHIUM_APP_PATH . '/tests/mocks/md/file_1.md.copy'; + * $this->assertFileNotEquals($file1, $file2); + * }}} + * + * @param string $expected Path to the expected file + * @param string $actual Path to the actual file + * @param string $message optional + * @return bool + */ + public function assertFileNotEquals($expected, $actual, $message = '{:message}') { + $expected = md5_file($expected); + $result = md5_file($actual); + return $this->assert($expected !== $result, $message, compact('expected', 'result')); + } + + /** + * Will mark the test `true` if the file `$actual` exists. + * + * {{{ + * $this->assertFileExists(LITHIUM_APP_PATH . '/readme.md'); + * }}} + * + * {{{ + * $this->assertFileExists(LITHIUM_APP_PATH . '/does/not/exist.txt'); + * }}} + * + * @param string $actual Path to the file you are asserting + * @param string $message optional + * @return bool + */ + public function assertFileExists($actual, $message = '{:message}') { + return $this->assert(file_exists($actual), $message, array( + 'expected' => $actual, + 'result' => file_exists($actual) + )); + } + + /** + * Will mark the test `true` if the file `$actual` does not exist. + * + * {{{ + * $this->assertFileExists(LITHIUM_APP_PATH . '/does/not/exist.txt'); + * }}} + * + * {{{ + * $this->assertFileExists(LITHIUM_APP_PATH . '/readme.md'); + * }}} + * + * @param string $actual Path to the file you are asserting + * @param string $message optional + * @return bool + */ + public function assertFileNotExists($actual, $message = '{:message}') { + return $this->assert(!file_exists($actual), $message, array( + 'expected' => $actual, + 'result' => !file_exists($actual) + )); + } + + /** + * Will mark the test `true` if `$expected` greater than `$actual`. + * + * {{{ + * $this->assertGreaterThan(5, 3); + * }}} + * + * {{{ + * $this->assertGreaterThan(3, 5); + * }}} + * + * @param float|int $expected + * @param float|int $actual + * @param string $message optional + * @return bool + */ + public function assertGreaterThan($expected, $actual, $message = '{:message}') { + return $this->assert($expected > $actual, $message, array( + 'expected' => $expected, + 'result' => $actual + )); + } + + /** + * Will mark the test `true` if `$expected` great than or equal to `$actual`. + * + * {{{ + * $this->assertGreaterThanOrEqual(5, 5); + * }}} + * + * {{{ + * $this->assertGreaterThanOrEqual(3, 5); + * }}} + * + * @param float|int $expected + * @param float|int $actual + * @param string $message optional + * @return bool + */ + public function assertGreaterThanOrEqual($expected, $actual, $message = '{:message}') { + return $this->assert($expected >= $actual, $message, array( + 'expected' => $expected, + 'result' => $actual + )); + } + + /** + * Will mark the test `true` if `$expected` less than `$actual`. + * + * {{{ + * $this->assertLessThan(3, 5); + * }}} + * + * {{{ + * $this->assertLessThan(5, 3); + * }}} + * + * @param float|int $expected + * @param float|int $actual + * @param string $message optional + * @return bool + */ + public function assertLessThan($expected, $actual, $message = '{:message}') { + return $this->assert($expected < $actual, $message, array( + 'expected' => $expected, + 'result' => $actual + )); + } + + /** + * Will mark the test `true` if `$expected` is less than or equal to `$actual`. + * + * {{{ + * $this->assertLessThanOrEqual(5, 5); + * }}} + * + * {{{ + * $this->assertLessThanOrEqual(5, 3); + * }}} + * + * @param float|int $expected + * @param float|int $actual + * @param string $message optional + * @return bool + */ + public function assertLessThanOrEqual($expected, $actual, $message = '{:message}') { + return $this->assert($expected <= $actual, $message, array( + 'expected' => $expected, + 'result' => $actual + )); + } + + /** + * Will mark the test `true` if `$actual` is a `$expected`. + * + * {{{ + * $this->assertInstanceOf('stdClass', new stdClass); + * }}} + * + * {{{ + * $this->assertInstanceOf('ReflectionClass', new stdClass); + * }}} + * + * @param string $expected Fully namespaced expected class + * @param object $actual Object you are testing + * @param string $message optional + * @return bool + */ + public function assertInstanceOf($expected, $actual, $message = '{:message}') { + return $this->assert(is_a($actual, $expected), $message, array( + 'expected' => $expected, + 'result' => get_class($actual) + )); + } + + /** + * Will mark the test `true` if `$actual` is not a `$expected`. + * + * {{{ + * $this->assertNotInstanceOf('ReflectionClass', new stdClass); + * }}} + * + * {{{ + * $this->assertNotInstanceOf('stdClass', new stdClass); + * }}} + * + * @param string $expected Fully namespaced expected class + * @param object $actual Object you are testing + * @param string $message optional + * @return bool + */ + public function assertNotInstanceOf($expected, $actual, $message = '{:message}') { + return $this->assert(!is_a($actual, $expected), $message, array( + 'expected' => $expected, + 'result' => get_class($actual) + )); + } + + /** + * Will mark the test `true` if `$actual` if of type $expected. + * + * {{{ + * $this->assertInternalType('string', 'foobar'); + * }}} + * + * {{{ + * $this->assertInternalType('int', 'foobar'); + * }}} + * + * @param string $expected Internal data type + * @param object $actual Object you are testing + * @param string $message optional + * @return bool + */ + public function assertInternalType($expected, $actual, $message = '{:message}') { + $method = self::$_internalTypes[$expected]; + return $this->assert($method($actual), $message, array( + 'expected' => $expected, + 'result' => gettype($actual) + )); + } + + /** + * Will mark the test `true` if `$actual` if not of type $expected. + * + * {{{ + * $this->assertNotInternalType('int', 'foobar'); + * }}} + * + * {{{ + * $this->assertNotInternalType('string', 'foobar'); + * }}} + * + * @param string $expected Internal data type + * @param object $actual Object you are testing + * @param string $message optional + * @return bool + */ + public function assertNotInternalType($expected, $actual, $message = '{:message}') { + $method = self::$_internalTypes[$expected]; + return $this->assert(!$method($actual), $message, array( + 'expected' => $expected, + 'result' => gettype($actual) + )); + } + + /** + * Will mark the test as true if `$actual` is not null. + * + * {{{ + * $this->assertNotNull(1); + * }}} + * + * {{{ + * $this->assertNotNull(null); + * }}} + * + * @param object $actual Variable you are testing + * @param string $message optional + * @return bool + */ + public function assertNotNull($actual, $message = '{:message}') { + return $this->assert(!is_null($actual), $message, array( + 'expected' => null, + 'actual' => gettype($actual) + )); + } + + /** + * Will mark the test `true` if `$object` has an attribute `$attributeName`. + * + * {{{ + * $this->assertObjectHasAttribute('name', '\ReflectionClass'); + * }}} + * + * {{{ + * $this->assertObjectHasAttribute('__construct', '\ReflectionClass'); + * }}} + * + * @see lithium\test\Unit::assertClassHasAttribute() + * @throws InvalidArgumentException When $object is not an object + * @param string $attributeName Attribute you wish to look for + * @param string $object Object to assert + * @param string $message optional + * @return bool + */ + public function assertObjectHasAttribute($attributeName, $object, $message = '{:message}') { + if(!is_object($object)) { + throw new InvalidArgumentException('Second argument $object must be an object.'); + } + $object = new ReflectionClass($object); + return $this->assert($object->hasProperty($attributeName), $message, array( + 'expected' => $attributeName, + 'result' => $object->getProperties() + )); + } + + /** + * Will mark the test `true` if `$object` has an attribute `$attributeName`. + * + * {{{ + * $this->assertObjectNotHasAttribute('__construct', '\ReflectionClass'); + * }}} + * + * {{{ + * $this->assertObjectNotHasAttribute('name', '\ReflectionClass'); + * }}} + * + * @see lithium\test\Unit::assertClassHasNotAttribute() + * @throws InvalidArgumentException When $object is not an object + * @param string $attributeName Attribute you wish to look for + * @param string $object Object to assert + * @param string $message optional + * @return bool + */ + public function assertObjectNotHasAttribute($attributeName, $object, $message = '{:message}') { + if(!is_object($object)) { + throw new InvalidArgumentException('Second argument $object must be an object'); + } + $object = new ReflectionClass($object); + return $this->assert(!$object->hasProperty($attributeName), $message, array( + 'expected' => $attributeName, + 'result' => $object->getProperties() + )); + } + + /** + * Will mark the test `true` if `$actual` matches $expected using `preg_match`. + * + * {{{ + * $this->assertRegExp('/^foo/', 'foobar'); + * }}} + * + * {{{ + * $this->assertRegExp('/^foobar/', 'bar'); + * }}} + * + * @param string $expected Regex to match against $actual + * @param string $actual String to be matched upon + * @param string $message optional + * @return bool + */ + public function assertRegExp($expected, $actual, $message = '{:message}') { + return $this->assert(preg_match($expected, $actual, $matches) === 1, $message, array( + 'expected' => $expected, + 'result' => $matches + )); + } + + /** + * Will mark the test `true` if `$actual` does not match $expected using `preg_match`. + * + * {{{ + * $this->assertNotRegExp('/^foobar/', 'bar'); + * }}} + * + * {{{ + * $this->assertNotRegExp('/^foo/', 'foobar'); + * }}} + * + * @param string $expected Regex to match against $actual + * @param string $actual String to be matched upon + * @param string $message optional + * @return bool + */ + public function assertNotRegExp($expected, $actual, $message = '{:message}') { + return $this->assert(preg_match($expected, $actual, $matches) === 0, $message, array( + 'expected' => $expected, + 'result' => $matches + )); + } + + /** + * Will mark the test `true` if $actual matches $expected using `sprintf` format. + * + * {{{ + * $this->assertStringMatchesFormat('%d', '10') + * }}} + * + * {{{ + * $this->assertStringMatchesFormat('%d', '10.555') + * }}} + * + * @link http://php.net/sprintf + * @link http://php.net/sscanf + * @param string $expected Expected format using sscanf's format + * @param string $actual Value to compare against + * @param string $message optional + * @return bool + */ + public function assertStringMatchesFormat($expected, $actual, $message = '{:message}') { + $result = sscanf($actual, $expected); + return $this->assert($result[0] == $actual, $message, compact('expected', 'result')); + } + + /** + * Will mark the test `true` if $actual doesn't match $expected using `sprintf` format. + * + * {{{ + * $this->assertStringNotMatchesFormat('%d', '10.555') + * }}} + * + * {{{ + * $this->assertStringNotMatchesFormat('%d', '10') + * }}} + * + * @link http://php.net/sprintf + * @link http://php.net/sscanf + * @param string $expected Expected format using sscanf's format + * @param string $actual Value to test against + * @param string $message optional + * @return bool + */ + public function assertStringNotMatchesFormat($expected, $actual, $message = '{:message}') { + $result = sscanf($actual, $expected); + return $this->assert($result[0] != $actual, $message, compact('expected', 'result')); + } + + /** + * Will mark the test `true` if $actual ends with `$expected`. + * + * {{{ + * $this->assertStringEndsWith('bar', 'foobar'); + * }}} + * + * {{{ + * $this->assertStringEndsWith('foo', 'foobar'); + * }}} + * + * @param string $expected The suffix to check for + * @param string $actual Value to test against + * @param string $message optional + * @return bool + */ + public function assertStringEndsWith($expected, $actual, $message = '{:message}') { + return $this->assert(preg_match("/$expected$/", $actual, $matches) === 1, $message, array( + 'expected' => $expected, + 'result' => $actual + )); + } + + /** + * Will mark the test `true` if $actual starts with `$expected`. + * + * {{{ + * $this->assertStringStartsWith('foo', 'foobar'); + * }}} + * + * {{{ + * $this->assertStringStartsWith('bar', 'foobar'); + * }}} + * + * @param string $expected Prefix to check for + * @param string $actual Value to test against + * @param string $message optional + * @return bool + */ + public function assertStringStartsWith($expected, $actual, $message = '{:message}') { + return $this->assert(preg_match("/^$expected/", $actual, $matches) === 1, $message, array( + 'expected' => $expected, + 'result' => $actual + )); + } + } ?> \ No newline at end of file diff --git a/tests/cases/test/UnitTest.php b/tests/cases/test/UnitTest.php index 70eb949970..b3f8da968a 100644 --- a/tests/cases/test/UnitTest.php +++ b/tests/cases/test/UnitTest.php @@ -670,6 +670,940 @@ public function testTestMethods() { $result = $this->test->methods(); $this->assertIdentical($expected, $result); } + + public function testAssertCountTrue() { + $this->assertTrue($this->test->assertCount(1, array('foo'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertCountFalse() { + $this->assertFalse($this->test->assertCount(2, array('foo', 'bar', 'bar'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertIdentical(array( + 'expected' => 2, + 'result' => 3 + ), $result['data']); + } + + public function testAssertNotCountTrue() { + $this->assertTrue($this->test->assertNotCount(2, array('foo', 'bar', 'bar'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotCountFalse() { + $this->assertFalse($this->test->assertNotCount(1, array('foo'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertIdentical(array( + 'expected' => 1, + 'result' => 1 + ), $result['data']); + } + + public function testArrayHasKeyTrue() { + $this->assertTrue($this->test->assertArrayHasKey('bar', array('bar' => 'baz'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testArrayHasKeyFalse() { + $this->assertFalse($this->test->assertArrayHasKey('foo', array('bar' => 'baz'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertIdentical(array( + 'expected' => 'foo', + 'result' => array('bar' => 'baz') + ), $result['data']); + } + + public function testArrayNotHasKeyTrue() { + $this->assertTrue($this->test->assertArrayNotHasKey('foo', array('bar' => 'baz'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testArrayNotHasKeyFalse() { + $this->assertFalse($this->test->assertArrayNotHasKey('bar', array('bar' => 'baz'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertIdentical(array( + 'expected' => 'bar', + 'result' => array('bar' => 'baz') + ), $result['data']); + } + + public function testClassHasAttributeTrue() { + $this->assertTrue($this->test->assertClassHasAttribute('name', '\ReflectionClass')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testClassHasAttributeFalse() { + $this->assertFalse($this->test->assertClassHasAttribute('foo', '\ReflectionClass')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'foo', + 'result' => array( + new \ReflectionProperty('ReflectionClass', 'name') + ) + ), $result['data']); + } + + public function testClassHasAttributeWrongClassType() { + $self =& $this; + $this->assertException('InvalidArgumentException', function() use($self) { + $self->test->assertClassHasAttribute('foo', new \stdClass); + }); + } + + public function testClassHasAttributeClassNotFound() { + $self =& $this; + $this->assertException('ReflectionException', function() use($self) { + $self->test->assertClassHasAttribute('foo', '\foo\bar\baz'); + }); + } + + public function testClassNotHasAttributeTrue() { + $this->assertTrue($this->test->assertClassNotHasAttribute('foo', '\ReflectionClass')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testClassNotHasAttributeFalse() { + $this->assertFalse($this->test->assertClassNotHasAttribute('name', '\ReflectionClass')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'name', + 'result' => array( + new \ReflectionProperty('ReflectionClass', 'name') + ) + ), $result['data']); + } + + public function testClassNotHasAttributeClassNotFound() { + $self =& $this; + $this->assertException('ReflectionException', function() use($self) { + $self->test->assertClassNotHasAttribute('foo', '\foo\bar\baz'); + }); + } + + public function testClassNotHasAttributeWrongClassType() { + $self =& $this; + $this->assertException('InvalidArgumentException', function() use($self) { + $self->test->assertClassNotHasAttribute('foo', new \stdClass); + }); + } + + public function testClassHasStaticAttributeTrue() { + $class = '\lithium\core\StaticObject'; + $this->assertTrue($this->test->assertClassHasStaticAttribute('_methodFilters', $class)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testClassHasStaticAttributeFalse() { + $class = '\lithium\core\StaticObject'; + $this->assertFalse($this->test->assertClassHasStaticAttribute('foobar', $class)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'foobar', + 'result' => array( + new \ReflectionProperty('lithium\\core\\StaticObject', '_methodFilters'), + new \ReflectionProperty('lithium\\core\\StaticObject', '_parents') + ) + ), $result['data']); + } + + public function testClassHasStaticAttributeClassNotFound() { + $self =& $this; + $this->assertException('ReflectionException', function() use($self) { + $self->test->assertClassHasStaticAttribute('foo', '\foo\bar\baz'); + }); + } + + public function testClassNotHasStaticAttributeTrue() { + $class = '\lithium\core\StaticObject'; + $this->assertTrue($this->test->assertClassNotHasStaticAttribute('foobar', $class)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testClassNotHasStaticAttributeFalse() { + $class = '\lithium\core\StaticObject'; + $this->assertFalse($this->test->assertClassNotHasStaticAttribute('_methodFilters', $class)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => '_methodFilters', + 'result' => array( + new \ReflectionProperty('lithium\\core\\StaticObject', '_methodFilters'), + new \ReflectionProperty('lithium\\core\\StaticObject', '_parents') + ) + ), $result['data']); + } + + public function testClassNotHasStaticAttributeClassNotFound() { + $self =& $this; + $this->assertException('ReflectionException', function() use($self) { + $self->test->assertClassNotHasStaticAttribute('foo', '\foo\bar\baz'); + }); + } + + public function testAssertContainsStringInStrTrue() { + $this->assertTrue($this->test->assertContains('foo', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertContainsStringInStrFalse() { + $this->assertFalse($this->test->assertContains('baz', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'baz', + 'result' => 'foobar' + ), $result['data']); + } + + public function testAssertContainsTrue() { + $this->assertTrue($this->test->assertContains('bar', array('foo', 'bar', 'baz'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertContainsFalse() { + $this->assertFalse($this->test->assertContains('foobar', array('foo', 'bar', 'baz'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'foobar', + 'result' => array( + 'foo', 'bar', 'baz' + ) + ), $result['data']); + } + + public function testAssertNotContainsStringInStrTrue() { + $this->assertTrue($this->test->assertNotContains('baz', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotContainsStringInStrFalse() { + $this->assertFalse($this->test->assertNotContains('foo', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'foo', + 'result' => 'foobar' + ), $result['data']); + } + + public function testAssertNotContainsTrue() { + $this->assertTrue($this->test->assertNotContains('foobar', array('foo', 'bar', 'baz'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotContainsFalse() { + $this->assertFalse($this->test->assertNotContains('bar', array('foo', 'bar', 'baz'))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'bar', + 'result' => array( + 'foo', 'bar', 'baz' + ) + ), $result['data']); + } + + public function testAssertContainsOnlyTrue() { + $this->assertTrue($this->test->assertContainsOnly('int', array(1,2,3))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertContainsOnlyFalse() { + $this->assertFalse($this->test->assertContainsOnly('string', array(1,2,3))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'string', + 'result' => array( + 1,2,3 + ) + ), $result['data']); + } + + public function testAssertNotContainsOnlyTrue() { + $this->assertTrue($this->test->assertNotContainsOnly('string', array(1,2,3))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotContainsOnlyFalse() { + $this->assertFalse($this->test->assertNotContainsOnly('int', array(1,2,3))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'int', + 'result' => array( + 1,2,3 + ) + ), $result['data']); + } + + public function testAssertContainsOnlyInstanceOfTrue() { + $obj = new \stdClass; + $this->assertTrue($this->test->assertContainsOnlyInstancesOf('stdClass', array($obj))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertContainsOnlyInstanceOfFalse() { + $obj = new \lithium\test\Unit; + $this->assertFalse($this->test->assertContainsOnlyInstancesOf('stdClass', array($obj))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'stdClass', + 'result' => array( + 0 => new \lithium\test\Unit + ) + ), $result['data']); + } + + public function testAssertEmptyTrue() { + $this->assertTrue($this->test->assertEmpty(array())); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertEmptyFalse() { + $this->assertFalse($this->test->assertEmpty(array(1))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => array(1), + 'result' => false + ), $result['data']); + } + + public function testAssertNotEmptyTrue() { + $this->assertTrue($this->test->assertNotEmpty(array(1))); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotEmptyFalse() { + $this->assertFalse($this->test->assertNotEmpty(array())); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => array(), + 'result' => false + ), $result['data']); + } + + public function testAssertFileEqualsTrue() { + $file1 = __DIR__ . '/UnitTest.php'; + $file2 = __DIR__ . '/UnitTest.php'; + $this->assertTrue($this->test->assertFileEquals($file1, $file2)); + } + + public function testAssertFileEqualsFalse() { + $file1 = __DIR__ . '/UnitTest.php'; + $file2 = __DIR__ . '/ReportTest.php'; + $this->assertFalse($this->test->assertFileEquals($file1, $file2)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => md5_file($file1), + 'result' => md5_file($file2) + ), $result['data']); + } + + public function testAssertFileNotEqualsTrue() { + $file1 = __DIR__ . '/UnitTest.php'; + $file2 = __DIR__ . '/ReportTest.php'; + $this->assertTrue($this->test->assertFileNotEquals($file1, $file2)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertFileNotEqualsFalse() { + $file1 = __DIR__ . '/UnitTest.php'; + $file2 = __DIR__ . '/UnitTest.php'; + $this->assertFalse($this->test->assertFileNotEquals($file1, $file2)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => md5_file($file1), + 'result' => md5_file($file2) + ), $result['data']); + } + + public function testAssertFileExistsTrue() { + $file1 = __FILE__; + $this->assertTrue($this->test->assertFileExists($file1)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertFileExistsFalse() { + $file1 = __DIR__ . '/does/not/exist.txt'; + $this->assertFalse($this->test->assertFileExists($file1)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => __DIR__ . '/does/not/exist.txt', + 'result' => false + ), $result['data']); + } + + public function testAssertFileNotExistsTrue() { + $file1 = __DIR__ . '/does/not/exist.txt'; + $this->assertTrue($this->test->assertFileNotExists($file1)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertFileNotExistsFalse() { + $file1 = __FILE__; + $this->assertFalse($this->test->assertFileNotExists($file1)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => __FILE__, + 'result' => false + ), $result['data']); + } + + public function testAssertGreaterThanTrue() { + $this->assertTrue($this->test->assertGreaterThan(5, 3)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertGreaterThanFalse() { + $this->assertFalse($this->test->assertGreaterThan(3, 5)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 3, + 'result' => 5 + ), $result['data']); + } + + public function testAssertGreaterThanOrEqualTrue() { + $this->assertTrue($this->test->assertGreaterThanOrEqual(5, 5)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertGreaterThanOrEqualFalse() { + $this->assertFalse($this->test->assertGreaterThanOrEqual(3, 5)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 3, + 'result' => 5 + ), $result['data']); + } + + public function testAssertLessThanTrue() { + $this->assertTrue($this->test->assertLessThan(3, 5)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertLessThanFalse() { + $this->assertFalse($this->test->assertLessThan(5, 3)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 5, + 'result' => 3 + ), $result['data']); + } + + public function testAssertLessThanOrEqualTrue() { + $this->assertTrue($this->test->assertLessThanOrEqual(5, 5)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertLessThanOrEqualFalse() { + $this->assertFalse($this->test->assertLessThanOrEqual(5, 3)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 5, + 'result' => 3 + ), $result['data']); + } + + public function testAssertInstanceOfTrue() { + $this->assertTrue($this->test->assertInstanceOf('\stdClass', new \stdClass)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertInstanceOfFalse() { + $this->assertFalse($this->test->assertInstanceOf('\ReflectionClass', new \stdClass)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => '\ReflectionClass', + 'result' => 'stdClass' + ), $result['data']); + } + + public function testAssertNotInstanceOfTrue() { + $this->assertTrue($this->test->assertNotInstanceOf('\ReflectionClass', new \stdClass)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotInstanceOfFalse() { + $this->assertFalse($this->test->assertNotInstanceOf('\stdClass', new \stdClass)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => '\stdClass', + 'result' => 'stdClass' + ), $result['data']); + } + + public function testAssertInternalTypeTrue() { + $this->assertTrue($this->test->assertInternalType('string', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertInternalTypeFalse() { + $this->assertFalse($this->test->assertInternalType('int', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'int', + 'result' => 'string' + ), $result['data']); + } + + public function testAssertNotInternalTypeTrue() { + $this->assertTrue($this->test->assertNotInternalType('int', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotInternalTypeFalse() { + $this->assertFalse($this->test->assertNotInternalType('string', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'string', + 'result' => 'string' + ), $result['data']); + } + + public function testAssertNotNullTrue() { + $this->assertTrue($this->test->assertNotNull(1)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotNullFalse() { + $this->assertFalse($this->test->assertNotNull(null)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => NULL, + 'actual' => 'NULL', + ), $result['data']); + } + + public function testObjectHasAttributeTrue() { + $obj = new \ReflectionClass(new \stdClass); + $this->assertTrue($this->test->assertObjectHasAttribute('name', $obj)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testObjectHasAttributeFalse() { + $obj = new \ReflectionClass(new \stdClass); + $this->assertFalse($this->test->assertObjectHasAttribute('foo', $obj)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'foo', + 'result' => array( + new \ReflectionProperty('ReflectionClass', 'name') + ) + ), $result['data']); + } + + public function testObjectHasAttributeWrongClassType() { + $self =& $this; + $this->assertException('InvalidArgumentException', function() use($self) { + $self->test->assertObjectHasAttribute('foo', '\stdClass'); + }); + } + + public function testObjectNotHasAttributeTrue() { + $obj = new \ReflectionClass(new \stdClass); + $this->assertTrue($this->test->assertObjectNotHasAttribute('foo', $obj)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testObjectNotHasAttributeFalse() { + $obj = new \ReflectionClass(new \stdClass); + $this->assertFalse($this->test->assertObjectNotHasAttribute('name', $obj)); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'name', + 'result' => array( + new \ReflectionProperty('ReflectionClass', 'name') + ) + ), $result['data']); + } + + public function testObjectNotHasAttributeWrongClassType() { + $self =& $this; + $this->assertException('InvalidArgumentException', function() use($self) { + $self->test->assertObjectNotHasAttribute('foo', 'new \stdClass'); + }); + } + + public function testAssertRegExpTrue() { + $this->assertTrue($this->test->assertRegExp('/^foo/', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertRegExpFalse() { + $this->assertFalse($this->test->assertRegExp('/^bar/', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => '/^bar/', + 'result' => array() + ), $result['data']); + } + + public function testAssertNotRegExpTrue() { + $this->assertTrue($this->test->assertNotRegExp('/^bar/', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertNotRegExpFalse() { + $this->assertFalse($this->test->assertNotRegExp('/^foo/', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => '/^foo/', + 'result' => array('foo') + ), $result['data']); + } + + public function testAssertStringMatchesFormatTrue() { + $this->assertTrue($this->test->assertStringMatchesFormat('%d', '10')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertStringMatchesFormatFalse() { + $this->assertFalse($this->test->assertStringMatchesFormat('%d', '10.555')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => '%d', + 'result' => array('10') + ), $result['data']); + } + + public function testAssertStringNotMatchesFormatTrue() { + $this->assertTrue($this->test->assertStringNotMatchesFormat('%d', '10.555')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertStringNotMatchesFormatFalse() { + $this->assertFalse($this->test->assertStringNotMatchesFormat('%d', '10')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => '%d', + 'result' => array('10') + ), $result['data']); + } + + public function testAssertStringEndsWithTrue() { + $this->assertTrue($this->test->assertStringEndsWith('bar', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertStringEndsWithFalse() { + $this->assertFalse($this->test->assertStringEndsWith('foo', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'foo', + 'result' => 'foobar' + ), $result['data']); + } + + public function testAssertStringStartsWithTrue() { + $this->assertTrue($this->test->assertStringStartsWith('foo', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('pass', $result['result']); + } + + public function testAssertStringStartsWithFalse() { + $this->assertFalse($this->test->assertStringStartsWith('bar', 'foobar')); + + $results = $this->test->results(); + $result = array_pop($results); + + $this->assertEqual('fail', $result['result']); + $this->assertEqual(array( + 'expected' => 'bar', + 'result' => 'foobar' + ), $result['data']); + } + } ?> \ No newline at end of file