From d2fbd382edea717b5ea21208e45f9303d9753ebc Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sun, 21 Jul 2019 20:53:00 +0200 Subject: [PATCH] Add deprecated assertions in our own suite of tests for now --- .../ORM/Functional/Ticket/DDC3123Test.php | 5 ++--- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 2 +- tests/Doctrine/Tests/OrmTestCase.php | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php index ba8b3c6a27a..3d956ebeef5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php @@ -22,7 +22,6 @@ protected function setUp() : void public function testIssue() : void { - $test = $this; $user = new CmsUser(); $uow = $this->em->getUnitOfWork(); @@ -39,8 +38,8 @@ public function testIssue() : void $listener ->expects($this->once()) ->method(Events::postFlush) - ->will($this->returnCallback(static function () use ($uow, $test) { - $test->assertAttributeEmpty('extraUpdates', $uow, 'ExtraUpdates are reset before postFlush'); + ->will($this->returnCallback(static function () use ($uow) { + self::assertAttributeEmpty('extraUpdates', $uow, 'ExtraUpdates are reset before postFlush'); })); $this->em->getEventManager()->addEventListener(Events::postFlush, $listener); diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index e67dd3c8e5e..c42f08b5fb0 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -401,7 +401,7 @@ public function testResultCacheProfileCanBeRemovedViaSetter() : void $query->useResultCache(true); $query->setResultCacheProfile(); - self::assertAttributeSame(null, 'queryCacheProfile', $query); + self::assertAttributeEmpty('queryCacheProfile', $query); } /** @group 7527 */ diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index c14970df61d..41c074da945 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -19,6 +19,7 @@ use Doctrine\ORM\Proxy\Factory\ProxyFactory; use function is_array; use function realpath; +use ReflectionClass; /** * Base testcase class for all ORM testcases. @@ -171,4 +172,22 @@ protected function getSharedSecondLevelCacheDriverImpl() return $this->secondLevelCacheDriverImpl; } + + public static function assertAttributeEmpty(string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void + { + $class = new ReflectionClass($haystackClassOrObject); + $property = $class->getProperty($haystackAttributeName); + $property->setAccessible(true); + + self::assertEmpty($property->getValue($haystackClassOrObject)); + } + + public static function assertAttributeSame($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void + { + $class = new ReflectionClass($actualClassOrObject); + $property = $class->getProperty($actualAttributeName); + $property->setAccessible(true); + + self::assertSame($expected, $property->getValue($actualClassOrObject)); + } }