This is my directory Structure
application
---modules
------admin
---------models
-----------User.php
This is my user Model class
class admin_Model_User
{
//User.php
}
This is my UserTest Class with simple AssertType
class admin_Model_UserTest
extends PHPUnit_Framework_TestCase
{
public function testUserModel()
{
$testUser = new admin_Model_User();
$this->assertType("admin_Model_User",$testUser);
}
}
When I run this. I am getting following Errors
[tests]# phpunit
PHPUnit 3.5.13 by Sebastian Bergmann.
0
Fatal error: Class 'admin_Model_User' not found in /web/zendbase/tests/application/modules/admin/models/UserTest.php on line 18
I know there my must be some path setting. I really could not able to figure out what is really wrong. Looking for help.....
All I need to do is this
// and then require_once it in Bootstrap file. thats all :) it is working.
You need to bootstrap Zend in your project's PHPUnit bootstrap.php file. Even though you are testing models and thus don't need the dispatcher, you must still have
Zend_Application
loadapplication.ini
and register its autoloader.You can use
Zend_Test_PHPUnit_ControllerTestCase
to do the bootstrapping instead and make sure your model tests run after one of these, but that's a bit hacky.Another option is to
require_once
the model classes manually for each test. The reason this doesn't work automatically via PHPUnit's autoloader is that it doesn't know how to transform the "namespace"admin_Model
into the pathadmin/models
.Finally, you could write a simple autoloader to replace the one in PHPUnit. Before converting underscores to slashes, check if the class begins with the "namespace" above and replace it if so.