cakephp/cakephp — pull request #898 by Savvy84 (2012-10-12 10:20:10+00:00)
Title: Fixes error thrown by test.php when Model has not Test cases.

When running a test from Test.php on a Model with no test cases a "Call to undefined method PHPUnit_Framework_AssertionFailedError::getComparisonFailure() " error is thrown.

This seems to be because $failure being asked for getComparisonFailure(); before being checked it is an object.

$failure = $message->getComparisonFailure();
if (is_object($failure)) {
$actualMsg = $message->getComparisonFailure()->getActualAsString();
$expectedMsg = $message->getComparisonFailure()->getExpectedAsString();
}

I move the check and added an empty string to $failure as it was throwing another editor.

I am fairly new to PHP and GIT so if there is a more elegant way of doing this then please amend my commit.

Here is a test case (taken from a bug fix page).

1.create users table

CREATE TABLE users (
id int(20) NOT NULL AUTO_INCREMENT,
username varchar(191) CHARACTER SET ascii NOT NULL,
`password` varchar(191) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
email varchar(191) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
created datetime NOT NULL,
modified datetime NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAUL

2.execute "./cake bake all user"
3.open "/Test/Case/Model/UserTest.php"

User = ClassRegistry::init('User');
}

/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->User);

parent::tearDown();
}
}

4.access "/test.php?case=Model%2FUser"
5.error "Call to undefined method PHPUnit_Framework_AssertionFailedError::getComparisonFailure()"