Codeception icon indicating copy to clipboard operation
Codeception copied to clipboard

Codeigniter 2 and codeception

Open evancauwenberg opened this issue 14 years ago • 4 comments

Hi i have a clean CodeIgniter framework version 2 installed. And created a phpunit test in /tests/unit/PostTest.php with following contents:

CI = &get_instance(); $this->CI->load->database('testing'); } public function testGetsAllPosts() { $this->CI->load->model('post'); $posts = $this->CI->post->getAll(); $this->assertEquals(1, count($posts)); } ``` } and this is my bootstrap: http://conversal.w0p.be/tests/unit/_bootstrap.phps when i run codecept run unit --bedug i get this: Running PostTest::testGetsAllPosts PHP Fatal error: Call to undefined function get_instance() in /var/www/sites/conversal.w0p.be/tests/unit/PostTest.php on line 9 PHP Stack trace: PHP 1. {main}() /usr/bin/codecept:0 PHP 2. Symfony\Component\Console\Application->run() /usr/bin/codecept:39 PHP 3. Symfony\Component\Console\Application->doRun() /usr/share/php/Codeception/vendor/Symfony/Component/Console/Application.php:105 PHP 4. Symfony\Component\Console\Command\Command->run() /usr/share/php/Codeception/vendor/Symfony/Component/Console/Application.php:188 PHP 5. Codeception\Command\Run->execute() /usr/share/php/Codeception/vendor/Symfony/Component/Console/Command/Command.php:227 PHP 6. Codeception\Codecept->runSuite() /usr/share/php/Codeception/src/Codeception/Command/Run.php:57 PHP 7. Codeception\SuiteManager->run() /usr/share/php/Codeception/src/Codeception/Codecept.php:89 PHP 8. Codeception\PHPUnit\Runner->doEnhancedRun() /usr/share/php/Codeception/src/Codeception/SuiteManager.php:130 PHP 9. PHPUnit_Framework_TestSuite->run() /usr/share/php/Codeception/src/Codeception/PHPUnit/Runner.php:97 PHP 10. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:705 PHP 11. PHPUnit_Framework_TestSuite->runTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:745 PHP 12. PHPUnit_Framework_TestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:772 PHP 13. PHPUnit_Framework_TestResult->run() /usr/share/php/PHPUnit/Framework/TestCase.php:751 PHP 14. PHPUnit_Framework_TestCase->runBare() /usr/share/php/PHPUnit/Framework/TestResult.php:650 PHP 15. PostTest->setUp() /usr/share/php/PHPUnit/Framework/TestCase.php:801 FATAL ERROR OCCURRED. TESTS NOT FINISHED. it looks like it doens't load the _bootstrap?

evancauwenberg avatar Apr 02 '12 18:04 evancauwenberg

Sorry, bootstrap files work only with native Cest or Cept formats. I think I should improve Codeception to make loading of boostrtap file into Test files too. Thanks for your report.

DavertMik avatar Apr 03 '12 19:04 DavertMik

oke so i should rewrite the unit test to a cest?

evancauwenberg avatar Apr 03 '12 19:04 evancauwenberg

No, there is no need in doing so. All the formats should be equal. I will try to release a patch which fixes boostrtap for Test files today.

DavertMik avatar Apr 03 '12 20:04 DavertMik

great !

evancauwenberg avatar Apr 03 '12 21:04 evancauwenberg