Skip to content

Commit

Permalink
Migrating TableRegistry to use the new table name convention
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Nov 8, 2013
1 parent b2485eb commit 6d92b13
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
Expand Up @@ -17,7 +17,7 @@
* Article table class
*
*/
class ArticleTable extends Table {
class ArticlesTable extends Table {

public function initialize(array $config) {
$this->belongsTo('author');
Expand Down
Expand Up @@ -17,7 +17,7 @@
* Tag table class
*
*/
class ArticlesTagTable extends Table {
class ArticlesTagsTable extends Table {

public function initialize(array $config) {
$this->belongsTo('article');
Expand Down
Expand Up @@ -17,7 +17,7 @@
* Author table class
*
*/
class AuthorTable extends Table {
class AuthorsTable extends Table {

public function initialize(array $config) {
$this->hasMany('article');
Expand Down
Expand Up @@ -17,7 +17,7 @@
* Tag table class
*
*/
class TagTable extends Table {
class TagsTable extends Table {

public function initialize(array $config) {
$this->belongsTo('author');
Expand Down
40 changes: 20 additions & 20 deletions Cake/Test/TestCase/ORM/TableRegistryTest.php
Expand Up @@ -68,17 +68,17 @@ public function tearDown() {
* @return void
*/
public function testConfig() {
$this->assertEquals([], TableRegistry::config('Test'));
$this->assertEquals([], TableRegistry::config('Tests'));

$data = [
'connection' => 'testing',
'entityClass' => 'TestApp\Model\Entity\Article',
];
$result = TableRegistry::config('Test', $data);
$result = TableRegistry::config('Tests', $data);
$this->assertEquals($data, $result, 'Returns config data.');

$result = TableRegistry::config();
$expected = ['Test' => $data];
$expected = ['Tests' => $data];
$this->assertEquals($expected, $result);
}

Expand All @@ -88,13 +88,13 @@ public function testConfig() {
* @return void
*/
public function testGet() {
$result = TableRegistry::get('Article', [
$result = TableRegistry::get('Articles', [
'table' => 'my_articles',
]);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('my_articles', $result->table());

$result2 = TableRegistry::get('Article', [
$result2 = TableRegistry::get('Articles', [
'table' => 'herp_derp',
]);
$this->assertSame($result, $result2);
Expand All @@ -107,10 +107,10 @@ public function testGet() {
* @return void
*/
public function testGetWithConfig() {
TableRegistry::config('Article', [
TableRegistry::config('Articles', [
'table' => 'my_articles',
]);
$result = TableRegistry::get('Article');
$result = TableRegistry::get('Articles');
$this->assertEquals('my_articles', $result->table(), 'Should use config() data.');
}

Expand All @@ -121,26 +121,26 @@ public function testGetWithConfig() {
* @return void
*/
public function testBuildConvention() {
$table = TableRegistry::get('article');
$this->assertInstanceOf('\TestApp\Model\Repository\ArticleTable', $table);
$table = TableRegistry::get('Article');
$this->assertInstanceOf('\TestApp\Model\Repository\ArticleTable', $table);
$table = TableRegistry::get('articles');
$this->assertInstanceOf('\TestApp\Model\Repository\ArticlesTable', $table);
$table = TableRegistry::get('Articles');
$this->assertInstanceOf('\TestApp\Model\Repository\ArticlesTable', $table);

$table = TableRegistry::get('author');
$this->assertInstanceOf('\TestApp\Model\Repository\AuthorTable', $table);
$table = TableRegistry::get('Author');
$this->assertInstanceOf('\TestApp\Model\Repository\AuthorTable', $table);
$table = TableRegistry::get('authors');
$this->assertInstanceOf('\TestApp\Model\Repository\AuthorsTable', $table);
$table = TableRegistry::get('Authors');
$this->assertInstanceOf('\TestApp\Model\Repository\AuthorsTable', $table);

$class = $this->getMockClass('\Cake\ORM\Table');
$class::staticExpects($this->once())
->method('defaultConnectionName')
->will($this->returnValue('test'));

if (!class_exists('MyPlugin\Model\Repository\SuperTestTable')) {
class_alias($class, 'MyPlugin\Model\Repository\SuperTestTable');
if (!class_exists('MyPlugin\Model\Repository\SuperTestsTable')) {
class_alias($class, 'MyPlugin\Model\Repository\SuperTestsTable');
}

$table = TableRegistry::get('MyPlugin.SuperTest');
$table = TableRegistry::get('MyPlugin.SuperTests');
$this->assertInstanceOf($class, $table);
}

Expand Down Expand Up @@ -192,8 +192,8 @@ public function testConfigAndBuild() {
*/
public function testSet() {
$mock = $this->getMock('Cake\ORM\Table');
$this->assertSame($mock, TableRegistry::set('Article', $mock));
$this->assertSame($mock, TableRegistry::get('Article'));
$this->assertSame($mock, TableRegistry::set('Articles', $mock));
$this->assertSame($mock, TableRegistry::get('Articles'));
}

}

0 comments on commit 6d92b13

Please sign in to comment.