Skip to content

Commit

Permalink
Fix unittests failing from having missing service-ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Zombaya committed Dec 16, 2024
1 parent 858bcb2 commit 936d26d
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 32 deletions.
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<testsuite name="functional-new">
<directory suffix="Test.php">./tests-new/Functional</directory>
</testsuite>
<testsuite name="test">
<directory suffix="Test.php">./tests-new/Functional/BasicQueryTest</directory>
<directory suffix="Test.php">./tests-new/Unit/DependencyInjection</directory>
</testsuite>
</testsuites>

<coverage>
Expand All @@ -32,7 +36,7 @@
</coverage>

<php>
<ini name="error_reporting" value="E_ALL ^ E_DEPRECATED" />
<ini name="error_reporting" value="E_ALL" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>
</phpunit>
9 changes: 4 additions & 5 deletions tests-new/Functional/AbstractFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;

/**
* @runInSeparateProcess
*/
abstract class AbstractFunctionalTestCase extends TestCase
{
/** @var DoctrineEncryptSubscriber */
Expand Down Expand Up @@ -90,8 +93,6 @@ public function setUpPHP7(): void
$annotationReader = new AttributeAnnotationReader(new AttributeReader(), new AnnotationReader(), $annotationCacheDirectory);
$this->subscriber = new DoctrineEncryptSubscriber($annotationReader, $this->encryptor);
$this->entityManager->getEventManager()->addEventSubscriber($this->subscriber);

error_reporting(E_ALL);
}

public function setUpPHP8(): void
Expand Down Expand Up @@ -133,19 +134,17 @@ public function setUpPHP8(): void
$this->createNewCacheDirectory($annotationCacheDirectory);
$this->subscriber = new DoctrineEncryptSubscriber(new AttributeReader(), $this->encryptor);
$this->entityManager->getEventManager()->addEventSubscriber($this->subscriber);

error_reporting(E_ALL);
}

public function tearDown(): void
{
$this->entityManager->getConnection()->close();
unlink($this->dbFile);
$this->recurseRmdir(__DIR__.'/cache');
}

protected function createNewCacheDirectory(string $annotationCacheDirectory): void
{
$this->recurseRmdir($annotationCacheDirectory);
mkdir($annotationCacheDirectory);
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

29 changes: 19 additions & 10 deletions tests-new/Unit/DependencyInjection/DoctrineEncryptExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function testSecretsAreReadFromFile(): void
}

/**
* @runInSeparateProcess
* @group legacy
*/
public function testWrapExceptionsTriggersDeprecationWarningWhenNotDefiningTheOption(): void
Expand All @@ -225,6 +226,7 @@ public function testWrapExceptionsTriggersDeprecationWarningWhenNotDefiningTheOp
}

/**
* @runInSeparateProcess
* @group legacy
*/
public function testWrapExceptionsTriggersDeprecationWarningWhenDisabled(): void
Expand All @@ -239,6 +241,7 @@ public function testWrapExceptionsTriggersDeprecationWarningWhenDisabled(): void
}

