Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fixes error thrown by test.php when Model has no Test cases. #898

wants to merge 1 commit into


None yet
2 participants

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)

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

    App::uses('User', 'Model');

     * User Test Case
    class UserTest extends CakeTestCase {

     * Fixtures
     * @var array
        public $fixtures = array(

     * setUp method
     * @return void
        public function setUp() {
            $this->User = ClassRegistry::init('User');

     * tearDown method
     * @return void
        public function tearDown() {


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

Fixes trowing of "Call to undefined method PHPUnit_Framework_Assertio…
…nFailedError::getComparisonFailure()" when model has no tests.

@dereuromark dereuromark commented on the diff Oct 12, 2012

if (is_object($failure)) {
+ $failure = $message->getComparisonFailure();

dereuromark Oct 12, 2012


thats not a fix. that breaks it for good :) the if case will never return true now.


andrewsavill Oct 12, 2012

hmmm that is a fair point lol. Second try coming in a few mins.

OK I'm going to have to hide behind my "New to GIT" shield. This has been fixed with this pull request here


I was actually working off of the newest Tag instead of the newest 2.X Branch.


dereuromark commented Oct 12, 2012

yeah, I thought I had fixed it already :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment