1
votes

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

1
You tagged Laravel 3, but Artisan is a Laravel 4 class, mixing up?Muhammad Usman
Okay yes, this definitely could be... :)skorzinetzki
I just tried out with another Laravel class: DB. This class was not found, too. So the question is still: How can I use Laravel classes in my tests?skorzinetzki
Are you using Laravel 4 then? All classes should work in tests, you are missing something apparent. How are you running tests? Do you have a phpunit.xml in the Laravel root?Muhammad Usman
I found one problem! And sorry for not mentioning it. I configured my IDE to run the tests. (NetBeans) But it was not right configured... It missed the phpunit.xml. Now when I run the tests, this works.skorzinetzki

1 Answers

2
votes

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.