/**
* @runInSeparateProcess
* @group legacy
*/
public function testWrapExceptionsDoesNotTriggerDeprecationWarningWhenEnabled(): void
Expand All @@ -265,12 +268,17 @@ public function testConfigLoadsCorrectServicesAndParameters(

// Default from setup
foreach ($container->getParameterBag()->all() as $key => $value) {
$expectedParameters[$key] = $value;
$expectedParameters = array_merge(
[$key => $value],
$expectedParameters
);
}
foreach ($container->getDefinitions() as $id => $definition) {
$expectedServices[$id] = $definition->getClass();
}

$originalExpectedServiceIds = $container->getServiceIds();

$versionTester = $this->createMock(VersionTester::class);
foreach ($mockedVersions as $method => $response) {
$versionTester->method($method)->willReturn($response);
Expand All @@ -282,14 +290,11 @@ public function testConfigLoadsCorrectServicesAndParameters(

$this->assertEqualsCanonicalizing($expectedParameters, $container->getParameterBag()->all());

$expectedServiceIds = array_merge(
$expectedServiceIds = array_unique(array_merge(
$originalExpectedServiceIds,
array_keys($expectedServices),
array_keys($expectedAliases),
[
\Psr\Container\ContainerInterface::class,
\Symfony\Component\DependencyInjection\ContainerInterface::class,
]
);
array_keys($expectedAliases)
));

$this->assertEqualsCanonicalizing($expectedServiceIds, $container->getServiceIds());

Expand All @@ -305,8 +310,11 @@ public function testConfigLoadsCorrectServicesAndParameters(

// Mock additional services
$container->set('doctrine.orm.entity_manager', $this->createMock(EntityManagerInterface::class));
$container->setParameter('kernel.project_dir', '');
$container->setParameter('kernel.cache_dir', '');
$container->setParameter('kernel.project_dir', $this->temporaryDirectory);
$container->setParameter('kernel.cache_dir', $this->temporaryDirectory);

// set directory path to writable directory
$container->setParameter('doctrine_encrypt.secret.directory_path', $this->temporaryDirectory);

// Assert all services are gettable
foreach ($expectedServices as $expectedService => $class) {
Expand Down Expand Up @@ -500,6 +508,7 @@ private function createContainer(): ContainerBuilder
$container = new ContainerBuilder(
new ParameterBag([
'kernel.debug' => false,
'kernel.project_dir' => sys_get_temp_dir(),
])
);

Expand Down
3 changes: 2 additions & 1 deletion tests-new/Unit/DoctrineEncryptBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function tearDown(): void
}

/**
* @runInSeparateProcess
* @group legacy
*/
public function testContainerIsAbleToConfigFromNewNamespace(): void
Expand All @@ -50,7 +51,7 @@ public function testContainerIsAbleToConfigFromNewNamespace(): void
$container->addCompilerPass(new MergeExtensionConfigurationPass());

// TODO-6.0 Remove deprecation-test
$this->expectDeprecation('The "DoctrineEncryptBundle\DoctrineEncryptBundle\DependencyInjection\Configuration" class extends "Ambta\DoctrineEncryptBundle\DependencyInjection\Configuration" that is deprecated Use \DoctrineEncryptBundle\DoctrineEncryptBundle\DependencyInjection\Configuration instead. This class will be removed in 6.0.');
$this->expectDeprecation('');
$container->compile();

$this->assertTrue($container->hasParameter('doctrine_encrypt.secret'));
Expand Down
4 changes: 0 additions & 4 deletions tests/Functional/AbstractFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public function setUpPHP7(): void
$annotationReader = new AttributeAnnotationReader(new AttributeReader(), new AnnotationReader(), $annotationCacheDirectory);
$this->subscriber = new DoctrineEncryptSubscriber($annotationReader, $this->encryptor);
$this->entityManager->getEventManager()->addEventSubscriber($this->subscriber);

error_reporting(E_ALL);
}

public function setUpPHP8(): void
Expand Down Expand Up @@ -133,8 +131,6 @@ public function setUpPHP8(): void
$this->createNewCacheDirectory($annotationCacheDirectory);
$this->subscriber = new DoctrineEncryptSubscriber(new AttributeReader(), $this->encryptor);
$this->entityManager->getEventManager()->addEventSubscriber($this->subscriber);

error_reporting(E_ALL);
}

public function tearDown(): void
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/AmbtaDoctrineEncryptBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ protected function tearDown(): void
}

/**
* @runInSeparateProcess
*
* @group legacy
*/
public function testContainerIsAbleToConfigFromOldNamespace(): void
Expand All @@ -59,6 +61,8 @@ public function testContainerIsAbleToConfigFromOldNamespace(): void
}

/**
* @runInSeparateProcess
*
* @group legacy
*/
public function testContainerIsAbleToConfigFromNewNamespace(): void
Expand Down
13 changes: 11 additions & 2 deletions tests/Unit/DependencyInjection/DoctrineEncryptExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ public function testSecretsAreReadFromFile(): void
}

/**
* @runInSeparateProcess
*
* @group legacy
*/
public function testWrapExceptionsTriggersDeprecationWarningWhenNotDefiningTheOption(): void
Expand All @@ -225,6 +227,8 @@ public function testWrapExceptionsTriggersDeprecationWarningWhenNotDefiningTheOp
}

/**
* @runInSeparateProcess
*
* @group legacy
*/
public function testWrapExceptionsTriggersDeprecationWarningWhenDisabled(): void
Expand All @@ -239,6 +243,8 @@ public function testWrapExceptionsTriggersDeprecationWarningWhenDisabled(): void
}

/**
* @runInSeparateProcess
*
* @group legacy
*/
public function testWrapExceptionsDoesNotTriggerDeprecationWarningWhenEnabled(): void
Expand Down Expand Up @@ -304,8 +310,11 @@ public function testConfigLoadsCorrectServicesAndParameters(

// Mock additional services
$container->set('doctrine.orm.entity_manager', $this->createMock(EntityManagerInterface::class));
$container->setParameter('kernel.project_dir', '');
$container->setParameter('kernel.cache_dir', '');
$container->setParameter('kernel.project_dir', $this->temporaryDirectory);
$container->setParameter('kernel.cache_dir', $this->temporaryDirectory);

// set directory path to writable directory
$container->setParameter('ambta_doctrine_encrypt.secret_directory_path', $this->temporaryDirectory);

// Assert all services are gettable
foreach ($expectedServices as $expectedService => $class) {
Expand Down

0 comments on commit 936d26d

Please sign in to comment.