X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FId%2FAssignedGeneratorTest.php;fp=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FId%2FAssignedGeneratorTest.php;h=3a009e5eab968b4d28d54c18799089278c2c1b43;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fapplication_blanche.git diff --git a/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php new file mode 100644 index 0000000..3a009e5 --- /dev/null +++ b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php @@ -0,0 +1,67 @@ +_em = $this->_getTestEntityManager(); + $this->_assignedGen = new AssignedGenerator; + } + + public function testThrowsExceptionIfIdNotAssigned() + { + try { + $entity = new AssignedSingleIdEntity; + $this->_assignedGen->generate($this->_em, $entity); + $this->fail('Assigned generator did not throw exception even though ID was missing.'); + } catch (\Doctrine\ORM\ORMException $expected) {} + + try { + $entity = new AssignedCompositeIdEntity; + $this->_assignedGen->generate($this->_em, $entity); + $this->fail('Assigned generator did not throw exception even though ID was missing.'); + } catch (\Doctrine\ORM\ORMException $expected) {} + } + + public function testCorrectIdGeneration() + { + $entity = new AssignedSingleIdEntity; + $entity->myId = 1; + $id = $this->_assignedGen->generate($this->_em, $entity); + $this->assertEquals(array('myId' => 1), $id); + + $entity = new AssignedCompositeIdEntity; + $entity->myId2 = 2; + $entity->myId1 = 4; + $id = $this->_assignedGen->generate($this->_em, $entity); + $this->assertEquals(array('myId1' => 4, 'myId2' => 2), $id); + } +} + +/** @Entity */ +class AssignedSingleIdEntity { + /** @Id @Column(type="integer") */ + public $myId; +} + +/** @Entity */ +class AssignedCompositeIdEntity { + /** @Id @Column(type="integer") */ + public $myId1; + /** @Id @Column(type="integer") */ + public $myId2; +}