Skip to content

Commit

Permalink
Codeception#5663: build failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Basster committed Sep 12, 2019
1 parent 96d4d3e commit 0555350
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/data/doctrine2_entities/CircularRelations/A.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace CircularRelations;

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

/**
* @ORM\Entity
* @ORM\Table(name="circular_a")
*/
class A
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;

/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\OneToMany(targetEntity="C", mappedBy="a")
*/
private $cs;

public function __construct()
{
$this->cs = new ArrayCollection();
}

/**
* @return int|null
*/
public function getId()
{
return $this->id;
}

/**
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getCs()
{
return $this->cs;
}
}
48 changes: 48 additions & 0 deletions tests/data/doctrine2_entities/CircularRelations/B.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace CircularRelations;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="circular_b")
*/
class B
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;

/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @ORM\OneToMany(targetEntity="C", mappedBy="b")
*/
private $cs;

public function __construct()
{
$this->cs = new ArrayCollection();
}

/**
* @return int|null
*/
public function getId()
{
return $this->id;
}

/**
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getCs()
{
return $this->cs;
}
}
38 changes: 38 additions & 0 deletions tests/data/doctrine2_entities/CircularRelations/C.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace CircularRelations;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="circular_c")
*/
class C
{
/**
* @var \CircularRelations\A
* @ORM\Id
* @ORM\ManyToOne(targetEntity="A", inversedBy="cs", cascade={"persist"})
*/
private $a;

/**
* @var \CircularRelations\B
* @ORM\Id
* @ORM\ManyToOne(targetEntity="B", inversedBy="cs", cascade={"persist"})
*/
private $b;

/**
* C constructor.
*
* @param \CircularRelations\A $a
* @param \CircularRelations\B $b
*/
public function __construct(\CircularRelations\A $a, \CircularRelations\B $b)
{
$this->a = $a;
$this->b = $b;
}
}
17 changes: 17 additions & 0 deletions tests/unit/Codeception/Module/Doctrine2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ protected function _setUp()
require_once $dir . "/MultilevelRelations/A.php";
require_once $dir . "/MultilevelRelations/B.php";
require_once $dir . "/MultilevelRelations/C.php";
require_once $dir . "/CircularRelations/A.php";
require_once $dir . "/CircularRelations/B.php";
require_once $dir . "/CircularRelations/C.php";

$this->em = EntityManager::create(
['url' => 'sqlite:///:memory:'],
Expand All @@ -71,6 +74,9 @@ protected function _setUp()
$this->em->getClassMetadata(\MultilevelRelations\A::class),
$this->em->getClassMetadata(\MultilevelRelations\B::class),
$this->em->getClassMetadata(\MultilevelRelations\C::class),
$this->em->getClassMetadata(\CircularRelations\A::class),
$this->em->getClassMetadata(\CircularRelations\B::class),
$this->em->getClassMetadata(\CircularRelations\C::class),
]);

$this->module = new Doctrine2(make_container(), [
Expand Down Expand Up @@ -375,6 +381,17 @@ public function testCompositePrimaryKey()
$this->assertEquals([123, 'abc'], $res);
}

public function testCompositePrimaryKeyWithEntities()
{
$a = new \CircularRelations\A();
$b = new \CircularRelations\B();
$c = new \CircularRelations\C($a, $b);

$pks = $this->module->haveInRepository($c);

$this->assertEquals([$a, $b], $pks);
}

public function testRefresh()
{
// We have an entity:
Expand Down

0 comments on commit 0555350

Please sign in to comment.