Skip to content

Commit

Permalink
test: test new & legacy proxy (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi authored Sep 21, 2024
1 parent b4ff491 commit 1113909
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.4.0

* test: use full Symfony framework-bundle for testing
* test: test new & legacy proxy

## 1.3.2

Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
],
"require": {
"doctrine/orm": "^2.16 || ^3.0",
"doctrine/persistence": "^3.1",
"rekalogika/direct-property-access": "^1.1.2 || ^1.2",
"symfony/config": "^6.0 || ^7.0",
"symfony/dependency-injection": "^6.0 || ^7.0",
"symfony/http-kernel": "^6.0 || ^7.0"
},
"require-dev": {
"doctrine/collections": "^2.2",
"doctrine/doctrine-bundle": "^2.13",
"doctrine/doctrine-fixtures-bundle": "^3.6",
"doctrine/doctrine-bundle": "^2.0",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^10.5",
"psalm/plugin-phpunit": "^0.19.0",
Expand Down
14 changes: 7 additions & 7 deletions tests/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ doctrine:
use_savepoints: true

orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
controller_resolver:
auto_mapping: false
# auto_generate_proxy_classes: true
# naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
# auto_mapping: true
# enable_lazy_ghost_objects: true
# report_fields_where_declared: true
# controller_resolver:
# auto_mapping: false
mappings:
Entity:
is_bundle: false
Expand Down
34 changes: 21 additions & 13 deletions tests/src/Tests/DoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ public function testProxy(): void
$this->assertInstanceOf(Proxy::class, $post);
$this->assertFalse($post->__isInitialized());

// should be true. see https://github.com/doctrine/orm/pull/11606
// remove this when upstream fixes the problem
$post->getImage();
$this->assertFalse($post->__isInitialized());
if (!\property_exists($post, '__initializer__')) {
// lazy ghost proxy.
// should be true. see https://github.com/doctrine/orm/pull/11606
// remove this when upstream fixes the problem
$post->getImage();
$this->assertFalse($post->__isInitialized());

$post->getTitle();
$this->assertTrue($post->__isInitialized());
$post->getTitle();
$this->assertTrue($post->__isInitialized());
}

$this->assertEquals('someImage', $post->getImage());
}
Expand All @@ -117,6 +120,8 @@ public function testUninitializedProxyFlush(): void
$this->assertInstanceOf(Post::class, $post);
$this->assertInstanceOf(Proxy::class, $post);
$this->assertFalse($post->__isInitialized());

// this flush should not remove the image
$this->entityManager->flush();

// clear
Expand All @@ -127,16 +132,19 @@ public function testUninitializedProxyFlush(): void
$this->assertInstanceOf(Post::class, $post);
$this->assertInstanceOf(Proxy::class, $post);
$this->assertFalse($post->__isInitialized());
$this->entityManager->flush();

// should be true. see https://github.com/doctrine/orm/pull/11606
// remove this when upstream fixes the problem
$post->getImage();
$this->assertFalse($post->__isInitialized());
if (!\property_exists($post, '__initializer__')) {
// lazy ghost proxy.
// should be true. see https://github.com/doctrine/orm/pull/11606
// remove this when upstream fixes the problem
$post->getImage();
$this->assertFalse($post->__isInitialized());

$post->getTitle();
$this->assertTrue($post->__isInitialized());
$post->getTitle();
$this->assertTrue($post->__isInitialized());
}

// make sure the flush did not remove the image
$this->assertEquals('someImage', $post->getImage());
}
}

0 comments on commit 1113909

Please sign in to comment.