Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
10bc51fd
Commit
10bc51fd
authored
Nov 06, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-116] Fixed.
parent
7220cb2e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
9 deletions
+76
-9
Assigned.php
lib/Doctrine/ORM/Id/Assigned.php
+8
-9
AllTests.php
tests/Doctrine/Tests/ORM/Id/AllTests.php
+1
-0
AssignedIdTest.php
tests/Doctrine/Tests/ORM/Id/AssignedIdTest.php
+67
-0
No files found.
lib/Doctrine/ORM/Id/Assigned.php
View file @
10bc51fd
...
...
@@ -29,6 +29,7 @@ use Doctrine\ORM\ORMException;
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
* @todo Rename: AssignedGenerator?
*/
class
Assigned
extends
AbstractIdGenerator
{
...
...
@@ -42,28 +43,26 @@ class Assigned extends AbstractIdGenerator
public
function
generate
(
EntityManager
$em
,
$entity
)
{
$class
=
$em
->
getClassMetadata
(
get_class
(
$entity
));
$identifier
=
null
;
if
(
$class
->
isIdentifierComposite
())
{
$identifier
=
array
();
$identifier
=
array
();
if
(
$class
->
isIdentifierComposite
)
{
$idFields
=
$class
->
getIdentifierFieldNames
();
foreach
(
$idFields
as
$idField
)
{
$identifier
[]
=
$value
=
$class
->
getReflectionProperty
(
$idField
)
->
getValue
(
$entity
);
if
(
isset
(
$value
))
{
$identifier
[]
=
$value
;
}
else
{
throw
ORMException
::
entityMissingAssignedId
(
$entity
);
}
}
}
else
{
$value
=
$class
->
getReflectionProperty
(
$class
->
getSingleIdentifierFieldName
())
->
getValue
(
$entity
);
if
(
isset
(
$value
))
{
$identifier
=
array
(
$value
);
$identifier
[]
=
$value
;
}
else
{
throw
ORMException
::
entityMissingAssignedId
(
$entity
);
}
}
if
(
!
$identifier
)
{
throw
ORMException
::
entityMissingAssignedId
(
$entity
);
}
return
$identifier
;
}
...
...
tests/Doctrine/Tests/ORM/Id/AllTests.php
View file @
10bc51fd
...
...
@@ -20,6 +20,7 @@ class AllTests
$suite
=
new
\Doctrine\Tests\DoctrineTestSuite
(
'Doctrine Orm Id'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Id\SequenceGeneratorTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Id\AssignedIdTest'
);
return
$suite
;
}
...
...
tests/Doctrine/Tests/ORM/Id/AssignedIdTest.php
0 → 100644
View file @
10bc51fd
<?php
namespace
Doctrine\Tests\ORM\Id
;
use
Doctrine\ORM\Id\Assigned
;
require_once
__DIR__
.
'/../../TestInit.php'
;
/**
* AssignedIdTest
*
* @author robo
*/
class
AssignedIdTest
extends
\Doctrine\Tests\OrmTestCase
{
private
$_em
;
private
$_assignedGen
;
protected
function
setUp
()
{
$this
->
_em
=
$this
->
_getTestEntityManager
();
$this
->
_assignedGen
=
new
Assigned
;
}
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
(
1
),
$id
);
$entity
=
new
AssignedCompositeIdEntity
;
$entity
->
myId2
=
2
;
$entity
->
myId1
=
4
;
$id
=
$this
->
_assignedGen
->
generate
(
$this
->
_em
,
$entity
);
$this
->
assertEquals
(
array
(
4
,
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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment