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
43ecaf54
Commit
43ecaf54
authored
Feb 25, 2010
by
beberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] DDC-374 - Implement and tested DriverChain Mapping Adapter
parent
fcd623e8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
1 deletion
+104
-1
DriverChain.php
lib/Doctrine/ORM/Mapping/Driver/DriverChain.php
+13
-1
DriverChainTest.php
tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php
+91
-0
No files found.
lib/Doctrine/ORM/Mapping/Driver/DriverChain.php
View file @
43ecaf54
...
...
@@ -22,7 +22,8 @@
namespace
Doctrine\ORM\Mapping\Driver
;
use
Doctrine\ORM\Mapping\Driver\Driver
,
Doctrine\ORM\Mapping\ClassMetadataInfo
;
Doctrine\ORM\Mapping\ClassMetadataInfo
,
Doctrine\ORM\Mapping\MappingException
;
/**
* The DriverChain allows you to add multiple other mapping drivers for
...
...
@@ -44,6 +45,12 @@ class DriverChain implements Driver
*/
private
$_drivers
=
array
();
/**
* Add a nested driver
*
* @param Driver $nestedDriver
* @param string $namespace
*/
public
function
addDriver
(
Driver
$nestedDriver
,
$namespace
)
{
$this
->
_drivers
[
$namespace
]
=
$nestedDriver
;
...
...
@@ -60,8 +67,11 @@ class DriverChain implements Driver
foreach
(
$this
->
_drivers
AS
$namespace
=>
$driver
)
{
if
(
strpos
(
$className
,
$namespace
)
===
0
)
{
$driver
->
loadMetadataForClass
(
$className
,
$metadata
);
return
;
}
}
throw
MappingException
::
classIsNotAValidEntityOrMappedSuperClass
(
$className
);
}
/**
...
...
@@ -93,5 +103,7 @@ class DriverChain implements Driver
return
$driver
->
isTransient
(
$className
);
}
}
throw
MappingException
::
classIsNotAValidEntityOrMappedSuperClass
(
$className
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php
0 → 100644
View file @
43ecaf54
<?php
namespace
Doctrine\Tests\ORM\Mapping
;
use
Doctrine\ORM\Mapping\Driver\Driver
;
use
Doctrine\ORM\Mapping\Driver\DriverChain
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
DriverChainTest
extends
\Doctrine\Tests\OrmTestCase
{
public
function
testDelegateToMatchingNamespaceDriver
()
{
$className
=
'Doctrine\Tests\ORM\Mapping\DriverChainEntity'
;
$classMetadata
=
new
\Doctrine\ORM\Mapping\ClassMetadata
(
$className
);
$chain
=
new
DriverChain
();
$driver1
=
$this
->
getMock
(
'Doctrine\ORM\Mapping\Driver\Driver'
);
$driver1
->
expects
(
$this
->
never
())
->
method
(
'loadMetadataForClass'
);
$driver1
->
expectS
(
$this
->
never
())
->
method
(
'isTransient'
);
$driver2
=
$this
->
getMock
(
'Doctrine\ORM\Mapping\Driver\Driver'
);
$driver2
->
expects
(
$this
->
at
(
0
))
->
method
(
'loadMetadataForClass'
)
->
with
(
$this
->
equalTo
(
$className
),
$this
->
equalTo
(
$classMetadata
));
$driver2
->
expects
(
$this
->
at
(
1
))
->
method
(
'isTransient'
)
->
with
(
$this
->
equalTo
(
$className
))
->
will
(
$this
->
returnValue
(
true
));
$chain
->
addDriver
(
$driver1
,
'Doctrine\Tests\Models\Company'
);
$chain
->
addDriver
(
$driver2
,
'Doctrine\Tests\ORM\Mapping'
);
$chain
->
loadMetadataForClass
(
$className
,
$classMetadata
);
$this
->
assertTrue
(
$chain
->
isTransient
(
$className
)
);
}
public
function
testLoadMetadata_NoDelegatorFound_ThrowsMappingException
()
{
$className
=
'Doctrine\Tests\ORM\Mapping\DriverChainEntity'
;
$classMetadata
=
new
\Doctrine\ORM\Mapping\ClassMetadata
(
$className
);
$chain
=
new
DriverChain
();
$this
->
setExpectedException
(
'Doctrine\ORM\Mapping\MappingException'
);
$chain
->
loadMetadataForClass
(
$className
,
$classMetadata
);
}
public
function
testIsTransient_NoDelegatorFound_ThrowsMappingException
()
{
$className
=
'Doctrine\Tests\ORM\Mapping\DriverChainEntity'
;
$classMetadata
=
new
\Doctrine\ORM\Mapping\ClassMetadata
(
$className
);
$chain
=
new
DriverChain
();
$this
->
setExpectedException
(
'Doctrine\ORM\Mapping\MappingException'
);
$chain
->
isTransient
(
$className
);
}
public
function
testGatherAllClassNames
()
{
$className
=
'Doctrine\Tests\ORM\Mapping\DriverChainEntity'
;
$classMetadata
=
new
\Doctrine\ORM\Mapping\ClassMetadata
(
$className
);
$chain
=
new
DriverChain
();
$driver1
=
$this
->
getMock
(
'Doctrine\ORM\Mapping\Driver\Driver'
);
$driver1
->
expects
(
$this
->
once
())
->
method
(
'getAllClassNames'
)
->
will
(
$this
->
returnValue
(
array
(
'Foo'
)));
$driver2
=
$this
->
getMock
(
'Doctrine\ORM\Mapping\Driver\Driver'
);
$driver2
->
expects
(
$this
->
once
())
->
method
(
'getAllClassNames'
)
->
will
(
$this
->
returnValue
(
array
(
'Bar'
,
'Baz'
)));
$chain
->
addDriver
(
$driver1
,
'Doctrine\Tests\Models\Company'
);
$chain
->
addDriver
(
$driver2
,
'Doctrine\Tests\ORM\Mapping'
);
$this
->
assertEquals
(
array
(
'Foo'
,
'Bar'
,
'Baz'
),
$chain
->
getAllClassNames
());
}
}
class
DriverChainEntity
{
}
\ No newline at end of file
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