Skip to content

Commit

Permalink
IBX-1809: Allowed override of test Kernel via environment (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p authored Dec 29, 2021
1 parent 6e30685 commit fdcb00d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion phpunit-integration-legacy-solr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<env name="CORES_SETUP" value="dedicated" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
<ini name="error_reporting" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
<env name="KERNEL_CLASS" value="Ibexa\Contracts\Core\Test\IbexaTestKernel"/>
</php>
<testsuites>
<testsuite name="eZ\Publish\API\Repository">
Expand Down
1 change: 1 addition & 0 deletions phpunit-integration-legacy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
<ini name="error_reporting" value="-1" />
<env name="DATABASE_URL" value="sqlite://:memory:" />
<env name="KERNEL_CLASS" value="Ibexa\Contracts\Core\Test\IbexaTestKernel"/>
</php>
<testsuites>
<testsuite name="eZ\Publish\API\Repository">
Expand Down
21 changes: 20 additions & 1 deletion src/contracts/Test/IbexaKernelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
use eZ\Publish\API\Repository\SectionService;
use eZ\Publish\API\Repository\Tests\LegacySchemaImporter;
use eZ\Publish\API\Repository\UserService;
use eZ\Publish\Core\Repository\Values\User\UserReference;
use eZ\Publish\SPI\Persistence\TransactionHandler;
use eZ\Publish\SPI\Tests\Persistence\FixtureImporter;
use eZ\Publish\SPI\Tests\Persistence\YamlFixture;
use LogicException;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

Expand All @@ -31,9 +33,16 @@
*/
abstract class IbexaKernelTestCase extends KernelTestCase
{
private const FIXTURE_USER_ADMIN_ID = 14;
private const FIXTURE_USER_ANONYMOUS_ID = 10;

protected static function getKernelClass(): string
{
return IbexaTestKernel::class;
try {
return parent::getKernelClass();
} catch (LogicException $e) {
return IbexaTestKernel::class;
}
}

final protected static function loadSchema(): void
Expand Down Expand Up @@ -170,4 +179,14 @@ protected static function getSectionService(): SectionService
{
return self::getServiceByClassName(SectionService::class);
}

protected static function setAnonymousUser(): void
{
self::getPermissionResolver()->setCurrentUserReference(new UserReference(self::FIXTURE_USER_ANONYMOUS_ID));
}

protected static function setAdministratorUser(): void
{
self::getPermissionResolver()->setCurrentUserReference(new UserReference(self::FIXTURE_USER_ADMIN_ID));
}
}

0 comments on commit fdcb00d

Please sign in to comment.