orchestral / testbench

Laravel Testing Helper for Packages Development
https://packages.tools/testbench
MIT License
2.1k stars 136 forks source link

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

Closed Drenth1 closed 1 year ago

Drenth1 commented 1 year ago

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'   => '',
        ]);
    }
    }
  2. 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

<?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>