Skip to content

Commit 27ae203

Browse files
committed
Moved some tests to a new test case file
1 parent 059c864 commit 27ae203

File tree

2 files changed

+66
-27
lines changed

2 files changed

+66
-27
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* For full copyright and license information, please see the LICENSE.txt
8+
* Redistributions of files must retain the above copyright notice.
9+
*
10+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11+
* @link http://cakephp.org CakePHP(tm) Project
12+
* @since 3.0.0
13+
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
14+
*/
15+
namespace Cake\Test\TestCase\ORM;
16+
17+
use Cake\ORM\Association;
18+
use Cake\ORM\Table;
19+
use Cake\ORM\TableRegistry;
20+
use Cake\TestSuite\TestCase;
21+
22+
/**
23+
* Tests the features related to proxying methods from the Association
24+
* class to the Table class
25+
*
26+
*/
27+
class AssociationProxyTest extends TestCase {
28+
29+
/**
30+
* Fixtures to be loaded
31+
*
32+
* @var array
33+
*/
34+
public $fixtures = [
35+
'core.article', 'core.author', 'core.comment'
36+
];
37+
38+
/**
39+
* Tests that it is possible to get associations as a property
40+
*
41+
* @return void
42+
*/
43+
public function testAssociationAsProperty() {
44+
$articles = TableRegistry::get('articles');
45+
$articles->hasMany('comments');
46+
$articles->belongsTo('authors');
47+
$this->assertTrue(isset($articles->authors));
48+
$this->assertTrue(isset($articles->comments));
49+
$this->assertFalse(isset($articles->posts));
50+
$this->assertSame($articles->association('authors'), $articles->authors);
51+
$this->assertSame($articles->association('comments'), $articles->comments);
52+
}
53+
54+
/**
55+
* Tests that getting a bad property throws exception
56+
*
57+
* @expectedException \RuntimeException
58+
* @expectedExceptionMessage Table "TestApp\Model\Table\ArticlesTable" is not associated with "posts"
59+
* @return void
60+
*/
61+
public function testGetBadAssociation() {
62+
$articles = TableRegistry::get('articles');
63+
$articles->posts;
64+
}
65+
66+
}

tests/TestCase/ORM/TableTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,31 +3308,4 @@ public function testDebugInfo() {
33083308
$this->assertEquals($expected, $result);
33093309
}
33103310

3311-
/**
3312-
* Tests that it is possible to get associations as a property
3313-
*
3314-
* @return void
3315-
*/
3316-
public function testAssociationAsProperty() {
3317-
$articles = TableRegistry::get('articles');
3318-
$articles->hasMany('comments');
3319-
$articles->belongsTo('authors');
3320-
$this->assertTrue(isset($articles->authors));
3321-
$this->assertTrue(isset($articles->comments));
3322-
$this->assertFalse(isset($articles->posts));
3323-
$this->assertSame($articles->association('authors'), $articles->authors);
3324-
$this->assertSame($articles->association('comments'), $articles->comments);
3325-
}
3326-
3327-
/**
3328-
* Tests that getting a bad property throws exception
3329-
*
3330-
* @expectedException \RuntimeException
3331-
* @expectedExceptionMessage Table "TestApp\Model\Table\ArticlesTable" is not associated with "posts"
3332-
* @return void
3333-
*/
3334-
public function testGetBadAssociation() {
3335-
$articles = TableRegistry::get('articles');
3336-
$articles->posts;
3337-
}
33383311
}

0 commit comments

Comments
 (0)