Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'TestCase' not found. #39

Closed
AhabTheCaptain opened this issue Aug 4, 2015 · 5 comments
Closed

Class 'TestCase' not found. #39

AhabTheCaptain opened this issue Aug 4, 2015 · 5 comments

Comments

@AhabTheCaptain
Copy link

Hello,
I am having problems setting up ci-phpunit-test with PHPUnit 4.7 and CodeIgniter 3. I have gone through the documentation here and on the PHPUnit site to ensure I haven't missed any setup steps, but maybe that is all that is happening here. When I run a specific test case file with phpunit, I receive the following error message:

vagrant@vagrant-ubuntu-trusty-64:/var/www/html/application/tests/models/User$ phpunit User_model_test.php
/*
** Unit tests for the User Model.
**
**
*/

PHP Fatal error:  Class 'TestCase' not found in /var/www/html/application/tests/models/User/User_model_test.php on line 11
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:537
PHP   3. PHPUnit_TextUI_Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:99
PHP   4. PHPUnit_Runner_BaseTestRunner->getTest() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:121
PHP   5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php:66
PHP   6. PHPUnit_Runner_StandardTestSuiteLoader->load() phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php:121
PHP   7. PHPUnit_Util_Fileloader::checkAndLoad() phar:///usr/local/bin/phpunit/phpunit/Runner/StandardTestSuiteLoader.php:37
PHP   8. PHPUnit_Util_Fileloader::load() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:36
PHP   9. include_once() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:52

This clears up if I add "include '../TestCase.php';" but then it can't find another class, and so on down the rabbit hole.

The code below is a meaningless test as I am trying to get phpunit to run and be able to find the necessary classes for core functionality.

<?php
// include '../TestCase.php';

class User_model_test extends TestCase 
{
    public function setUp()
    {
        $this->CI =& get_instance();
        $this->load->model('User_model');
        $this->obj = $this->CI->User_model;
    }

    public function testSignUp()
    {
        $actual = $this->obj->signUp();
        $this->assertTrue($actual);
    }
}
?>

Please let me know if I can provide additional relevant details. My PHP knowledge is weak, but I am experienced with JUnit.

Thank You!

@RodolfoSilva
Copy link
Contributor

@kenjis
Copy link
Owner

kenjis commented Aug 4, 2015

It seems you don't load tests/Bootrap.php.

I've got your problem.

vagrant@vagrant-ubuntu-trusty-64:/var/www/html/application/tests/models/User$ phpunit User_model_test.php

You are in application/tests/models/User. But you should have been in application/tests.

phpunit reads phpunit.xml in the current folder.

@RodolfoSilva
Copy link
Contributor

Do you have in your folder test the file TestCase.php

@AhabTheCaptain
Copy link
Author

Thank you for the help. Running phpunit from the tests directory cleared this up. I am getting different errors now, but I will bang on them myself for awhile so I can learn the system. Thanks again for your quick responses to my fairly derpy issue. =)

@kenjis
Copy link
Owner

kenjis commented Aug 5, 2015

No problem.

I added note: ccc0489

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants