Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make RepositoryAwareTrait not coupled to the ORM.
Add a default type (the ORM loader) and allow userland repository types. The plan is to allow users + plugins to define new repository types that can be fetched from their own factory methods. Register the TableRegistry so things 'just work'
- Loading branch information
Showing
4 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since CakePHP(tm) v 3.0.0 | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace Cake\Test\TestCase\Utility; | ||
|
||
use Cake\TestSuite\TestCase; | ||
use Cake\Utility\RepositoryAwareTrait; | ||
|
||
/** | ||
* Testing stub. | ||
*/ | ||
class Stub { | ||
|
||
use RepositoryAwareTrait; | ||
|
||
public function setProps($name) { | ||
$this->_setModelClass($name); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* RepositoryAwareTrait test case | ||
*/ | ||
class RepositoryAwareTraitTest extends TestCase { | ||
|
||
/** | ||
* Test set modelClass | ||
* | ||
* @return void | ||
*/ | ||
public function testSetModelClass() { | ||
$stub = new Stub(); | ||
$this->assertNull($stub->modelClass); | ||
|
||
$stub->setProps('StubArticles'); | ||
$this->assertEquals('StubArticles', $stub->modelClass); | ||
} | ||
|
||
/** | ||
* test repository() | ||
* | ||
* @return void | ||
*/ | ||
public function testRepository() { | ||
$stub = new Stub(); | ||
$stub->setProps('Articles'); | ||
$stub->repositoryFactory('Table', ['\Cake\ORM\TableRegistry', 'get']); | ||
|
||
$this->assertTrue($stub->repository()); | ||
$this->assertInstanceOf('Cake\ORM\Table', $stub->Articles); | ||
|
||
$this->assertTrue($stub->repository('Comments')); | ||
$this->assertInstanceOf('Cake\ORM\Table', $stub->Comments); | ||
} | ||
|
||
/** | ||
* test alternate repository factories. | ||
* | ||
* @return void | ||
*/ | ||
public function testRepositoryFactory() { | ||
$stub = new Stub(); | ||
$stub->setProps('Articles'); | ||
|
||
$stub->repositoryFactory('Test', function($name) { | ||
$mock = new \StdClass(); | ||
$mock->name = $name; | ||
return $mock; | ||
}); | ||
|
||
$result = $stub->repository('Magic', 'Test'); | ||
$this->assertTrue($result); | ||
$this->assertInstanceOf('\StdClass', $stub->Magic); | ||
$this->assertEquals('Magic', $stub->Magic->name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters