So I have a very peculiar problem with my unit tests in laravel. What I am trying to do is some basic unit testing, and so I have a single class set up with my tests. The tests worked perfectly when I had a single method that ran tests. The class looked like so:
class Pixel_BasicTest extends Illuminate\Foundation\Testing\TestCase {
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
return $app;
}
public function testRoutes(){
echo "Start of testRoutes\n";
//Test all the GET routes we have
$routeCollection = Route::getRoutes();
$num_404s = 0;
$path_404s = [];
...various other code that does some tests, these all work right
}
}
Now, the problem occurs when I try to add another function. My class now looks like this:
class Pixel_BasicTest extends Illuminate\Foundation\Testing\TestCase {
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
return $app;
}
public function testRoutes(){
echo "Start of testRoutes\n";
//Test all the GET routes we have
$routeCollection = Route::getRoutes();
$num_404s = 0;
$path_404s = [];
...various other code that does some tests, these all work right
}
public function testSecondThing() {
echo "Start of testSecondThing";
...some code testing something else
}
}
Now, I know that the code from the 2nd function works, because when I put that code in the first function, and remove the 2nd function entirely, the tests run perfectly. However, when I put the code in a second function, it fails, and my terminal window looks like this:
Mikes-MacBook-Air-96:hq pixelmember$ ./vendor/bin/phpunit -v --debug
PHPUnit 4.8.29 by Sebastian Bergmann and contributors.
Runtime: PHP 5.6.10
Configuration: /Users/pixelmember/Documents/hq/phpunit.xml
Starting test 'Pixel_BasicTest::testRoutes'.
.Start of testRoutes
End of testRoutes
Starting test 'Pixel_BasicTest::testAfterschool'.
Mikes-MacBook-Air-96:hq pixelmember$
As you can see, it gets to the 2nd function, and just stops or fails or something. There is no error message, and I also don't see the message I wrote in the code at the start of the function (The echo "Starting testSecondThing()" part)
I'm honestly at a loss for what to do. I can make do without the unit tests for now, and can work on some other parts of my application, but I really want to be able to use unit tests without having to stick every single one of my tests in a single function.
In case it helps, here is my phpunit.xml file. Perhaps someone can see something in here:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<file>./tests/Pixel_BasicTest.php</file>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory>./vendor</directory>
</blacklist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="DB_DATABASE" value="test"/>
<env name="DB_USERNAME" value="root"/>
<env name="DB_PASSWORD" value=""/>
</php>
I didn't really edit or change much of this file, besides adding some database related environment variables.
EDIT: I FIXED MY ISSUE, SEE BELOW FOR FIX