2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-21 23:55:39 +00:00
|
|
|
* CakeTestCase file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4667
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-08 20:18:45 +00:00
|
|
|
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-07 22:37:02 +00:00
|
|
|
require_once CAKE_TESTS_LIB . 'cake_fixture_manager.php';
|
2008-05-30 11:40:08 +00:00
|
|
|
require_once CAKE_TESTS_LIB . 'cake_test_model.php';
|
|
|
|
require_once CAKE_TESTS_LIB . 'cake_test_fixture.php';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-21 23:55:39 +00:00
|
|
|
* CakeTestCase class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.lib
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-05-04 18:17:08 +00:00
|
|
|
class CakeTestCase extends PHPUnit_Framework_TestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Methods used internally.
|
|
|
|
*
|
|
|
|
* @var array
|
2009-03-21 23:55:39 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $methods = array('start', 'end', 'startcase', 'endcase', 'starttest', 'endtest');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* By default, all fixtures attached to this class will be truncated and reloaded after each test.
|
|
|
|
* Set this to false to handle manually
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $autoFixtures = true;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-09 21:49:49 +00:00
|
|
|
/**
|
2008-09-09 22:18:49 +00:00
|
|
|
* Set this to false to avoid tables to be dropped if they already exist
|
2008-09-09 21:49:49 +00:00
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $dropTables = true;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-21 23:55:39 +00:00
|
|
|
/**
|
|
|
|
* savedGetData property
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-21 23:55:39 +00:00
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
2010-04-04 06:33:39 +00:00
|
|
|
private $__savedGetData = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-01 03:37:21 +00:00
|
|
|
/**
|
|
|
|
* Runs the test case and collects the results in a TestResult object.
|
|
|
|
* If no TestResult object is passed a new one will be created.
|
|
|
|
* This method is run for each test method in this class
|
|
|
|
*
|
|
|
|
* @param PHPUnit_Framework_TestResult $result
|
|
|
|
* @return PHPUnit_Framework_TestResult
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function run(PHPUnit_Framework_TestResult $result = NULL) {
|
|
|
|
if (!empty($this->sharedFixture)) {
|
|
|
|
$this->sharedFixture->load($this);
|
|
|
|
}
|
|
|
|
$result = parent::run($result);
|
|
|
|
if (!empty($this->sharedFixture)) {
|
|
|
|
$this->sharedFixture->unload($this);
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2009-03-21 23:55:39 +00:00
|
|
|
/**
|
|
|
|
* Called when a test case (group of methods) is about to start (to be overriden when needed.)
|
|
|
|
*
|
|
|
|
* @param string $method Test method about to get executed.
|
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function startCase() {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Called when a test case (group of methods) has been executed (to be overriden when needed.)
|
|
|
|
*
|
2009-03-21 23:55:39 +00:00
|
|
|
* @param string $method Test method about that was executed.
|
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function endCase() {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Called when a test case method is about to start (to be overriden when needed.)
|
|
|
|
*
|
2009-03-21 23:55:39 +00:00
|
|
|
* @param string $method Test method about to get executed.
|
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function startTest($method) {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Called when a test case method has been executed (to be overriden when needed.)
|
|
|
|
*
|
2009-03-21 23:55:39 +00:00
|
|
|
* @param string $method Test method about that was executed.
|
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function endTest($method) {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Overrides SimpleTestCase::skipIf to provide a boolean return value
|
2009-03-21 23:55:39 +00:00
|
|
|
*
|
|
|
|
* @param boolean $shouldSkip
|
|
|
|
* @param string $message
|
|
|
|
* @return boolean
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-05-04 18:17:08 +00:00
|
|
|
public function skipIf($shouldSkip, $message = '') {
|
|
|
|
if ($shouldSkip) {
|
|
|
|
$this->markTestSkipped($message);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return $shouldSkip;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Announces the start of a test.
|
|
|
|
*
|
|
|
|
* @param string $method Test method just started.
|
2009-03-21 23:55:39 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-05-07 22:37:02 +00:00
|
|
|
protected function assertPreConditions() {
|
|
|
|
parent::assertPreConditions();
|
|
|
|
if (!in_array(strtolower($this->getName()), $this->methods)) {
|
|
|
|
$this->startTest($this->getName());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Announces the end of a test.
|
|
|
|
*
|
|
|
|
* @param string $method Test method just finished.
|
2009-03-21 23:55:39 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-05-07 22:37:02 +00:00
|
|
|
protected function assertPostConditions() {
|
|
|
|
parent::assertPostConditions();
|
|
|
|
if (!in_array(strtolower($this->getName()), $this->methods)) {
|
|
|
|
$this->endTest($this->getName());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets a list of test names. Normally that will be all internal methods that start with the
|
|
|
|
* name "test". This method should be overridden if you want a different rule.
|
|
|
|
*
|
2009-03-21 23:55:39 +00:00
|
|
|
* @return array List of test names.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function getTests() {
|
2009-02-13 06:22:34 +00:00
|
|
|
return array_merge(
|
|
|
|
array('start', 'startCase'),
|
2010-04-15 03:36:47 +00:00
|
|
|
array_diff(parent::getTests(), array('testAction')),
|
2009-02-13 06:22:34 +00:00
|
|
|
array('endCase', 'end')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Chooses which fixtures to load for a given test
|
|
|
|
*
|
2009-02-13 06:22:34 +00:00
|
|
|
* @param string $fixture Each parameter is a model name that corresponds to a
|
|
|
|
* fixture, i.e. 'Post', 'Author', etc.
|
2009-03-21 23:55:39 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access public
|
|
|
|
* @see CakeTestCase::$autoFixtures
|
|
|
|
*/
|
|
|
|
function loadFixtures() {
|
2010-05-08 20:25:16 +00:00
|
|
|
if (empty($this->sharedFixture)) {
|
|
|
|
throw new Exception(__('No fixture manager to load the test fixture'));
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
foreach ($args as $class) {
|
2010-05-21 02:49:50 +00:00
|
|
|
$this->sharedFixture->loadSingle($class);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-02-13 06:22:34 +00:00
|
|
|
* Takes an array $expected and generates a regex from it to match the provided $string.
|
|
|
|
* Samples for $expected:
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-02-13 06:22:34 +00:00
|
|
|
* Checks for an input tag with a name attribute (contains any non-empty value) and an id
|
|
|
|
* attribute that contains 'my-input':
|
2008-05-30 11:40:08 +00:00
|
|
|
* array('input' => array('name', 'id' => 'my-input'))
|
|
|
|
*
|
|
|
|
* Checks for two p elements with some text in them:
|
|
|
|
* array(
|
|
|
|
* array('p' => true),
|
|
|
|
* 'textA',
|
|
|
|
* '/p',
|
|
|
|
* array('p' => true),
|
|
|
|
* 'textB',
|
|
|
|
* '/p'
|
|
|
|
* )
|
|
|
|
*
|
2009-02-13 06:22:34 +00:00
|
|
|
* You can also specify a pattern expression as part of the attribute values, or the tag
|
|
|
|
* being defined, if you prepend the value with preg: and enclose it with slashes, like so:
|
2008-05-30 11:40:08 +00:00
|
|
|
* array(
|
|
|
|
* array('input' => array('name', 'id' => 'preg:/FieldName\d+/')),
|
|
|
|
* 'preg:/My\s+field/'
|
|
|
|
* )
|
|
|
|
*
|
2009-02-13 06:22:34 +00:00
|
|
|
* Important: This function is very forgiving about whitespace and also accepts any
|
|
|
|
* permutation of attribute order. It will also allow whitespaces between specified tags.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $string An HTML/XHTML/XML string
|
|
|
|
* @param array $expected An array, see above
|
|
|
|
* @param string $message SimpleTest failure output string
|
2009-03-21 23:55:39 +00:00
|
|
|
* @return boolean
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function assertTags($string, $expected, $fullDebug = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$regex = array();
|
|
|
|
$normalized = array();
|
|
|
|
foreach ((array) $expected as $key => $val) {
|
|
|
|
if (!is_numeric($key)) {
|
|
|
|
$normalized[] = array($key => $val);
|
|
|
|
} else {
|
|
|
|
$normalized[] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$i = 0;
|
|
|
|
foreach ($normalized as $tags) {
|
2009-10-28 18:14:50 +00:00
|
|
|
if (!is_array($tags)) {
|
|
|
|
$tags = (string)$tags;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$i++;
|
|
|
|
if (is_string($tags) && $tags{0} == '<') {
|
|
|
|
$tags = array(substr($tags, 1) => array());
|
|
|
|
} elseif (is_string($tags)) {
|
2009-02-13 06:22:34 +00:00
|
|
|
$tagsTrimmed = preg_replace('/\s+/m', '', $tags);
|
|
|
|
|
|
|
|
if (preg_match('/^\*?\//', $tags, $match) && $tagsTrimmed !== '//') {
|
2008-05-30 11:40:08 +00:00
|
|
|
$prefix = array(null, null);
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($match[0] == '*/') {
|
|
|
|
$prefix = array('Anything, ', '.*?');
|
|
|
|
}
|
|
|
|
$regex[] = array(
|
|
|
|
sprintf('%sClose %s tag', $prefix[0], substr($tags, strlen($match[0]))),
|
|
|
|
sprintf('%s<[\s]*\/[\s]*%s[\s]*>[\n\r]*', $prefix[1], substr($tags, strlen($match[0]))),
|
|
|
|
$i,
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!empty($tags) && preg_match('/^preg\:\/(.+)\/$/i', $tags, $matches)) {
|
|
|
|
$tags = $matches[1];
|
|
|
|
$type = 'Regex matches';
|
|
|
|
} else {
|
|
|
|
$tags = preg_quote($tags, '/');
|
|
|
|
$type = 'Text equals';
|
|
|
|
}
|
|
|
|
$regex[] = array(
|
|
|
|
sprintf('%s "%s"', $type, $tags),
|
|
|
|
$tags,
|
|
|
|
$i,
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($tags as $tag => $attributes) {
|
|
|
|
$regex[] = array(
|
|
|
|
sprintf('Open %s tag', $tag),
|
|
|
|
sprintf('[\s]*<%s', preg_quote($tag, '/')),
|
|
|
|
$i,
|
|
|
|
);
|
|
|
|
if ($attributes === true) {
|
|
|
|
$attributes = array();
|
|
|
|
}
|
|
|
|
$attrs = array();
|
|
|
|
$explanations = array();
|
2010-04-05 01:43:29 +00:00
|
|
|
$i = 1;
|
2008-05-30 11:40:08 +00:00
|
|
|
foreach ($attributes as $attr => $val) {
|
|
|
|
if (is_numeric($attr) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
|
|
|
$attrs[] = $matches[1];
|
|
|
|
$explanations[] = sprintf('Regex "%s" matches', $matches[1]);
|
|
|
|
continue;
|
|
|
|
} else {
|
2010-04-05 01:43:29 +00:00
|
|
|
$quotes = '["\']';
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_numeric($attr)) {
|
|
|
|
$attr = $val;
|
|
|
|
$val = '.+?';
|
|
|
|
$explanations[] = sprintf('Attribute "%s" present', $attr);
|
2009-02-13 06:22:34 +00:00
|
|
|
} elseif (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
2010-04-05 01:43:29 +00:00
|
|
|
$quotes = '["\']?';
|
2008-05-30 11:40:08 +00:00
|
|
|
$val = $matches[1];
|
|
|
|
$explanations[] = sprintf('Attribute "%s" matches "%s"', $attr, $val);
|
|
|
|
} else {
|
|
|
|
$explanations[] = sprintf('Attribute "%s" == "%s"', $attr, $val);
|
|
|
|
$val = preg_quote($val, '/');
|
|
|
|
}
|
2010-04-05 01:43:29 +00:00
|
|
|
$attrs[] = '[\s]+' . preg_quote($attr, '/') . '=' . $quotes . $val . $quotes;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-04-05 01:43:29 +00:00
|
|
|
$i++;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if ($attrs) {
|
|
|
|
$permutations = $this->__array_permute($attrs);
|
2010-04-05 01:43:29 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$permutationTokens = array();
|
|
|
|
foreach ($permutations as $permutation) {
|
2009-11-19 22:13:35 +00:00
|
|
|
$permutationTokens[] = implode('', $permutation);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
$regex[] = array(
|
2009-11-19 22:13:35 +00:00
|
|
|
sprintf('%s', implode(', ', $explanations)),
|
2008-05-30 11:40:08 +00:00
|
|
|
$permutationTokens,
|
|
|
|
$i,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$regex[] = array(
|
|
|
|
sprintf('End %s tag', $tag),
|
|
|
|
'[\s]*\/?[\s]*>[\n\r]*',
|
|
|
|
$i,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($regex as $i => $assertation) {
|
|
|
|
list($description, $expressions, $itemNum) = $assertation;
|
|
|
|
$matches = false;
|
|
|
|
foreach ((array)$expressions as $expression) {
|
|
|
|
if (preg_match(sprintf('/^%s/s', $expression), $string, $match)) {
|
|
|
|
$matches = true;
|
|
|
|
$string = substr($string, strlen($match[0]));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$matches) {
|
2010-05-08 05:49:45 +00:00
|
|
|
$this->assertTrue(false, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description));
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($fullDebug) {
|
|
|
|
debug($string, true);
|
|
|
|
debug($regex, true);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-08 05:49:45 +00:00
|
|
|
$this->assertTrue(true, '%s');
|
|
|
|
return true;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-21 23:55:39 +00:00
|
|
|
/**
|
|
|
|
* Generates all permutation of an array $items and returns them in a new array.
|
|
|
|
*
|
|
|
|
* @param array $items An array of items
|
|
|
|
* @return array
|
|
|
|
* @access private
|
|
|
|
*/
|
2010-04-15 03:31:15 +00:00
|
|
|
private function __array_permute($items, $perms = array()) {
|
2009-03-21 23:55:39 +00:00
|
|
|
static $permuted;
|
|
|
|
if (empty($perms)) {
|
|
|
|
$permuted = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($items)) {
|
|
|
|
$permuted[] = $perms;
|
|
|
|
} else {
|
|
|
|
$numItems = count($items) - 1;
|
|
|
|
for ($i = $numItems; $i >= 0; --$i) {
|
|
|
|
$newItems = $items;
|
|
|
|
$newPerms = $perms;
|
|
|
|
list($tmp) = array_splice($newItems, $i, 1);
|
|
|
|
array_unshift($newPerms, $tmp);
|
|
|
|
$this->__array_permute($newItems, $newPerms);
|
|
|
|
}
|
|
|
|
return $permuted;
|
|
|
|
}
|
|
|
|
}
|
2010-05-04 18:17:08 +00:00
|
|
|
|
2010-05-08 21:59:33 +00:00
|
|
|
/**
|
|
|
|
* Compatibility wrapper function for assertEquals
|
|
|
|
* @param mixed $a
|
|
|
|
* @param mixed $b
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-08 15:42:04 +00:00
|
|
|
protected function assertEqual($a, $b, $message = '') {
|
|
|
|
return $this->assertEquals($a, $b, $message);
|
|
|
|
}
|
2010-05-08 21:59:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compatibility wrapper function for assertNotEquals
|
|
|
|
* @param mixed $a
|
|
|
|
* @param mixed $b
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-08 15:42:04 +00:00
|
|
|
protected function assertNotEqual($a, $b, $message = '') {
|
|
|
|
return $this->assertNotEquals($a, $b, $message);
|
2010-05-04 18:17:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-08 21:59:33 +00:00
|
|
|
/**
|
|
|
|
* Compatibility wrapper function for assertRegexp
|
|
|
|
* @param mixed $pattern a regular expression
|
|
|
|
* @param string $string the text to be matched
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-04 18:17:08 +00:00
|
|
|
protected function assertPattern($pattern, $string, $message = '') {
|
|
|
|
return $this->assertRegExp($pattern, $string, $message);
|
|
|
|
}
|
|
|
|
|
2010-05-08 21:59:33 +00:00
|
|
|
/**
|
2010-05-27 03:52:58 +00:00
|
|
|
* Compatibility wrapper function for assertEquals
|
2010-05-08 21:59:33 +00:00
|
|
|
* @param mixed $expected
|
|
|
|
* @param mixed $actual
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-04 18:17:08 +00:00
|
|
|
protected function assertIdentical($expected, $actual, $message = '') {
|
2010-05-27 03:52:58 +00:00
|
|
|
return $this->assertEquals($expected, $actual, $message);
|
2010-05-04 18:17:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-08 21:59:33 +00:00
|
|
|
/**
|
2010-06-05 03:57:05 +00:00
|
|
|
* Compatibility wrapper function for assertNotEquals
|
|
|
|
* @param mixed $expected
|
|
|
|
* @param mixed $actual
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function assertNotIdentical($expected, $actual, $message = '') {
|
|
|
|
return $this->assertNotEquals($expected, $actual, $message);
|
|
|
|
}
|
|
|
|
/**
|
2010-05-08 21:59:33 +00:00
|
|
|
* Compatibility wrapper function for assertNotRegExp
|
|
|
|
* @param mixed $pattern a regular expression
|
|
|
|
* @param string $string the text to be matched
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-04 18:17:08 +00:00
|
|
|
protected function assertNoPattern($pattern, $string, $message = '') {
|
|
|
|
return $this->assertNotRegExp($pattern, $string, $message);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function assertNoErrors() {
|
|
|
|
}
|
2010-05-08 21:59:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compatibility wrapper function for setExpectedException
|
|
|
|
* @param mixed $expected the name of the Exception or error
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-08 15:42:04 +00:00
|
|
|
protected function expectError($expected = false, $message = '') {
|
|
|
|
if (!$expected) {
|
|
|
|
$expected = 'Exception';
|
|
|
|
}
|
|
|
|
$this->setExpectedException($expected, $message);
|
|
|
|
}
|
2010-05-04 18:17:08 +00:00
|
|
|
|
2010-05-08 21:59:33 +00:00
|
|
|
/**
|
|
|
|
* Compatibility wrapper function for setExpectedException
|
|
|
|
* @param mixed $expected the name of the Exception
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-09 23:18:39 +00:00
|
|
|
protected function expectException($name = 'Exception', $message = '') {
|
2010-05-08 21:59:33 +00:00
|
|
|
$this->setExpectedException($name, $message);
|
2010-05-04 18:17:08 +00:00
|
|
|
}
|
2010-05-09 20:39:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compatibility wrapper function for assertSame
|
|
|
|
* @param mixed $expected
|
|
|
|
* @param mixed $actual
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-22 17:09:17 +00:00
|
|
|
protected function assertReference(&$first, &$second, $message = '') {
|
2010-05-09 20:39:57 +00:00
|
|
|
return $this->assertSame($first, $second, $message);
|
|
|
|
}
|
2010-05-09 22:46:42 +00:00
|
|
|
|
2010-05-22 17:09:17 +00:00
|
|
|
/**
|
|
|
|
* Compatibility wrapper for assertIsA
|
|
|
|
*
|
|
|
|
* @param string $object
|
|
|
|
* @param string $type
|
|
|
|
* @param string $message
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function assertIsA($object, $type, $message = '') {
|
|
|
|
return $this->assertType($type, $object, $message);
|
|
|
|
}
|
|
|
|
|
2010-05-09 22:46:42 +00:00
|
|
|
/**
|
|
|
|
* Compatibility function to test if value is between an acceptable range
|
|
|
|
* @param mixed $value
|
|
|
|
* @param mixed $expected
|
|
|
|
* @param mixed $margin the rage of acceptation
|
|
|
|
* @param string $message the text to display if the assertion is not correct
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function assertWithinMargin($value, $expected, $margin, $message = '') {
|
|
|
|
$upper = $value + $margin;
|
|
|
|
$lower = $value - $margin;
|
|
|
|
$this->assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|