Note that there are some explanatory texts on larger screens.

plurals
  1. POPHPUnit: Fatal error Class ClassName not found
    primarykey
    data
    text
    <p>I'm trying to build a Unit Testing environment for a CodeIgniter application. I'm following <a href="https://github.com/efendibooks/codeigniter-handbook-vol-3/" rel="nofollow">this book</a> and got PHPUnit to work.</p> <p>I'm at a point where I'm testing some code in a model:</p> <pre><code> public function testPresent() { $tracker = new Tracker_model(); $tableObj = (object)array( 'type' =&gt; $this-&gt;expectedConstants['TABLE']); $visitsObj = (object)array( 'type' =&gt; $this-&gt;expectedConstants['VISITS']); $tableObj = $tracker-&gt;present($tableObj); $visitsObj = $tracker-&gt;present($visitsObj); $this-&gt;assertThat($tableObj, $this-&gt;isInstanceOf('Tracker_TablePresenter')); $this-&gt;assertThat($visitsObj, $this-&gt;isInstanceOf('Tracker_VisitsPresenter')); } </code></pre> <p>The code being tested is this:</p> <pre><code> public function present($obj) { if( isset($obj-&gt;type) ) { switch($obj-&gt;type) { case self::VISITS: $type = 'Visits'; break; case self::TABLE: default: $type = 'Table'; break; } $className = 'Tracker_'.$type.'Presenter'; $obj = new $className($obj, 'tracker'); } return $obj; } </code></pre> <p>It should load the class <code>Tracker_TablePresenter</code> which is in the file <code>presenters/tracker/TablePresenter.php</code>. I can't explain all the logic behind this mechanism because it would be too long and complex, but I know it works, because on another computer with the exact same code it's passing the test. On my computer, instead, I get this error:</p> <pre><code>.......PHP Fatal error: Class 'Tracker_TablePresenter' not found in /home/.../application/models/tracker_model.php on line 42 </code></pre> <p>More information on the error:</p> <pre><code>PHP Stack trace: PHP 1. {main}() /.../vendor/phpunit/phpunit/composer/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /.../vendor/phpunit/phpunit/composer/bin/phpunit:63 PHP 3. PHPUnit_TextUI_Command-&gt;run() /.../vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129 PHP 4. PHPUnit_TextUI_TestRunner-&gt;doRun() /.../vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176 PHP 5. PHPUnit_Framework_TestSuite-&gt;run() /.../vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:349 PHP 6. PHPUnit_Framework_TestSuite-&gt;run() /.../vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:705 PHP 7. PHPUnit_Framework_TestSuite-&gt;runTest() /.../vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745 PHP 8. PHPUnit_Framework_TestCase-&gt;run() /.../vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775 PHP 9. PHPUnit_Framework_TestResult-&gt;run() /.../vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:776 PHP 10. PHPUnit_Framework_TestCase-&gt;runBare() /.../vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648 PHP 11. PHPUnit_Framework_TestCase-&gt;runTest() /.../vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:831 PHP 12. ReflectionMethod-&gt;invokeArgs() /.../vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:976 PHP 13. Tracker_modelTest-&gt;testPresent() /.../vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:976 PHP 14. Tracker_model-&gt;present() /.../application/tests/models/Tracker_modelTest.php:38 </code></pre> <p>I'm working on Ubuntu, while the other guy who has the code working is using a Mac. This is the output of my php -v</p> <pre><code>PHP 5.4.9-4ubuntu2 (cli) (built: Mar 11 2013 16:09:26) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.3.0dev, Copyright (c) 2002-2013, by Derick Rethans </code></pre> <p>I also tried downgrading php to 5.3, since he is using the 5.3, but nothing. Same error. Can you help me understanding what's going on?</p> <p>Edit:</p> <p>This is the content of the file <code>TablePresenter.php</code></p> <pre><code>&lt;?php class Tracker_TablePresenter extends Presenter { public function values() { $this-&gt;ci =&amp; get_instance(); if (!isset($this-&gt;values)) { $this-&gt;ci-&gt;load-&gt;model('value_model', 'value'); $this-&gt;values = $this-&gt;ci-&gt;value-&gt;getManyForTracker($this-&gt;tracker-&gt;id); } return $this-&gt;values; } } ?&gt; </code></pre> <p>Edit 2:</p> <p>I changed the code in the <code>present</code> function as suggested by JoDev like this:</p> <pre><code> public function present($obj) { if( isset($obj-&gt;type) ) { switch($obj-&gt;type) { case self::VISITS: $type = 'Visits'; break; case self::TABLE: default: $type = 'Table'; break; } //use include, but require is to force an internal error if the file isn't founded! require_once('presenters/tracker/'.$type.'Presenter.php'); $className = 'Tracker_'.$type.'Presenter'; $obj = new $className($obj, 'tracker'); } return $obj; } </code></pre> <p>Now I get this error:</p> <pre><code>PHPUnit 3.7.21 by Sebastian Bergmann. Configuration read from .../phpunit.xml .......PHP Fatal error: Class 'Tracker_TablePresenter' not found in .../application/models/tracker_model.php on line 61 PHP Stack trace: PHP 1. {main}() .../vendor/phpunit/phpunit/composer/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() .../vendor/phpunit/phpunit/composer/bin/phpunit:63 PHP 3. PHPUnit_TextUI_Command-&gt;run() .../vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129 PHP 4. PHPUnit_TextUI_TestRunner-&gt;doRun() .../vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:176 PHP 5. PHPUnit_Framework_TestSuite-&gt;run() .../vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:349 PHP 6. PHPUnit_Framework_TestSuite-&gt;run() .../vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:705 PHP 7. PHPUnit_Framework_TestSuite-&gt;runTest() .../vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:745 PHP 8. PHPUnit_Framework_TestCase-&gt;run() .../vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:775 PHP 9. PHPUnit_Framework_TestResult-&gt;run() .../vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:776 PHP 10. PHPUnit_Framework_TestCase-&gt;runBare() .../vendor/phpunit/phpunit/PHPUnit/Framework/TestResult.php:648 PHP 11. PHPUnit_Framework_TestCase-&gt;runTest() .../vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:831 PHP 12. ReflectionMethod-&gt;invokeArgs() .../vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:976 PHP 13. Tracker_modelTest-&gt;testPresent() .../vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php:976 PHP 14. Tracker_model-&gt;present() .../application/tests/models/Tracker_modelTest.php:37 </code></pre> <p></p> <pre><code>&lt;h4&gt;A PHP Error was encountered&lt;/h4&gt; &lt;p&gt;Severity: Warning&lt;/p&gt; &lt;p&gt;Message: include(presenters/tracker/TablePresenter.php): failed to open stream: No such file or directory&lt;/p&gt; &lt;p&gt;Filename: models/tracker_model.php&lt;/p&gt; &lt;p&gt;Line Number: 58&lt;/p&gt; &lt;/div&gt;&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"&gt; &lt;h4&gt;A PHP Error was encountered&lt;/h4&gt; &lt;p&gt;Severity: Warning&lt;/p&gt; &lt;p&gt;Message: include(): Failed opening 'presenters/tracker/TablePresenter.php' for inclusion (include_path='.../vendor/phpunit/php-text-template:.../vendor/phpunit/phpunit-mock-objects:.../vendor/phpunit/php-timer:.../vendor/phpunit/php-token-stream:.../vendor/phpunit/php-file-iterator:.../vendor/phpunit/php-code-coverage:.../vendor/phpunit/phpunit:.../vendor/symfony/yaml:.../vendor/pdepend/pdepend/src/main/php:.../vendor/phpmd/phpmd/src/main/php:.:/usr/share/php:/usr/share/pear')&lt;/p&gt; &lt;p&gt;Filename: models/tracker_model.php&lt;/p&gt; &lt;p&gt;Line Number: 58&lt;/p&gt; &lt;/div&gt;% </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload