Text size +/-

19 Dec 07 _ Beware Testing Group Models in Cakephp


By casey
in CakePHP, Casey's Corner

If you haven’t read the Bakery article on Testing Models in Cakephp, by Mariano Iglesias, you should go and read it now.

Having read that, there is something to watch out for. I have a authorization system that uses a model called Group which hasMany users. Ok. After making a series of tests in the vein of Mariano’s article, I came across this error when trying to run the test:


Fatal error: Cannot redeclare class GroupTest in /xxxx/app/tests/cases/models/group.test.php on line 6

Line six of group.text.php was pretty basic, just declaring the GroupTest class model to use in the test:


class GroupTest extends Group {
    var $name = 'GroupTest';
    var $useDbConfig = 'test_suite';
}

After poking around a bit, I found this, on line 608 of test_case.php in the /vendors/simpletest/ directory.


class GroupTest extends TestSuite { }

Ah! The SimpleTest program itself was declaring the GroupClass for doing group tests. So just renaming my model to “GroupTestModel” or the like fixed the problem.

Spread the Word:
  • Slashdot
  • Digg
  • Facebook
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • NewsVine



Leave a Reply