Search code examples
testingphpunitlaravelautoloadlaravel-3

Autoloading in Laravel Tests


I'm trying to start writing tests within Laravel. I think it is good practice to write my own basic TestCase, that runs the test setup (for example migrations).

<?php

class TestCase extends PHPUnit_Framework_TestCase {
    public function setUp()
    {
        parent::setUp();

        // just for example:
        DB::table('categories')->first();
    }

}

After that, I want to inherit all my TestCases from the one created above

<?php

class TestExample extends TestCase {
    public function testSomethingIsTrue()
    {
        $this->assertTrue(true);    
    }
}

So now I have three problems:

  1. My TestCase throws error, class DB not found. Why the heck is the test not autoloading Laravel Framework Classes?

  2. PHPUnit tells me (with a warning) that my TestCase does not contain any tests, but that is my suspected behaviour for this class, how can I avoid this message?

  3. My TestExample cannot find the class TestCase.

Can you help me understanding that?! How can I configure a test specific autoloading?

UPDATE: Answer 1: Because I run the tests in NetBeans IDE, that needs to be configured! Setting up the right phpunit.xml helped


Solution

  • As revealed in our discussion, when you run your PHPUnit tests using your IDE (NetBeans, PhpStrom and so), you have to make sure your IDE is correctly configured to catch phpunit.xml.