Skip to content

Commit

Permalink
Moved some tests to a new test case file
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 10, 2014
1 parent 059c864 commit 27ae203
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 27 deletions.
66 changes: 66 additions & 0 deletions tests/TestCase/ORM/AssociationProxyTest.php
@@ -0,0 +1,66 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\ORM;

use Cake\ORM\Association;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

/**
* Tests the features related to proxying methods from the Association
* class to the Table class
*
*/
class AssociationProxyTest extends TestCase {

/**
* Fixtures to be loaded
*
* @var array
*/
public $fixtures = [
'core.article', 'core.author', 'core.comment'
];

/**
* Tests that it is possible to get associations as a property
*
* @return void
*/
public function testAssociationAsProperty() {
$articles = TableRegistry::get('articles');
$articles->hasMany('comments');
$articles->belongsTo('authors');
$this->assertTrue(isset($articles->authors));
$this->assertTrue(isset($articles->comments));
$this->assertFalse(isset($articles->posts));
$this->assertSame($articles->association('authors'), $articles->authors);
$this->assertSame($articles->association('comments'), $articles->comments);
}

/**
* Tests that getting a bad property throws exception
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Table "TestApp\Model\Table\ArticlesTable" is not associated with "posts"
* @return void
*/
public function testGetBadAssociation() {
$articles = TableRegistry::get('articles');
$articles->posts;
}

}
27 changes: 0 additions & 27 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -3308,31 +3308,4 @@ public function testDebugInfo() {
$this->assertEquals($expected, $result);
}

/**
* Tests that it is possible to get associations as a property
*
* @return void
*/
public function testAssociationAsProperty() {
$articles = TableRegistry::get('articles');
$articles->hasMany('comments');
$articles->belongsTo('authors');
$this->assertTrue(isset($articles->authors));
$this->assertTrue(isset($articles->comments));
$this->assertFalse(isset($articles->posts));
$this->assertSame($articles->association('authors'), $articles->authors);
$this->assertSame($articles->association('comments'), $articles->comments);
}

/**
* Tests that getting a bad property throws exception
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Table "TestApp\Model\Table\ArticlesTable" is not associated with "posts"
* @return void
*/
public function testGetBadAssociation() {
$articles = TableRegistry::get('articles');
$articles->posts;
}
}

0 comments on commit 27ae203

Please sign in to comment.