Skip to content

Commit

Permalink
Remove hack to access class scope inside closures
Browse files Browse the repository at this point in the history
This is possible since 5.4.
  • Loading branch information
carusogabriel committed Jul 21, 2019
1 parent d606941 commit 79b038a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
5 changes: 2 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ protected function setUp() : void

public function testIssue() : void
{
$test = $this;
$user = new CmsUser();
$uow = $this->em->getUnitOfWork();

Expand All @@ -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(function () use ($uow) {
self::assertAttributeEmpty('extraUpdates', $uow, 'ExtraUpdates are reset before postFlush');
}));

$this->em->getEventManager()->addEventListener(Events::postFlush, $listener);
Expand Down
12 changes: 4 additions & 8 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,19 @@ class DDC3644User

public function setAddresses(Collection $addresses)
{
$self = $this;

$this->addresses = $addresses;

$addresses->map(static function ($address) use ($self) {
$address->user = $self;
$addresses->map(function ($address) {
$address->user = $this;
});
}

public function setPets(Collection $pets)
{
$self = $this;

$this->pets = $pets;

$pets->map(static function ($pet) use ($self) {
$pet->owner = $self;
$pets->map(function ($pet) {
$pet->owner = $this;
});
}
}
Expand Down
10 changes: 4 additions & 6 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ public function testQuoteMetadata() : void
*/
public function testFallbackLoadingCausesEventTriggeringThatCanModifyFetchedMetadata() : void
{
$test = $this;

/** @var ClassMetadata $metadata */
$metadata = $this->createMock(ClassMetadata::class);
$cmf = new ClassMetadataFactory();
Expand All @@ -351,10 +349,10 @@ public function testFallbackLoadingCausesEventTriggeringThatCanModifyFetchedMeta
$listener
->expects($this->any())
->method('onClassMetadataNotFound')
->will($this->returnCallback(static function (OnClassMetadataNotFoundEventArgs $args) use ($metadata, $em, $test) {
$test->assertNull($args->getFoundMetadata());
$test->assertSame('Foo', $args->getClassName());
$test->assertSame($em, $args->getObjectManager());
->will($this->returnCallback(function (OnClassMetadataNotFoundEventArgs $args) use ($metadata, $em) {
self::assertNull($args->getFoundMetadata());
self::assertSame('Foo', $args->getClassName());
self::assertSame($em, $args->getObjectManager());

$args->setFoundMetadata($metadata);
}));
Expand Down

0 comments on commit 79b038a

Please sign in to comment.