Skip to content

Commit

Permalink
#4252 Failing test for cascading refresh to lazy loaded associations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacharias Luiten committed Jun 8, 2018
1 parent fae518a commit 08a1e79
Showing 1 changed file with 215 additions and 0 deletions.
215 changes: 215 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH4252Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Annotation as ORM;

/**
* @group GH-4252
*/
class GH4252Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp() : void
{
parent::setUp();

$this->schemaTool->createSchema(array(
$this->em->getClassMetadata(GH4252City::class),
$this->em->getClassMetadata(GH4252Resident::class),
$this->em->getClassMetadata(GH4252Address::class),
));
}

public function testIssue() : void
{
$city = new GH4252City([new GH4252Resident([new GH4252Address()])]);

$this->em->persist($city);
$this->em->flush();
$this->em->clear();

/** @var GH4252City $city */
$city = $this->em->find(GH4252City::class, $city->getId());
$city->setFlag(false);
/** @var GH4252Resident $resident */
$resident = $city->getResidents()->first();
$resident->setFlag(false);
/** @var GH4252Address $address */
$address = $resident->getAddresses()->first();
$address->setFlag(false);

$this->em->refresh($city);

$resident = $city->getResidents()->first();
$address = $resident->getAddresses()->first();

$this->assertTrue($city->getFlag());
$this->assertTrue($resident->getFlag());
$this->assertTrue($address->getFlag());
}
}

/**
* @ORM\Entity
*/
class GH4252City
{
/**
* @var int
* @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
*/
private $id;

/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $flag;

/**
* @var GH4252Resident[]|Collection
*
* @ORM\OneToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252Resident", mappedBy="city", cascade={"persist","refresh"})
*/
private $residents;

public function __construct(array $residents)
{
$this->residents = new ArrayCollection();
foreach ($residents as $resident) {
$this->residents->add($resident);
$resident->setCity($this);
}
$this->flag = true;
}

public function getId() : int
{
return $this->id;
}

public function getFlag() : bool
{
return $this->flag;
}

public function setFlag(bool $flag) : void
{
$this->flag = $flag;
}

public function getResidents() : Collection
{
return $this->residents;
}
}

/**
* @ORM\Entity
*/
class GH4252Resident
{
/**
* @var int
* @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
*/
private $id;

/**
* @var GH4252City
* @ORM\ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252City", inversedBy="residents")
*/
private $city;

/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $flag;

/**
* @var GH4252Address[]|Collection
*
* @ORM\ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252Address", fetch="EXTRA_LAZY", cascade={"persist","refresh"})
*/
private $addresses;

public function __construct(array $addresses)
{
$this->addresses = new ArrayCollection();
foreach ($addresses as $address) {
$this->addresses->add($address);
}
$this->flag = true;
}

public function getId() : int
{
return $this->id;
}

public function getCity() : GH4252City
{
return $this->city;
}

public function setCity(GH4252City $city) : void
{
$this->city = $city;
}

public function getFlag() : bool
{
return $this->flag;
}

public function setFlag(bool $flag) : void
{
$this->flag = $flag;
}

public function getAddresses() : Collection
{
return $this->addresses;
}
}

/** @ORM\Entity */
class GH4252Address
{
/**
* @var int
* @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
*/
private $id;

/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $flag;

public function __construct()
{
$this->flag = true;
}

public function getId() : int
{
return $this->id;
}

public function getFlag() : bool
{
return $this->flag;
}

public function setFlag(bool $flag) : void
{
$this->flag = $flag;
}
}

0 comments on commit 08a1e79

Please sign in to comment.