orchestral/testbench

sqlite settings appears to be ignored getting access denied

Closed this issue · 3 comments

  • Testbench Version: 7.22
  • Laravel Version: 9.51.0
  • PHP Version: 8.2
  • Database Driver & Version: sqlite

Description:

I'm not certain if I've installed testbench correctly when trying to run tests I'm getting Access denied for user 'forge'@'localhost' but sqlite should be used.

My test case:

<?php

namespace Dcblogdev\MsGraph\Tests;

use AllowDynamicProperties;
use Dcblogdev\MsGraph\MsGraphServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Orchestra\Testbench\TestCase as Orchestra;

class TestCase extends Orchestra
{
    use RefreshDatabase;

    protected function getPackageProviders($app)
    {
        return [
            MsGraphServiceProvider::class,
        ];
    }

    protected function getEnvironmentSetUp($app)
    {
        // Setup default database to use sqlite :memory:
        $app['config']->set('database.default', 'testing');
        $app['config']->set('database.connections.testing', [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        ]);
    }
}

In my service provder I have:

public function boot(Router $router)
    {
        $this->mergeConfigFrom(__DIR__.'/../config/msgraph.php', 'msgraph');
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
        $this->registerMiddleware($router);

        if ($this->app->runningInConsole()) {
            $this->registerCommands();
            $this->configurePublishing();
        }
    }

Also in phpunit.xml

<?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.3/phpunit.xsd"
>
  <coverage>
    <include>
      <directory suffix=".php">src/</directory>
    </include>
  </coverage>
  <testsuites>
    <testsuite name="Test">
      <directory suffix="Test.php">./tests</directory>
    </testsuite>
  </testsuites>
  <php>
    <env name="DB_CONNECTION" value="testing"/>
    <env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
  </php>
</phpunit>

If it helps here's a direct link to my package https://github.com/dcblogdev/laravel-microsoft-graph/blob/master/tests/TestCase.php

Don't use RefreshDatabase.

removing the trait doesn't change the error I'm getting.

Testbench own tests already cover using sqlite in memory without any issue.