Skip to content
This repository
Browse code

Cleaning up ModelCrossSchemaHabtm test case

  • Loading branch information...
commit 95b8675637ad1a5898c91dd511e402bc71c73eaa 1 parent a9c279a
Kyle Robinson Young authored
129  lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php
... ...
@@ -1,45 +1,81 @@
1 1
 <?php
2  
-
3  
-require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
4  
-
5 2
 /**
6  
- * Tests cross database HABTM.  Requires $test and $test2 to both be set in DATABASE_CONFIG
  3
+ * Tests cross database HABTM. Requires $test and $test2 to both be set in DATABASE_CONFIG
7 4
  * NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections,
8 5
  * or one connection will step on the other.
9 6
  *
10  
- * @package       cake
11  
- * @subpackage    cake.tests.cases.libs.model.operations
  7
+ * PHP 5
  8
+ *
  9
+ * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  10
+ * Copyright 2005-2011, Cake Software Foundation, Inc.
  11
+ *
  12
+ * Licensed under The MIT License
  13
+ * Redistributions of files must retain the above copyright notice
  14
+ *
  15
+ * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc.
  16
+ * @link          http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  17
+ * @package       Cake.Test.Case.Model
12 18
  * @since         CakePHP(tm) v 2.1
  19
+ * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
13 20
  */
  21
+require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
  22
+
14 23
 class ModelCrossSchemaHabtmTest extends BaseModelTest {
15 24
 
16  
-	var $fixtures = array(
  25
+/**
  26
+ * Fixtures to be used
  27
+ *
  28
+ * @var array
  29
+ */
  30
+	public $fixtures = array(
17 31
 		'core.player', 'core.guild', 'core.guilds_player',
18 32
 		'core.armor', 'core.armors_player',
19  
-		);
  33
+	);
20 34
 
21  
-	var $dropTables = false;
  35
+/**
  36
+ * Don't drop tables if they exist
  37
+ *
  38
+ * @var boolean
  39
+ */
  40
+	public $dropTables = false;
  41
+
  42
+/**
  43
+ * Don't auto load fixtures
  44
+ *
  45
+ * @var boolean
  46
+ */
  47
+	public $autoFixtures = false;
22 48
 
23  
-	function setUp() {
  49
+/**
  50
+ * setUp method
  51
+ *
  52
+ * @return void
  53
+ */
  54
+	public function setUp() {
24 55
 		parent::setUp();
25 56
 		$this->_checkConfigs();
26 57
 	}
27 58
 
28  
-	function tearDown() {
29  
-		parent::tearDown();
30  
-	}
31  
-
32  
-	function _checkConfigs() {
  59
+/**
  60
+ * Check if primary and secondary test databases are configured.
  61
+ *
  62
+ * @return void
  63
+ */
  64
+	protected function _checkConfigs() {
33 65
 		$config = ConnectionManager::enumConnectionObjects();
34  
-
35 66
 		$this->skipIf(
36 67
 			!isset($config['test']) || !isset($config['test2']),
37 68
 			 'Primary and secondary test databases not configured, skipping cross-database join tests.'
38  
-			.' To run these tests, you must define $test and $test2 in your database configuration.'
  69
+			. ' To run these tests, you must define $test and $test2 in your database configuration.'
39 70
 		);
40 71
 	}
41 72
 
42  
-	function testModelDatasources() {
  73
+/**
  74
+ * testModelDatasources method
  75
+ *
  76
+ * @return void
  77
+ */
  78
+	public function testModelDatasources() {
43 79
 		$this->loadFixtures('Player', 'Guild', 'GuildsPlayer');
44 80
 
45 81
 		$Player = ClassRegistry::init('Player');
@@ -52,7 +88,12 @@ function testModelDatasources() {
52 88
 		$this->assertEquals('test2', $Player->GuildsPlayer->getDataSource()->configKeyName);
53 89
 	}
54 90
 
55  
-	function testHabtmFind() {
  91
+/**
  92
+ * testHabtmFind method
  93
+ *
  94
+ * @return void
  95
+ */
  96
+	public function testHabtmFind() {
56 97
 		$this->loadFixtures('Player', 'Guild', 'GuildsPlayer');
57 98
 
58 99
 		$Player = ClassRegistry::init('Player');
@@ -63,10 +104,10 @@ function testHabtmFind() {
63 104
 				'Guild' => array(
64 105
 					'conditions' => array(
65 106
 						'Guild.name' => 'Wizards',
66  
-						),
67 107
 					),
68 108
 				),
69  
-			));
  109
+			),
  110
+		));
70 111
 		$this->assertEquals(4, count($players));
71 112
 		$wizards = Set::extract('/Guild[name=Wizards]', $players);
72 113
 		$this->assertEquals(1, count($wizards));
@@ -75,24 +116,28 @@ function testHabtmFind() {
75 116
 			'fields' => array('id', 'name'),
76 117
 			'conditions' => array(
77 118
 				'Player.id' => 1,
78  
-				),
79  
-			));
  119
+			),
  120
+		));
80 121
 		$this->assertEquals(1, count($players));
81 122
 		$wizards = Set::extract('/Guild', $players);
82 123
 		$this->assertEquals(2, count($wizards));
83 124
 	}
84 125
 
85  
-
86  
-	function testHabtmSave() {
  126
+/**
  127
+ * testHabtmSave method
  128
+ *
  129
+ * @return void
  130
+ */
  131
+	public function testHabtmSave() {
87 132
 		$this->loadFixtures('Player', 'Guild', 'GuildsPlayer');
88 133
 
89  
-		$Player =& ClassRegistry::init('Player');
  134
+		$Player = ClassRegistry::init('Player');
90 135
 		$players = $Player->find('count');
91 136
 		$this->assertEquals(4, $players);
92 137
 
93 138
 		$player = $Player->create(array(
94 139
 			'name' => 'rchavik',
95  
-			));
  140
+		));
96 141
 
97 142
 		$results = $Player->saveAll($player, array('validate' => 'first'));
98 143
 		$this->assertNotEqual(false, $results);
@@ -115,20 +160,25 @@ function testHabtmSave() {
115 160
 			'contain' => array(
116 161
 				'conditions' => array(
117 162
 					'Guild.name' => 'Rangers',
118  
-					),
119 163
 				),
120  
-			));
  164
+			),
  165
+		));
121 166
 
122 167
 		$rangers = Set::extract('/Guild[name=Rangers]', $players);
123 168
 		$this->assertEquals(2, count($rangers));
124 169
 	}
125 170
 
126  
-	function testHabtmWithThreeDatabases() {
  171
+/**
  172
+ * testHabtmWithThreeDatabases method
  173
+ *
  174
+ * @return void
  175
+ */
  176
+	public function testHabtmWithThreeDatabases() {
127 177
 		$config = ConnectionManager::enumConnectionObjects();
128 178
 		$this->skipIf(
129 179
 			!isset($config['test']) || !isset($config['test2']) || !isset($config['test_database_three']),
130 180
 			 'Primary, secondary, and tertiary test databases not configured, skipping test.'
131  
-			.' To run these tests, you must define $test, $test2, and $test_database_three in your database configuration.'
  181
+			. ' To run these tests, you must define $test, $test2, and $test_database_three in your database configuration.'
132 182
 		);
133 183
 
134 184
 		$this->loadFixtures('Player', 'Guild', 'GuildsPlayer', 'Armor', 'ArmorsPlayer');
@@ -139,9 +189,9 @@ function testHabtmWithThreeDatabases() {
139 189
 				'Armor' => array(
140 190
 					'with' => 'ArmorsPlayer',
141 191
 					'unique' => true,
142  
-					),
143 192
 				),
144  
-			), false);
  193
+			),
  194
+		), false);
145 195
 		$this->assertEquals('test', $Player->useDbConfig);
146 196
 		$this->assertEquals('test2', $Player->Armor->useDbConfig);
147 197
 		$this->assertEquals('test_database_three', $Player->ArmorsPlayer->useDbConfig);
@@ -151,7 +201,7 @@ function testHabtmWithThreeDatabases() {
151 201
 		$spongebob = $Player->create(array(
152 202
 			'id' => 10,
153 203
 			'name' => 'spongebob',
154  
-			));
  204
+		));
155 205
 		$spongebob['Armor'] = array('Armor' => array(1, 2, 3, 4));
156 206
 		$result = $Player->save($spongebob);
157 207
 
@@ -159,14 +209,14 @@ function testHabtmWithThreeDatabases() {
159 209
 			'Player' => array(
160 210
 				'id' => 10,
161 211
 				'name' => 'spongebob',
162  
-				),
  212
+			),
163 213
 			'Armor' => array(
164 214
 				'Armor' => array(
165 215
 					1, 2, 3, 4,
166 216
 					1, 2, 3, 4,
167  
-					),
168 217
 				),
169  
-			);
  218
+			),
  219
+		);
170 220
 		unset($result['Player']['created']);
171 221
 		unset($result['Player']['updated']);
172 222
 		$this->assertEquals($expected, $result);
@@ -174,10 +224,9 @@ function testHabtmWithThreeDatabases() {
174 224
 		$spongebob = $Player->find('all', array(
175 225
 			'conditions' => array(
176 226
 				'Player.id' => 10,
177  
-				)
178  
-			));
  227
+			)
  228
+		));
179 229
 		$spongeBobsArmors = Set::extract('/Armor', $spongebob);
180 230
 		$this->assertEquals(4, count($spongeBobsArmors));
181 231
 	}
182  
-
183 232
 }

0 notes on commit 95b8675

Please sign in to comment.
Something went wrong with that request. Please try again.