Looking at the laravel testing documentation, you get an idea of all the cool helpers I'd love to use in workbench.
Sadly I'm unable to do so.
Illuminate\Foundation\Testing\TestCase
seems to be unavailable when running my tests from the package directory and therefore i can't extend it.
<?php namespace Acme\Foo;
class TestCase extends \Illuminate\Foundation\Testing\TestCase {
/**
* Creates the application.
*
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../../../../bootstrap/start.php';
}
}
PHP Fatal error: Class 'Illuminate\Foundation\Testing\TestCase' not found in
/Applications/MAMP/htdocs/Webseiten/acme/workbench/acme/foo/tests/TestCase.php on line 3
I think thats not the correct way, this should be done anyways...
I have already found orchestral/testbench but I'm not really sure if it is a good idea to use it. It seems to require the whole laravel framework, which doesn't make sense to me? ( A package should extend a laravel install and not add the framework a second time!? )
I just did like this,
First of all, change your
phpunit.xml
content on your workbench directory. You will "bootstrap" attribute section, change it fromvendor/autoload.php
to../../../bootstrap/autoload.php
Then try running
phpunit
on your workbench directory.For me, because of the way workbench is setup, the test cases can only extend from PHPUnit_Framework_TestCase. So I run the test cases from the app folder instead of the package folder.
I choose the second option as testbench heavily depends on the particular Laravel version and seems a bit heavy to set up. What I did is configure the phpunit.xml under the main app to include the package tests folder as a test suite:
And then run:
Using this method, we can still extends from \Illuminate\Foundation\Testing\TestCase.
I found this solution at http://ngo-hung.com/blog/2014/04/16/laravel-unit-testing-in-workbench-note
Removing
should fix it. Then you can run tests from the package dir. Also be sure to run composer dump-autoload in the package dir or php artisan dump-autoload from main app dir.
UPDATE I was able to replicate the error in a clean Laravel 4.1 installation and fixed it following this steps without installing extra packages:
1 - Install PHPUnit in the main laravel root composer.json (not the workbench package composer.json file)
2 - Run composer update in main laravel root dir.
3 - In your test classes use fully qualified names (namespace prefixed with )
4 - To run workbench package tests, go to package directory and run main phpunit
5 - Output Green flag recognizing laravel app third party packages