Reputation: 5942
I have a number of tests written for a Laravel 5.1 application, and I'm currently using PHPUnit to run the tests. I'm attempting to investigate codeception as we have other applications that aren't built on Laravel, so codeception looks like the easiest way to get a similar interface for testing.
We have a reasonably large team, so I would prefer to use a single consistent command for testing across all projects instead of some using codecept
and some using phpunit
.
Here's what I've tried as my codeception.yml
:
actor: Tester
paths:
tests: tests
log: storage/codeception/_output
data: storage/codeception/_data
support: storage/codeception/_support
envs: storage/codeception/_envs
modules:
enabled:
- Laravel5:
environment_file: .env
But I get this response:
$ codecept run Codeception PHP Testing Framework v2.1.4 Powered by PHPUnit 4.8.18 by Sebastian Bergmann and contributors. [RuntimeException] Suite '' could not be found
So my question is this:
How do I convince codeception to run my existing PHPUnit tests with as little modification as possible?
Upvotes: 3
Views: 805
Reputation: 5942
After a lot of time, I found out that it's possible, but you have to make some modifications to how your tests are laid out. The bonus, though, is that it doesn't stop you from just running PHPUnit itself.
For posterity, here's how to do it:
TestCase.php
into a folder named unit
under the tests
folder.It should look like this:
tests/
tests/unit/
tests/unit/MyUnitTest.php
tests/unit/TestCase.php
unit.suite.yml
file in the tests/
folder.The contents should look something like this:
modules:
enabled:
- Laravel5:
environment_file: .env.testing
composer.json
to with the correct folder for the testing classmapIn your autoload-dev
section:
"classmap": [
"tests/unit/TestCase.php"
]
TestCase.php
to load bootstrap.php
from the correct folder.This should be in the createApplication()
method at the top of TestCase.php
public function createApplication()
{
// $app = require __DIR__ . '/../bootstrap/app.php';
$app = require __DIR__ . '/../../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
Finally, run composer dump-autoload
, and codeception should run. As a bonus, phpunit
should also still run.
Upvotes: 3