I have a PHP unit working on a remote interpreter perfectly.
It work in all cases without PHP Storm (I.E. using the same command in command line on the docker)
Here is the command command executed by phpstorm, and its the one i try in all situation to compare:
php /var/www/privateapi/vendor/bin/simple-phpunit --bootstrap /var/www/privateapi/tests/bootstrap.php --configuration /var/www/privateapi/phpunit.xml.dist --teamcity --cache-result-file=/va
r/www/privateapi/.phpunit.result.cache
In PhpStorm when I run tests that should communicate with database, it fails because it tries to use a MYSQL driver and I use PGSQL.
Summary:
Working cases:
- In commandline, on the docker, with or without DB Tests
- In commandline, outside the docker (i.e.
docker exec -it
... ), with or without DB Tests - With PHPStorm, with remote interpreter, without DB Tests
Failing case:
- With PHPStorm, with remote interpreter, with DB Tests
Here is my conf :
app/config/packages/test/doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL_TEST)%'
driver: 'pdo_pgsql'
mapping_types:
container_mode: string
network_provider: string
sensor_status: string
notification_channel: string
server_version: 11
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
app/phpunit.xml.dist
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php">
<php>
<ini name="error_reporting" value="-1" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />
<env name="APP_ENV" value="test" />
<env name="KERNEL_CLASS" value="App\Kernel" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<file>src/Kernel.php</file>
<file>src/Event/Listener/JsonToHtmlDevEventListener.php</file>
</exclude>
</whitelist>
</filter>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
</phpunit>
It works well with any code, but as soon as I want to test some use case with Database like this one :
app/tests/Security/Voter/OrganizationVoterTest.php
class OrganizationVoterTest extends KernelTestCase
{
private ?OrganizationVoter $voter;
private ?UserRepository $userRepository;
private ?OrganizationRepository $orgaRepository;
protected function setUp()
{
self::bootKernel();
$container = self::$container;
$this->voter = $container->get(OrganizationVoter::class);
$this->userRepository = $container->get('doctrine')->getRepository(User::class);
$this->orgaRepository = $container->get('doctrine')->getRepository(Organization::class);
parent::setUp();
}
public function testGetMinRequiredLevel()
{
$orga = $this->orgaRepository->findOneBy(['name' => 'orga1']);
[....]
}
}
I will get the following error :
Doctrine\DBAL\Exception\DriverException : An exception occurred in driver: could not find driver
/var/www/privateapi/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:106
/var/www/privateapi/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:166
/var/www/privateapi/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:154
/var/www/privateapi/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:28
/var/www/privateapi/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:362
/var/www/privateapi/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1443
/var/www/privateapi/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:890
/var/www/privateapi/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:718
/var/www/privateapi/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:193
/var/www/privateapi/tests/Security/Voter/OrganizationVoterTest.php:32