mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-05 15:43:53 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* CakeTestCase file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.TestSuite
|
||||
* @since CakePHP(tm) v 1.2.0.4667
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeFixtureManager', 'TestSuite/Fixture');
|
||||
App::uses('CakeTestFixture', 'TestSuite/Fixture');
|
||||
|
||||
|
@ -42,9 +42,13 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
public $autoFixtures = true;
|
||||
|
||||
/**
|
||||
* Set this to false to avoid tables to be dropped if they already exist
|
||||
* Control table create/drops on each test method.
|
||||
*
|
||||
* @var boolean
|
||||
* Set this to false to avoid tables to be dropped if they already exist
|
||||
* between each test method. Tables will still be dropped at the
|
||||
* end of each test runner execution.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $dropTables = true;
|
||||
|
||||
|
@ -67,7 +71,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* 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
|
||||
* @param PHPUnit_Framework_TestResult $result The test result object
|
||||
* @return PHPUnit_Framework_TestResult
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
|
@ -103,9 +107,9 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* Overrides SimpleTestCase::skipIf to provide a boolean return value
|
||||
*
|
||||
* @param boolean $shouldSkip
|
||||
* @param string $message
|
||||
* @return boolean
|
||||
* @param bool $shouldSkip Whether or not the test should be skipped.
|
||||
* @param string $message The message to display.
|
||||
* @return bool
|
||||
*/
|
||||
public function skipIf($shouldSkip, $message = '') {
|
||||
if ($shouldSkip) {
|
||||
|
@ -170,7 +174,6 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* Announces the start of a test.
|
||||
*
|
||||
* @param string $method Test method just started.
|
||||
* @return void
|
||||
*/
|
||||
protected function assertPreConditions() {
|
||||
|
@ -181,7 +184,6 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* Announces the end of a test.
|
||||
*
|
||||
* @param string $method Test method just finished.
|
||||
* @return void
|
||||
*/
|
||||
protected function assertPostConditions() {
|
||||
|
@ -194,8 +196,8 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* Chooses which fixtures to load for a given test
|
||||
*
|
||||
* @param string $fixture Each parameter is a model name that corresponds to a
|
||||
* fixture, i.e. 'Post', 'Author', etc.
|
||||
* Each parameter is a model name that corresponds to a fixture, i.e. 'Post', 'Author', etc.
|
||||
*
|
||||
* @return void
|
||||
* @see CakeTestCase::$autoFixtures
|
||||
* @throws Exception when no fixture manager is available.
|
||||
|
@ -206,7 +208,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
$args = func_get_args();
|
||||
foreach ($args as $class) {
|
||||
$this->fixtureManager->loadSingle($class);
|
||||
$this->fixtureManager->loadSingle($class, null, $this->dropTables);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,8 +218,8 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
*
|
||||
* @param string $expected The expected value.
|
||||
* @param string $result The actual value.
|
||||
* @param message The message to use for failure.
|
||||
* @return boolean
|
||||
* @param string $message The message to use for failure.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTextNotEquals($expected, $result, $message = '') {
|
||||
$expected = str_replace(array("\r\n", "\r"), "\n", $expected);
|
||||
|
@ -231,8 +233,8 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
*
|
||||
* @param string $expected The expected value.
|
||||
* @param string $result The actual value.
|
||||
* @param message The message to use for failure.
|
||||
* @return boolean
|
||||
* @param string $message message The message to use for failure.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTextEquals($expected, $result, $message = '') {
|
||||
$expected = str_replace(array("\r\n", "\r"), "\n", $expected);
|
||||
|
@ -244,10 +246,10 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* Asserts that a string starts with a given prefix, ignoring differences in newlines.
|
||||
* Helpful for doing cross platform tests of blocks of text.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @return boolean
|
||||
* @param string $prefix The prefix to check for.
|
||||
* @param string $string The string to search in.
|
||||
* @param string $message The message to use for failure.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTextStartsWith($prefix, $string, $message = '') {
|
||||
$prefix = str_replace(array("\r\n", "\r"), "\n", $prefix);
|
||||
|
@ -259,10 +261,10 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* Asserts that a string starts not with a given prefix, ignoring differences in newlines.
|
||||
* Helpful for doing cross platform tests of blocks of text.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @return boolean
|
||||
* @param string $prefix The prefix to not find.
|
||||
* @param string $string The string to search.
|
||||
* @param string $message The message to use for failure.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTextStartsNotWith($prefix, $string, $message = '') {
|
||||
$prefix = str_replace(array("\r\n", "\r"), "\n", $prefix);
|
||||
|
@ -274,10 +276,10 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* Asserts that a string ends with a given prefix, ignoring differences in newlines.
|
||||
* Helpful for doing cross platform tests of blocks of text.
|
||||
*
|
||||
* @param string $suffix
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @return boolean
|
||||
* @param string $suffix The suffix to find.
|
||||
* @param string $string The string to search.
|
||||
* @param string $message The message to use for failure.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTextEndsWith($suffix, $string, $message = '') {
|
||||
$suffix = str_replace(array("\r\n", "\r"), "\n", $suffix);
|
||||
|
@ -289,10 +291,10 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* Asserts that a string ends not with a given prefix, ignoring differences in newlines.
|
||||
* Helpful for doing cross platform tests of blocks of text.
|
||||
*
|
||||
* @param string $suffix
|
||||
* @param string $string
|
||||
* @param string $message
|
||||
* @return boolean
|
||||
* @param string $suffix The suffix to not find.
|
||||
* @param string $string The string to search.
|
||||
* @param string $message The message to use for failure.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTextEndsNotWith($suffix, $string, $message = '') {
|
||||
$suffix = str_replace(array("\r\n", "\r"), "\n", $suffix);
|
||||
|
@ -304,11 +306,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* Assert that a string contains another string, ignoring differences in newlines.
|
||||
* Helpful for doing cross platform tests of blocks of text.
|
||||
*
|
||||
* @param string $needle
|
||||
* @param string $haystack
|
||||
* @param string $message
|
||||
* @param boolean $ignoreCase
|
||||
* @return boolean
|
||||
* @param string $needle The string to search for.
|
||||
* @param string $haystack The string to search through.
|
||||
* @param string $message The message to display on failure.
|
||||
* @param bool $ignoreCase Whether or not the search should be case-sensitive.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTextContains($needle, $haystack, $message = '', $ignoreCase = false) {
|
||||
$needle = str_replace(array("\r\n", "\r"), "\n", $needle);
|
||||
|
@ -320,11 +322,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* Assert that a text doesn't contain another text, ignoring differences in newlines.
|
||||
* Helpful for doing cross platform tests of blocks of text.
|
||||
*
|
||||
* @param string $needle
|
||||
* @param string $haystack
|
||||
* @param string $message
|
||||
* @param boolean $ignoreCase
|
||||
* @return boolean
|
||||
* @param string $needle The string to search for.
|
||||
* @param string $haystack The string to search through.
|
||||
* @param string $message The message to display on failure.
|
||||
* @param bool $ignoreCase Whether or not the search should be case-sensitive.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTextNotContains($needle, $haystack, $message = '', $ignoreCase = false) {
|
||||
$needle = str_replace(array("\r\n", "\r"), "\n", $needle);
|
||||
|
@ -338,32 +340,41 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
*
|
||||
* Checks for an input tag with a name attribute (contains any non-empty value) and an id
|
||||
* attribute that contains 'my-input':
|
||||
* array('input' => array('name', 'id' => 'my-input'))
|
||||
*
|
||||
* ```
|
||||
* 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'
|
||||
* )
|
||||
*
|
||||
* ```
|
||||
* array(
|
||||
* array('p' => true),
|
||||
* 'textA',
|
||||
* '/p',
|
||||
* array('p' => true),
|
||||
* 'textB',
|
||||
* '/p'
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* 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:
|
||||
* array(
|
||||
* array('input' => array('name', 'id' => 'preg:/FieldName\d+/')),
|
||||
* 'preg:/My\s+field/'
|
||||
* )
|
||||
*
|
||||
* ```
|
||||
* array(
|
||||
* array('input' => array('name', 'id' => 'preg:/FieldName\d+/')),
|
||||
* 'preg:/My\s+field/'
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* Important: This function is very forgiving about whitespace and also accepts any
|
||||
* permutation of attribute order. It will also allow whitespace between specified tags.
|
||||
*
|
||||
* @param string $string An HTML/XHTML/XML string
|
||||
* @param array $expected An array, see above
|
||||
* @param string $message SimpleTest failure output string
|
||||
* @return boolean
|
||||
* @param string $fullDebug Whether or not more verbose output should be used.
|
||||
* @return bool
|
||||
*/
|
||||
public function assertTags($string, $expected, $fullDebug = false) {
|
||||
$regex = array();
|
||||
|
@ -381,7 +392,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
$tags = (string)$tags;
|
||||
}
|
||||
$i++;
|
||||
if (is_string($tags) && $tags{0} == '<') {
|
||||
if (is_string($tags) && $tags{0} === '<') {
|
||||
$tags = array(substr($tags, 1) => array());
|
||||
} elseif (is_string($tags)) {
|
||||
$tagsTrimmed = preg_replace('/\s+/m', '', $tags);
|
||||
|
@ -389,12 +400,12 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
if (preg_match('/^\*?\//', $tags, $match) && $tagsTrimmed !== '//') {
|
||||
$prefix = array(null, null);
|
||||
|
||||
if ($match[0] == '*/') {
|
||||
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]))),
|
||||
sprintf('%s<[\s]*\/[\s]*%s[\s]*>[\n\r]*', $prefix[1], substr($tags, strlen($match[0]))),
|
||||
$i,
|
||||
);
|
||||
continue;
|
||||
|
@ -437,8 +448,13 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
$val = '.+?';
|
||||
$explanations[] = sprintf('Attribute "%s" present', $attr);
|
||||
} elseif (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
||||
$quotes = '["\']?';
|
||||
$val = $matches[1];
|
||||
$val = str_replace(
|
||||
array('.*', '.+'),
|
||||
array('.*?', '.+?'),
|
||||
$matches[1]
|
||||
);
|
||||
$quotes = $val !== $matches[1] ? '["\']' : '["\']?';
|
||||
|
||||
$explanations[] = sprintf('Attribute "%s" matches "%s"', $attr, $val);
|
||||
} else {
|
||||
$explanations[] = sprintf('Attribute "%s" == "%s"', $attr, $val);
|
||||
|
@ -449,16 +465,9 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
$i++;
|
||||
}
|
||||
if ($attrs) {
|
||||
$permutations = $this->_arrayPermute($attrs);
|
||||
|
||||
$permutationTokens = array();
|
||||
foreach ($permutations as $permutation) {
|
||||
$permutationTokens[] = implode('', $permutation);
|
||||
}
|
||||
$regex[] = array(
|
||||
sprintf('%s', implode(', ', $explanations)),
|
||||
$permutationTokens,
|
||||
$i,
|
||||
'explains' => $explanations,
|
||||
'attrs' => $attrs,
|
||||
);
|
||||
}
|
||||
$regex[] = array(
|
||||
|
@ -468,9 +477,14 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
);
|
||||
}
|
||||
}
|
||||
foreach ($regex as $i => $assertation) {
|
||||
list($description, $expressions, $itemNum) = $assertation;
|
||||
foreach ($regex as $i => $assertion) {
|
||||
$matches = false;
|
||||
if (isset($assertion['attrs'])) {
|
||||
$string = $this->_assertAttributes($assertion, $string);
|
||||
continue;
|
||||
}
|
||||
|
||||
list($description, $expressions, $itemNum) = $assertion;
|
||||
foreach ((array)$expressions as $expression) {
|
||||
if (preg_match(sprintf('/^%s/s', $expression), $string, $match)) {
|
||||
$matches = true;
|
||||
|
@ -493,30 +507,33 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generates all permutation of an array $items and returns them in a new array.
|
||||
* Check the attributes as part of an assertTags() check.
|
||||
*
|
||||
* @param array $items An array of items
|
||||
* @return array
|
||||
* @param array $assertions Assertions to run.
|
||||
* @param string $string The HTML string to check.
|
||||
* @return void
|
||||
*/
|
||||
protected function _arrayPermute($items, $perms = array()) {
|
||||
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->_arrayPermute($newItems, $newPerms);
|
||||
protected function _assertAttributes($assertions, $string) {
|
||||
$asserts = $assertions['attrs'];
|
||||
$explains = $assertions['explains'];
|
||||
$len = count($asserts);
|
||||
do {
|
||||
$matches = false;
|
||||
foreach ($asserts as $j => $assert) {
|
||||
if (preg_match(sprintf('/^%s/s', $assert), $string, $match)) {
|
||||
$matches = true;
|
||||
$string = substr($string, strlen($match[0]));
|
||||
array_splice($asserts, $j, 1);
|
||||
array_splice($explains, $j, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $permuted;
|
||||
}
|
||||
if ($matches === false) {
|
||||
$this->assertTrue(false, 'Attribute did not match. Was expecting ' . $explains[$j]);
|
||||
}
|
||||
$len = count($asserts);
|
||||
} while ($len > 0);
|
||||
return $string;
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
|
@ -524,14 +541,14 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* Compatibility wrapper function for assertEquals
|
||||
*
|
||||
*
|
||||
* @param mixed $result
|
||||
* @param mixed $expected
|
||||
* @param string $message the text to display if the assertion is not correct
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected static function assertEqual($result, $expected, $message = '') {
|
||||
return self::assertEquals($expected, $result, $message);
|
||||
return static::assertEquals($expected, $result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -540,10 +557,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* @param mixed $result
|
||||
* @param mixed $expected
|
||||
* @param string $message the text to display if the assertion is not correct
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected static function assertNotEqual($result, $expected, $message = '') {
|
||||
return self::assertNotEquals($expected, $result, $message);
|
||||
return static::assertNotEquals($expected, $result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -552,10 +570,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* @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
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected static function assertPattern($pattern, $string, $message = '') {
|
||||
return self::assertRegExp($pattern, $string, $message);
|
||||
return static::assertRegExp($pattern, $string, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -564,10 +583,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* @param mixed $actual
|
||||
* @param mixed $expected
|
||||
* @param string $message the text to display if the assertion is not correct
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected static function assertIdentical($actual, $expected, $message = '') {
|
||||
return self::assertSame($expected, $actual, $message);
|
||||
return static::assertSame($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -576,10 +596,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* @param mixed $actual
|
||||
* @param mixed $expected
|
||||
* @param string $message the text to display if the assertion is not correct
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected static function assertNotIdentical($actual, $expected, $message = '') {
|
||||
return self::assertNotSame($expected, $actual, $message);
|
||||
return static::assertNotSame($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -588,12 +609,19 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* @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
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected static function assertNoPattern($pattern, $string, $message = '') {
|
||||
return self::assertNotRegExp($pattern, $string, $message);
|
||||
return static::assertNotRegExp($pattern, $string, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* assert no errors
|
||||
*
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected function assertNoErrors() {
|
||||
}
|
||||
|
||||
|
@ -602,6 +630,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
*
|
||||
* @param mixed $expected the name of the Exception or error
|
||||
* @param string $message the text to display if the assertion is not correct
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected function expectError($expected = false, $message = '') {
|
||||
|
@ -614,8 +643,9 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* Compatibility wrapper function for setExpectedException
|
||||
*
|
||||
* @param mixed $expected the name of the Exception
|
||||
* @param mixed $name The name of the expected Exception.
|
||||
* @param string $message the text to display if the assertion is not correct
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0.
|
||||
* @return void
|
||||
*/
|
||||
protected function expectException($name = 'Exception', $message = '') {
|
||||
|
@ -628,10 +658,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* @param mixed $first
|
||||
* @param mixed $second
|
||||
* @param string $message the text to display if the assertion is not correct
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected static function assertReference(&$first, &$second, $message = '') {
|
||||
return self::assertSame($first, $second, $message);
|
||||
return static::assertSame($first, $second, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -640,10 +671,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* @param string $object
|
||||
* @param string $type
|
||||
* @param string $message
|
||||
* @deprecated 3.0.0 This is a compatibility wrapper for 1.x. It will be removed in 3.0
|
||||
* @return void
|
||||
*/
|
||||
protected static function assertIsA($object, $type, $message = '') {
|
||||
return self::assertInstanceOf($type, $object, $message);
|
||||
return static::assertInstanceOf($type, $object, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -658,15 +690,15 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
protected static function assertWithinMargin($result, $expected, $margin, $message = '') {
|
||||
$upper = $result + $margin;
|
||||
$lower = $result - $margin;
|
||||
return self::assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
|
||||
return static::assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compatibility function for skipping.
|
||||
*
|
||||
* @param boolean $condition Condition to trigger skipping
|
||||
* @param bool $condition Condition to trigger skipping
|
||||
* @param string $message Message for skip
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
protected function skipUnless($condition, $message = '') {
|
||||
if (!$condition) {
|
||||
|
@ -676,4 +708,41 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
/**
|
||||
* Mock a model, maintain fixtures and table association
|
||||
*
|
||||
* @param string $model The model to get a mock for.
|
||||
* @param mixed $methods The list of methods to mock
|
||||
* @param array $config The config data for the mock's constructor.
|
||||
* @throws MissingModelException
|
||||
* @return Model
|
||||
*/
|
||||
public function getMockForModel($model, $methods = array(), $config = array()) {
|
||||
$defaults = ClassRegistry::config('Model');
|
||||
unset($defaults['ds']);
|
||||
|
||||
list($plugin, $name) = pluginSplit($model, true);
|
||||
App::uses($name, $plugin . 'Model');
|
||||
|
||||
$config = array_merge($defaults, (array)$config, array('name' => $name));
|
||||
|
||||
if (!class_exists($name)) {
|
||||
throw new MissingModelException(array($model));
|
||||
}
|
||||
$mock = $this->getMock($name, $methods, array($config));
|
||||
|
||||
$availableDs = array_keys(ConnectionManager::enumConnectionObjects());
|
||||
|
||||
if ($mock->useDbConfig !== 'test' && in_array('test_' . $mock->useDbConfig, $availableDs)) {
|
||||
$mock->setDataSource('test_' . $mock->useDbConfig);
|
||||
} else {
|
||||
$mock->useDbConfig = 'test';
|
||||
$mock->setDataSource('test');
|
||||
}
|
||||
|
||||
ClassRegistry::removeObject($name);
|
||||
ClassRegistry::addObject($name, $mock);
|
||||
return $mock;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue