orchestral/testbench

Target class [cache.store] does not exist when running setUp function

Drenth1 opened this issue · 0 comments

  • Testbench Version: 8.0.5
  • Laravel Version: 10.2
  • PHP Version: 8.2.0
  • PHPUnit Version: 9.6.4
  • Database Driver & Version: MySQL (10.4.27-MariaDB)

Description:

When I run my tests for my Laravel package using ./vendor/bin/phpunit tests --testdox I get the following error:

Illuminate\Contracts\Container\BindingResolutionException: Target class [cache.store] does not exist.

Steps To Reproduce:

  1. Create a BaseTestCase that extends the \Orchestra\Testbench\TestCase testcase
class BaseTestCase extends \Orchestra\Testbench\TestCase
{
    public function setUp() : void
    {
        parent::setUp(); // the line that throws the error
    }

    protected function getApplicationProviders($app) : array
    {
        return [
            MyApplicationKernelServiceProvider::class
        ];
    }

    protected function getEnvironmentSetUp($app) : void
    {
        $app['config']->set('database.default', 'testing');
        $app['config']->set('database.connections.testing', [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        ]);
    }
}
  1. Create a testcase that extends the BaseTestCase and add a simple assertion
class BaseTest extends BaseTestCase
{
    public function test_we_can_run_tests() : void
    {
        $this->assertTrue(true);
    }
}
  1. Attempt to run the tests with ./vendor/bin/phpunit tests --testdox

Additional information

  • When I comment out parent::setUp();, the test runs normally.
  • When I comment out getEnvironmentSetup(), getApplicationProviders() or both, the error remains the same.
  • I've used this setup for older Laravel, Testbench and PHPUnit versions and it worked properly.
  • This is my phpunit.xml configuration:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        bootstrap="vendor/autoload.php"
        backupGlobals="false"
        backupStaticAttributes="false"
        colors="true"
        verbose="true"
        convertErrorsToExceptions="true"
        convertNoticesToExceptions="true"
        convertWarningsToExceptions="true"
        processIsolation="false"
        stopOnFailure="false"
        xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd">
    <coverage>
        <include>
            <directory suffix=".php">src/</directory>
        </include>
    </coverage>
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <php>
        <env name="DB_CONNECTION" value="testing"/>
        <env name="APP_KEY" value="<removed>"/>
    </php>
</phpunit>