gadreel's avatar

PHPUnit runs only one test.

Hi,

I am trying to test a sample class and and when I run vendor/bin/phpunit it only runs one test and stops.

For example for the below it just outputs a dot (.) that according to the documentation it pass the tests. But if you look at the second method it expects to be true but I set it to false and it stills outputs a dot.

Is like PHP Unit runs only the first method and it stops. What I am doing wrong?

<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $this->assertTrue(true);
    }

    /**
     * @test
     */
    public function testFirstTest()
    {
        $this->assertTrue(false);
    }

    /**
     * @test
     */
    public function testSecondTest()
    {
        $this->assertTrue(true);
    }

    /**
     * @test
     */
    public function testThirdTest()
    {
        $this->assertTrue(true);
    }
}

This is my phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Modules">
            <directory suffix="Test.php">./Modules/**/Tests</directory>
        </testsuite>
        <testsuite name="Modules-Feature">
            <directory suffix="Test.php">./Modules/**/Tests/Feature</directory>
        </testsuite>
        <testsuite name="Modules-Unit">
            <directory suffix="Test.php">./Modules/**/Tests/Unit</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
			<directory suffix=".php">./modules</directory>
            <exclude>
                <directory suffix="blade.php">./modules</directory>
                <directory suffix=".php">./modules/**/Routes</directory>
                <directory suffix=".php">./modules/**/Resources</directory>
                <directory suffix=".php">./modules/**/Tests</directory>
                <directory suffix=".php">./modules/**/Config</directory>
            </exclude>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>
0 likes
1 reply
gadreel's avatar
gadreel
OP
Best Answer
Level 4

I finally figured it out with --debug. The 2nd test actually never ended. According to PHP Error logs I had some helpers that did not have if (! function_exists('function_name')) { therefore PHP was re-declaring them causing a Fatal Error.

Please or to participate in this conversation.