Thursday, September 5, 2013

CakePHP integrated with PHPUnit returns error Controller class XYZControllerController could not be found when on live server

I've been successfully running PHPUnit integrated with CakePHP on my local machine. I've just installed PHPUnit onto the live server and tried running the same tests. However, I am seeing errors for every controller that has proper test methods (i.e. there are a couple of controllers that simply have sanity tests in them $this->assertTrue(1==1); ).

Here is a typical message that I receive when I run one of the controller tests for my controller, ClientsController:

MISSINGCONTROLLEREXCEPTION
Controller class ClientsControllerController could not be found.
Test case: ClientsControllerTest(testAddNoName)
Stack trace:
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/Framework/MockObject/Generator.php : 224
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/Framework/TestCase.php : 1325
/home/vg007web05/49/68/2016849/web/lib/Cake/TestSuite/ControllerTestCase.php : 332
/home/vg007web05/49/68/2016849/web/app/Test/Case/Controller/ClientsControllerTest.php : 46
ClientsControllerTest::testAddNoName
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/Framework/TestCase.php : 983
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/Framework/TestCase.php : 838
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/Framework/TestResult.php : 648
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/Framework/TestCase.php : 783
/home/vg007web05/49/68/2016849/web/lib/Cake/TestSuite/CakeTestCase.php : 79
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/Framework/TestSuite.php : 775
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/Framework/TestSuite.php : 745
/home/vg007web05/49/68/2016849/web/lib/PHPUnit/TextUI/TestRunner.php : 349
/home/vg007web05/49/68/2016849/web/lib/Cake/TestSuite/CakeTestRunner.php : 62
/home/vg007web05/49/68/2016849/web/lib/Cake/TestSuite/CakeTestSuiteCommand.php : 115
/home/vg007web05/49/68/2016849/web/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php : 243
/home/vg007web05/49/68/2016849/web/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php : 100
/home/vg007web05/49/68/2016849/web/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php : 117
/home/vg007web05/49/68/2016849/web/app/webroot/test.php : 98

I'm thinking it has something to do with the way the test cases are auto-magically discovered from the tests, but it is strange that it works on my local Apache server, but not on the live server.

Here's the corresponding controller code:

<?php
App::uses('ClientsController', 'Controller');

/**
 * ClientsController Test Case
 *
 */
class ClientsControllerTest extends ControllerTestCase {

/**
 * Fixtures
 *
 * @var array
 */
    public $fixtures = array(
        'app.access_control',
        'app.access_level',
        'app.access_permission',
        'app.article',
        'app.business_address',
        'app.client',
        'app.deactivated_account',
        'app.group',
        'app.offered_specialty',
        'app.professional_membership',
        'app.security_question',
        'app.setting',
        'app.specialty',
        'app.user',
        'app.user_extra_information'
    );

        
/**
 * testAddNoName method
 *
 * @return void
*/
       public function testAddNoName()
       {
            $Clients      = $this->generate('Clients',array(
                'components'    => array(
                    'Session',
                    'Auth'  => array ('user')
                )
            ));
            $Clients->Session
                ->expects ($this->once())
                ->method('setFlash')
                ->with('The new client name could not be saved. Please, try again.');
            $Clients->Auth->staticExpects($this->at(0))
            ->method('user')
            ->with('group_id')
            ->will($this->returnValue(3));
            $Clients->Auth->staticExpects($this->at(1))
            ->method('user')
            ->with('id')
            ->will($this->returnValue(2));// 
            $testdata   = array('Client'=>array('id'=>'','name'=>''));
            $result = $this->testAction('/clients/add/brian', 
                array('return' => 'contents', 'method' => 'post', 'data' => $testdata));
       }
}

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: