Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control proxy implementation via env #10282

Merged
merged 1 commit into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ jobs:
run: "composer require doctrine/dbal ^${{ matrix.dbal-version }} --no-update"
if: "${{ matrix.dbal-version != 'default' }}"

- name: "Require specific lazy-proxy implementation"
run: "composer require symfony/var-exporter ^6.2 doctrine/persistence ^3.1 --no-update"
if: "${{ matrix.proxy == 'lazy-ghost' }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
with:
Expand All @@ -91,11 +87,13 @@ jobs:
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage-no-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 0
ORM_PROXY_IMPLEMENTATION: "${{ matrix.proxy }}"

- name: "Run PHPUnit with Second Level Cache"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --exclude-group performance,non-cacheable,locking_functional --coverage-clover=coverage-cache.xml"
env:
ENABLE_SECOND_LEVEL_CACHE: 1
ORM_PROXY_IMPLEMENTATION: "${{ matrix.proxy }}"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v3"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
if: "${{ matrix.dbal-version != 'default' }}"

- name: "Require specific persistence version"
run: "composer require symfony/var-exporter ^6.2 doctrine/persistence ^$([ ${{ matrix.persistence-version }} = default ] && echo '3.1' || echo ${{ matrix.persistence-version }}) --no-update"
run: "composer require doctrine/persistence ^$([ ${{ matrix.persistence-version }} = default ] && echo '3.1' || echo ${{ matrix.persistence-version }}) --no-update"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
php-version: "${{ matrix.php-version }}"

- name: "Require specific persistence version"
run: "composer require symfony/var-exporter ^6.2 doctrine/persistence ^3.1 --no-update"
run: "composer require doctrine/persistence ^3.1 --no-update"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.1",
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
"symfony/var-exporter": "^4.4 || ^5.4 || ^6.2",
"symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"vimeo/psalm": "4.30.0 || 5.1.0"
},
Expand Down
13 changes: 3 additions & 10 deletions tests/Doctrine/Performance/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\Mocks\DriverResultMock;
use Symfony\Component\VarExporter\LazyGhostTrait;
use Doctrine\Tests\TestUtil;

use function array_map;
use function class_exists;
use function realpath;
use function trait_exists;

final class EntityManagerFactory
{
public static function getEntityManager(array $schemaClassNames): EntityManagerInterface
{
$config = new Configuration();

$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
$config->setProxyDir(__DIR__ . '/../Tests/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
TestUtil::configureProxies($config);
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL);
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver([
realpath(__DIR__ . '/Models/Cache'),
Expand All @@ -58,9 +53,7 @@ public static function makeEntityManagerWithNoResultsConnection(): EntityManager
{
$config = new Configuration();

$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
$config->setProxyDir(__DIR__ . '/../Tests/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
TestUtil::configureProxies($config);
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL);
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver([
realpath(__DIR__ . '/Models/Cache'),
Expand Down
9 changes: 2 additions & 7 deletions tests/Doctrine/Tests/Mocks/EntityManagerMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Symfony\Component\VarExporter\LazyGhostTrait;
use Doctrine\Tests\TestUtil;

use function class_exists;
use function sprintf;
use function trait_exists;

/**
* Special EntityManager mock used for testing purposes.
Expand All @@ -34,9 +31,7 @@ public function __construct(Connection $conn, ?Configuration $config = null, ?Ev
{
if ($config === null) {
$config = new Configuration();
$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
$config->setProxyDir(__DIR__ . '/../Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
TestUtil::configureProxies($config);
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMSetup;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\TestUtil;
use GearmanWorker;
use InvalidArgumentException;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\VarExporter\LazyGhostTrait;

use function assert;
use function class_exists;
use function is_array;
use function microtime;
use function sleep;
use function trait_exists;
use function unserialize;

class LockAgentWorker
Expand Down Expand Up @@ -117,9 +114,7 @@ protected function processWorkload($job): array
protected function createEntityManager(Connection $conn): EntityManagerInterface
{
$config = new Configuration();
$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
$config->setProxyDir(__DIR__ . '/../../../Proxies');
$config->setProxyNamespace('MyProject\Proxies');
TestUtil::configureProxies($config);
$config->setAutoGenerateProxyClasses(true);

$annotDriver = ORMSetup::createDefaultAnnotationDriver([__DIR__ . '/../../../Models/']);
Expand Down
9 changes: 2 additions & 7 deletions tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\Proxy;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\DbalExtensions\Connection;
use Doctrine\Tests\DbalExtensions\QueryLog;
use Doctrine\Tests\Models\Generic\DateTimeModel;
use Doctrine\Tests\OrmFunctionalTestCase;
use Symfony\Component\VarExporter\LazyGhostTrait;
use Doctrine\Tests\TestUtil;

use function assert;
use function class_exists;
use function realpath;
use function serialize;
use function trait_exists;
use function unserialize;

class MergeProxiesTest extends OrmFunctionalTestCase
Expand Down Expand Up @@ -243,9 +240,7 @@ private function createEntityManager(): EntityManagerInterface
{
$config = new Configuration();

$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
$config->setProxyDir(realpath(__DIR__ . '/../../Proxies'));
$config->setProxyNamespace('Doctrine\Tests\Proxies');
TestUtil::configureProxies($config);
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver(
[realpath(__DIR__ . '/../../Models/Cache')]
));
Expand Down
8 changes: 2 additions & 6 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\Mocks\MetadataDriverMock;
use Doctrine\Tests\Models\CMS\CmsArticle;
Expand All @@ -41,18 +40,17 @@
use Doctrine\Tests\Models\Quote;
use Doctrine\Tests\OrmTestCase;
use Doctrine\Tests\PHPUnitCompatibility\MockBuilderCompatibilityTools;
use Doctrine\Tests\TestUtil;
use Exception;
use InvalidArgumentException;
use PHPUnit\Framework\Assert;
use ReflectionClass;
use Symfony\Component\VarExporter\LazyGhostTrait;

use function array_search;
use function assert;
use function class_exists;
use function count;
use function sprintf;
use function trait_exists;

class ClassMetadataFactoryTest extends OrmTestCase
{
Expand Down Expand Up @@ -286,9 +284,7 @@ public function testGetAllMetadataWorksWithBadConnection(): void
protected function createEntityManager(MappingDriver $metadataDriver, $conn = null): EntityManagerMock
{
$config = new Configuration();
$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
$config->setProxyDir(__DIR__ . '/../../Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
TestUtil::configureProxies($config);
$eventManager = new EventManager();
if (! $conn) {
$platform = $this->createMock(AbstractPlatform::class);
Expand Down
8 changes: 2 additions & 6 deletions tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\OrmTestCase;
use Symfony\Component\VarExporter\LazyGhostTrait;
use Doctrine\Tests\TestUtil;

use function class_exists;
use function count;
use function file_exists;
use function rmdir;
use function trait_exists;
use function unlink;

/**
Expand All @@ -45,9 +43,7 @@ protected function createEntityManager(MappingDriver $metadataDriver): EntityMan
->willReturn(new EventManager());

$config = new Configuration();
$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
$config->setProxyDir(__DIR__ . '/../../Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
TestUtil::configureProxies($config);
$config->setMetadataDriverImpl($metadataDriver);

return new EntityManagerMock($connection, $config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\Driver\PHPDriver;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\OrmTestCase;
use Symfony\Component\VarExporter\LazyGhostTrait;
use Doctrine\Tests\TestUtil;
use Symfony\Component\Yaml\Parser;

use function class_exists;
use function count;
use function current;
use function file_get_contents;
Expand All @@ -38,7 +36,6 @@
use function rtrim;
use function simplexml_load_file;
use function str_replace;
use function trait_exists;
use function unlink;

/**
Expand Down Expand Up @@ -66,9 +63,7 @@ protected function createEntityManager($metadataDriver): EntityManagerMock
->willReturn(new EventManager());

$config = new Configuration();
$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
$config->setProxyDir(__DIR__ . '/../../Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
TestUtil::configureProxies($config);
$config->setMetadataDriverImpl($metadataDriver);

return new EntityManagerMock($connection, $config);
Expand Down
8 changes: 1 addition & 7 deletions tests/Doctrine/Tests/OrmFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Tools\ToolsException;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\DbalExtensions\QueryLog;
use Doctrine\Tests\DbalTypes\Rot13Type;
use Doctrine\Tests\EventListener\CacheMetadataListener;
Expand All @@ -37,15 +36,13 @@
use Psr\Cache\CacheItemPoolInterface;
use RuntimeException;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\VarExporter\LazyGhostTrait;
use Throwable;

use function array_map;
use function array_pop;
use function array_reverse;
use function array_slice;
use function assert;
use function class_exists;
use function explode;
use function get_debug_type;
use function getenv;
Expand All @@ -56,7 +53,6 @@
use function sprintf;
use function str_contains;
use function strtolower;
use function trait_exists;
use function var_export;

use const PHP_EOL;
Expand Down Expand Up @@ -768,11 +764,9 @@ protected function getEntityManager(
//FIXME: two different configs! $conn and the created entity manager have
// different configs.
$config = new Configuration();
$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
TestUtil::configureProxies($config);
$config->setMetadataCache(self::$metadataCache);
$config->setQueryCache(self::$queryCache);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');

if ($this->resultCache !== null) {
$config->setResultCache($this->resultCache);
Expand Down
8 changes: 1 addition & 7 deletions tests/Doctrine/Tests/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
use Doctrine\ORM\Configuration;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\ORMSetup;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\VarExporter\LazyGhostTrait;

use function class_exists;
use function realpath;
use function trait_exists;

/**
* Base testcase class for all ORM testcases.
Expand Down Expand Up @@ -80,11 +76,9 @@ protected function getTestEntityManager(?Connection $connection = null): EntityM

$config = new Configuration();

$config->setLazyGhostObjectEnabled(trait_exists(LazyGhostTrait::class) && class_exists(RuntimeReflectionProperty::class));
TestUtil::configureProxies($config);
$config->setMetadataCache($metadataCache);
$config->setQueryCache(self::getSharedQueryCache());
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver([
realpath(__DIR__ . '/Models/Cache'),
]));
Expand Down
Loading