Skip to content

Commit

Permalink
Merge pull request #10231 from robertpustulka/issue-10208
Browse files Browse the repository at this point in the history
Make target table class name check less strict.
  • Loading branch information
lorenzo committed Feb 15, 2017
2 parents 8f13b33 + eadae15 commit 2411728
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ORM/Association.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,10 @@ public function getTarget()
$this->_targetTable = $tableLocator->get($registryAlias, $config);

if ($exists) {
$targetClassName = get_class($this->_targetTable);
$className = $this->_getClassName($registryAlias, ['className' => $this->_className]);

if ($targetClassName !== $className) {
if (!$this->_targetTable instanceof $className) {
$targetClassName = get_class($this->_targetTable);
throw new RuntimeException(sprintf(
'Invalid Table retrieved from a registry. Requested: %s, got: %s',
$className,
Expand Down
27 changes: 27 additions & 0 deletions tests/TestCase/ORM/AssociationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,33 @@ public function testInvalidTableFetchedFromRegistry()
$this->association->getTarget();
}

/**
* Tests that a descendant table could be fetched from a registry.
*
* @return void
*/
public function testTargetTableDescendant()
{
TableRegistry::get('Test', [
'className' => '\Cake\Test\TestCase\ORM\TestTable'
]);
$className = '\Cake\ORM\Table';

$config = [
'className' => $className,
];
$this->association = $this->getMockBuilder('\Cake\ORM\Association')
->setMethods([
'_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide',
'saveAssociated', 'eagerLoader', 'type', 'requiresKeys'
])
->setConstructorArgs(['Test', $config])
->getMock();

$target = $this->association->getTarget();
$this->assertInstanceOf($className, $target);
}

/**
* Tests that cascadeCallbacks() returns the correct configured value
*
Expand Down

0 comments on commit 2411728

Please sign in to comment.