Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
how to load model in test? and how to load and test controller ?
  • how to load model in test? and how to load and test controller ? Fatal Error : Model Not Found! this works in the controller: #but does not work in the test namespace Adm; use Adm\Model\Medico;

  • D:\Projetos\periciaseg.com.br>php oil test
    Tests Running...This may take a few moments.
    PHP Fatal error: Class 'Adm\Model\Medico' not found in D:\Projetos\periciaseg.c
    om.br\fuel\app\modules\tests\adm\classes\model\medico.php on line 15
    PHP Stack trace:
    PHP 1. {main}() C:\Program Files (x86)\VertrigoServ\Pear\phpunit:0
    PHP 2. PHPUnit_TextUI_Command::main() C:\Program Files (x86)\VertrigoServ\Pear
    \phpunit:46
    PHP 3. PHPUnit_TextUI_Command->run() C:\Program Files (x86)\VertrigoServ\Pear\
    pear\PHPUnit\TextUI\Command.php:130
    PHP 4. PHPUnit_TextUI_TestRunner->doRun() C:\Program Files (x86)\VertrigoServ\
    Pear\pear\PHPUnit\TextUI\Command.php:192
    PHP 5. PHPUnit_Framework_TestSuite->run() C:\Program Files (x86)\VertrigoServ\
    Pear\pear\PHPUnit\TextUI\TestRunner.php:325
    PHP 6. PHPUnit_Framework_TestSuite->run() C:\Program Files (x86)\VertrigoServ\
    Pear\pear\PHPUnit\Framework\TestSuite.php:705
    PHP 7. PHPUnit_Framework_TestSuite->runTest() C:\Program Files (x86)\VertrigoS
    erv\Pear\pear\PHPUnit\Framework\TestSuite.php:745
    PHP 8. PHPUnit_Framework_TestCase->run() C:\Program Files (x86)\VertrigoServ\P
    ear\pear\PHPUnit\Framework\TestSuite.php:772
    PHP 9. PHPUnit_Framework_TestResult->run() C:\Program Files (x86)\VertrigoServ
    \Pear\pear\PHPUnit\Framework\TestCase.php:751
    PHP 10. PHPUnit_Framework_TestCase->runBare() C:\Program Files (x86)\VertrigoSe
    rv\Pear\pear\PHPUnit\Framework\TestResult.php:649
    PHP 11. PHPUnit_Framework_TestCase->runTest() C:\Program Files (x86)\VertrigoSe
    rv\Pear\pear\PHPUnit\Framework\TestCase.php:804
    PHP 12. ReflectionMethod->invokeArgs() C:\Program Files (x86)\VertrigoServ\Pear
    \pear\PHPUnit\Framework\TestCase.php:942
    PHP 13. Adm\Test_Model_Medico->test_autocomplete() C:\Program Files (x86)\Vertr
    igoServ\Pear\pear\PHPUnit\Framework\TestCase.php:942
    Error - Class 'Adm\Model\Medico' not found in APPPATH/modules/tests/adm/classes/
    model/medico.php on line 15
    D:\Projetos\periciaseg.com.br>
    D:\Projetos\periciaseg.com.br>
  • Is the module loaded? When you request it through the URL, the routing engine will load the module for you, but for a test you have to load it manually.
    \Module::load('adm');
    

    In the setup of your test class.
  • May I ask why you're loading a database model in a unit test? A lot of the time, external things like databases are mocked so you're not relying on them containing the right data.
  • Sorry my English! Thank you! I'm trying to load my models are independent of the database.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion