Laravel 4.2: Test Case Startup

Now that I am setting up a new test for my Laravel application, it is spreading from the TestCase base class

 class SomeTest extends TestCase { } 

I would like to create a new base test class called AnotherTestCase , so I can create test cases that share setup / break / helper / etc methods ...

 class SomeTest extends AnotherTestCase { } 

However, when I run

 phpunit app/tests/SomeTest.php 

I get the following error

 PHP Fatal error: Class 'AnotherTestCase' not found in /[...]/app/tests/SomeTest.php on line 3 

This is despite the fact that I have a class defined in

 #File: app/tests/AnotherTestCase.php <?php class AnotherTestCase extends TestCase { } 

This is confusing since phpunit automatically loads the TestCase class.

Do I need to manually require in custom base test classes, or is there a way to tell phpunit about my new base test class? In other words, why phpunit automatically loads TestCase but does not automatically load AnotherTestCase

+5
source share
1 answer

You can get around this error by adding it to your composer.json :

 "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/filters", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php", "app/tests/AnotherTestCase.php" // <-- Add Me ], // ... 

Then make sure you do composer dump-autoload . I just checked this by adding the following class:

 class AnotherTestCase extends TestCase {} 

And he changed one of my existing tests to use it as his parent instead. I believe the entry in composer.json is how you can load TestCase .

+7
source

Source: https://habr.com/ru/post/1201660/


All Articles