Merge lp:~lewiszhang/coughphp/1.4-switch-to-phpunit into lp:coughphp/1.4

Proposed by Lewis Zhang on 2010-12-15
Status: Merged
Approved by: Lewis Zhang on 2010-12-15
Approved revision: 309
Merged at revision: 309
Proposed branch: lp:~lewiszhang/coughphp/1.4-switch-to-phpunit
Merge into: lp:coughphp/1.4
Diff against target: 1367 lines (+282/-337)
13 files modified
scripts/test_all (+0/-18)
scripts/utest (+0/-79)
tests/autoloader/AutoloaderCacheFileTest.class.php (+23/-0)
tests/autoloader/AutoloaderTest.class.php (+14/-28)
tests/cough/CoughCollectionTest.class.php (+34/-35)
tests/cough/CoughDatabaseFactoryTest.class.php (+30/-28)
tests/cough/CoughInstancePoolTest.class.php (+9/-10)
tests/cough/CoughObjectTest.class.php (+80/-82)
tests/cough_generator/CoughGeneratorTest.class.php (+10/-11)
tests/dal/CoughAsDatabaseTest.class.php (+43/-44)
tests/database_config.inc.php (+8/-2)
tests/phpunit-after.xml (+8/-0)
tests/phpunit.xml (+23/-0)
To merge this branch: bzr merge lp:~lewiszhang/coughphp/1.4-switch-to-phpunit
Reviewer Review Type Date Requested Status
Anthony Bush 2010-12-15 Pending
Review via email: mp+43740@code.launchpad.net

Description of the change

Convert from SimpleTest to PHPUnit. To run the tests:

$ cd tests/
$ phpunit --verbose

If you would like to test Autoloader's register_shutdown_function hook:

$ phpunit --verbose --configuration phpunit-after.xml

Tested on PHPUnit version 3.5.5 installed via PEAR.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'scripts/test_all'
2--- scripts/test_all 2009-03-24 15:02:40 +0000
3+++ scripts/test_all 1970-01-01 00:00:00 +0000
4@@ -1,18 +0,0 @@
5-#!/usr/bin/env php
6-<?php
7-
8-$utest = dirname(__FILE__) . '/utest';
9-$coughRoot = dirname(dirname(__FILE__)) . '/';
10-
11-echo "Testing the cough generator:\n";
12-echo shell_exec(escapeshellarg($utest) . ' ' . escapeshellarg($coughRoot) . 'tests/cough_generator/Test*.class.php');
13-echo "Testing core cough:\n";
14-echo shell_exec(escapeshellarg($utest) . ' ' . escapeshellarg($coughRoot) . 'tests/cough/Test*.class.php');
15-echo "Testing DAL (Database Abstraction Layer) without magic_quotes_gpc:\n";
16-echo shell_exec('php -d magic_quotes_gpc=Off ' . escapeshellarg($utest) . ' ' . escapeshellarg($coughRoot) . 'tests/dal/TestCoughAsDatabase.class.php');
17-echo "Testing DAL (Database Abstraction Layer) with magic_quotes_gpc:\n";
18-echo shell_exec('php -d magic_quotes_gpc=On ' . escapeshellarg($utest) . ' ' . escapeshellarg($coughRoot) . 'tests/dal/TestCoughAsDatabase.class.php');
19-echo "Testing Autoloader:\n";
20-echo shell_exec(escapeshellarg($utest) . ' ' . escapeshellarg($coughRoot) . 'tests/autoloader/TestAutoloader.class.php');
21-
22-?>
23
24=== removed file 'scripts/utest'
25--- scripts/utest 2008-06-12 04:42:16 +0000
26+++ scripts/utest 1970-01-01 00:00:00 +0000
27@@ -1,79 +0,0 @@
28-#!/usr/bin/env php
29-<?php
30-
31-// CHANGE THIS TO YOUR `simpletest` PATH. (e.g. if it's in the include path, set it to empty string).
32-define('SIMPLETEST_PATH', 'simpletest/');
33-
34-
35-/////////////////////////////////
36-// Don't change anything below //
37-/////////////////////////////////
38-
39-
40-// Check that we're running in command line mode with at least one argument
41-if (!isset($_SERVER['argc']) || !isset($_SERVER['argv']) || $_SERVER['argc'] < 2)
42-{
43- print_usage();
44- exit(1);
45-}
46-
47-// Default options
48-$files = array();
49-
50-// Parse command line options
51-$argc = $_SERVER['argc'];
52-$argv = $_SERVER['argv'];
53-for ($i = 1; $i < $argc; $i++)
54-{
55- $files[] = $argv[$i];
56-}
57-
58-// Function for printing usage info
59-function print_usage()
60-{
61- $script = 'utest';
62-
63- echo 'NAME
64- ' . $script . ' -- run tests using the SimpleTest unit tester
65-
66-SYNOPSIS
67- ' . $script . ' file [file...]
68-
69-DESCRIPTION
70- ' . $script . ' takes one or more files that include test classes and
71- passes them to the SimpleTest unit tester.
72-
73-EXAMPLES
74- Test one file in the current directory:
75-
76- ' . $script . ' TestCoughCollection.class.php
77-
78- Test all files in the current directory that start with "Test" and end
79- with ".php"
80-
81- ' . $script . ' Test*.php
82-
83-SEE ALSO
84- Download SimpleTest from http://simpletest.sourceforge.net/
85-';
86-}
87-
88-
89-// simpletest is not strict compatible, so remove it
90-$oldErrorReporting = error_reporting();
91-error_reporting($oldErrorReporting & ~E_STRICT);
92-
93-// Run Tests
94-require_once(SIMPLETEST_PATH . 'autorun.php');
95-$test = new TestSuite('Running Tests');
96-foreach ($files as $file)
97-{
98- $test->addTestFile($file);
99-}
100-if (TextReporter::inCli())
101-{
102- exit ($test->run(new TextReporter()) ? 0 : 1);
103-}
104-$test->run(new HtmlReporter());
105-
106-?>
107\ No newline at end of file
108
109=== added file 'tests/autoloader/AutoloaderCacheFileTest.class.php'
110--- tests/autoloader/AutoloaderCacheFileTest.class.php 1970-01-01 00:00:00 +0000
111+++ tests/autoloader/AutoloaderCacheFileTest.class.php 2010-12-15 07:59:33 +0000
112@@ -0,0 +1,23 @@
113+<?php
114+class AutoloaderCacheFileTest extends PHPUnit_Framework_TestCase
115+{
116+ protected static $cacheFile = '';
117+
118+ public static function setUpBeforeClass()
119+ {
120+ self::$cacheFile = dirname(__FILE__) . '/class_path_cache.txt';
121+ }
122+
123+ public static function removeCacheFile()
124+ {
125+ if (file_exists(self::$cacheFile)) {
126+ unlink(self::$cacheFile);
127+ }
128+ }
129+
130+ public function testWasCacheFileCreated()
131+ {
132+ $this->assertFileExists(self::$cacheFile);
133+ self::removeCacheFile();
134+ }
135+}
136
137=== renamed file 'tests/autoloader/TestAutoloader.class.php' => 'tests/autoloader/AutoloaderTest.class.php'
138--- tests/autoloader/TestAutoloader.class.php 2008-09-22 04:12:07 +0000
139+++ tests/autoloader/AutoloaderTest.class.php 2010-12-15 07:59:33 +0000
140@@ -1,39 +1,25 @@
141 <?php
142-
143-class TestAutoloader extends UnitTestCase
144+class AutoloaderTest extends PHPUnit_Framework_TestCase
145 {
146- protected $cacheFile = '';
147+ protected static $cacheFile = '';
148
149- public function __construct()
150+ public static function setUpBeforeClass()
151 {
152- parent::__construct();
153-
154- $this->cacheFile = dirname(__FILE__) . 'class_path_cache.txt';
155- $this->removeCacheFile();
156+ self::$cacheFile = dirname(__FILE__) . '/class_path_cache.txt';
157+ self::removeCacheFile();
158
159 include_once(dirname(dirname(dirname(__FILE__))) . '/extras/Autoloader.class.php');
160 Autoloader::addClassPath(dirname(__FILE__) . '/classes_app/');
161 Autoloader::addClassPath(dirname(__FILE__) . '/classes_shared/');
162- Autoloader::setCacheFilePath($this->cacheFile);
163+ Autoloader::setCacheFilePath(self::$cacheFile);
164 //Autoloader::excludeFolderNamesMatchingRegex('/^CVS|\..*$/');
165 spl_autoload_register(array('Autoloader', 'loadClass'));
166 }
167
168- public function __destruct()
169- {
170- // Not sure how to put this in the testing framework since we are testing
171- // functionality as the script ends...
172- if (!file_exists($this->cacheFile))
173- {
174- trigger_error('Cache file was not saved at end of script', E_USER_ERROR);
175- }
176- $this->removeCacheFile();
177- }
178-
179- public function removeCacheFile()
180- {
181- if (file_exists($this->cacheFile)) {
182- unlink($this->cacheFile);
183+ public static function removeCacheFile()
184+ {
185+ if (file_exists(self::$cacheFile)) {
186+ unlink(self::$cacheFile);
187 }
188 }
189
190@@ -46,7 +32,7 @@
191 public function testAppCanOverrideClasses()
192 {
193 $obj = new As_String();
194- $this->assertEqual($obj->getClassLocation(), 'app');
195+ $this->assertEquals($obj->getClassLocation(), 'app');
196 }
197
198 public function testExtendedClassesAreAlsoAutoloaded()
199@@ -58,14 +44,14 @@
200
201 public function testCacheFileSavingIsDelayedUntilScriptEnds()
202 {
203- $this->assertFalse(file_exists($this->cacheFile), 'Cache file should not exist yet');
204+ $this->assertFalse(file_exists(self::$cacheFile), 'Cache file should not exist yet');
205 }
206
207 public function testCacheFileCanBeManuallySaved()
208 {
209 Autoloader::saveCachedPaths();
210- $this->assertTrue(file_exists($this->cacheFile), 'Cache file should exist');
211- $this->assertTrue(filesize($this->cacheFile) > 0, 'Cache file should be non-empty');
212+ $this->assertTrue(file_exists(self::$cacheFile), 'Cache file should exist');
213+ $this->assertTrue(filesize(self::$cacheFile) > 0, 'Cache file should be non-empty');
214 $this->removeCacheFile();
215 }
216 }
217
218=== renamed file 'tests/cough/TestCoughCollection.class.php' => 'tests/cough/CoughCollectionTest.class.php' (properties changed: +x to -x)
219--- tests/cough/TestCoughCollection.class.php 2009-11-05 19:53:50 +0000
220+++ tests/cough/CoughCollectionTest.class.php 2010-12-15 07:59:33 +0000
221@@ -1,12 +1,11 @@
222 <?php
223-
224-class TestCoughCollection extends UnitTestCase
225+class CoughCollectionTest extends PHPUnit_Framework_TestCase
226 {
227 //////////////////////////////////////
228 // Set Up
229 //////////////////////////////////////
230
231- public function __construct()
232+ public static function setUpBeforeClass()
233 {
234 $coughRoot = dirname(dirname(dirname(__FILE__)));
235 require_once($coughRoot . '/cough/load.inc.php');
236@@ -89,9 +88,9 @@
237 $sortMe1->add(new SortableElement($sortableData[0]));
238 $sortMe1->add(new SortableElement($sortableData[1]));
239 $sortMe1->add(new SortableElement($sortableData[2]));
240- $this->assertEqual($sortedCollectionIds, $sortMe1->getArrayKeys());
241+ $this->assertEquals($sortedCollectionIds, $sortMe1->getArrayKeys());
242 $sortMe1->sortByMethod('getManufacturerName');
243- $this->assertEqual($sortedCollectionIds, $sortMe1->getArrayKeys());
244+ $this->assertEquals($sortedCollectionIds, $sortMe1->getArrayKeys());
245 unset($sortMe1);
246
247 // Create another sorted copy and sort it using another method
248@@ -100,7 +99,7 @@
249 $sortMe2->add(new SortableElement($sortableData[1]));
250 $sortMe2->add(new SortableElement($sortableData[2]));
251 $sortMe2->sortByMethod('getProductName');
252- $this->assertEqual($sortedCollectionIds, $sortMe2->getArrayKeys());
253+ $this->assertEquals($sortedCollectionIds, $sortMe2->getArrayKeys());
254 unset($sortMe2);
255
256 // Create another sorted copy and sort it using another method
257@@ -109,7 +108,7 @@
258 $sortMe3->add(new SortableElement($sortableData[1]));
259 $sortMe3->add(new SortableElement($sortableData[2]));
260 $sortMe3->sortByMethod('getPrice');
261- $this->assertEqual($sortedCollectionIds, $sortMe3->getArrayKeys());
262+ $this->assertEquals($sortedCollectionIds, $sortMe3->getArrayKeys());
263 unset($sortMe3);
264
265 ///////////////////////////////////////////
266@@ -121,9 +120,9 @@
267 $sortMe4->add(new SortableElement($sortableData[1]));
268 $sortMe4->add(new SortableElement($sortableData[2]));
269 $sortMe4->add(new SortableElement($sortableData[0]));
270- $this->assertNotEqual($sortedCollectionIds, $sortMe4->getArrayKeys());
271+ $this->assertNotEquals($sortedCollectionIds, $sortMe4->getArrayKeys());
272 $sortMe4->sortByMethod('getManufacturerName');
273- $this->assertEqual($sortedCollectionIds, $sortMe4->getArrayKeys());
274+ $this->assertEquals($sortedCollectionIds, $sortMe4->getArrayKeys());
275 unset($sortMe4);
276
277 // Create another unsorted copy and sort it using another method
278@@ -131,9 +130,9 @@
279 $sortMe5->add(new SortableElement($sortableData[1]));
280 $sortMe5->add(new SortableElement($sortableData[2]));
281 $sortMe5->add(new SortableElement($sortableData[0]));
282- $this->assertNotEqual($sortedCollectionIds, $sortMe5->getArrayKeys());
283+ $this->assertNotEquals($sortedCollectionIds, $sortMe5->getArrayKeys());
284 $sortMe5->sortByMethod('getProductName');
285- $this->assertEqual($sortedCollectionIds, $sortMe5->getArrayKeys());
286+ $this->assertEquals($sortedCollectionIds, $sortMe5->getArrayKeys());
287 unset($sortMe5);
288
289 // Create another unsorted copy and sort it using another method
290@@ -141,9 +140,9 @@
291 $sortMe6->add(new SortableElement($sortableData[1]));
292 $sortMe6->add(new SortableElement($sortableData[2]));
293 $sortMe6->add(new SortableElement($sortableData[0]));
294- $this->assertNotEqual($sortedCollectionIds, $sortMe6->getArrayKeys());
295+ $this->assertNotEquals($sortedCollectionIds, $sortMe6->getArrayKeys());
296 $sortMe6->sortByMethod('getProductName');
297- $this->assertEqual($sortedCollectionIds, $sortMe6->getArrayKeys());
298+ $this->assertEquals($sortedCollectionIds, $sortMe6->getArrayKeys());
299 unset($sortMe6);
300
301 }
302@@ -153,37 +152,37 @@
303 $collection = $this->buildSortableCollection();
304
305 $collection->sortByMethods('getManufacturerName');
306- $this->assertEqual(array(1,4,2,3), $collection->getArrayKeys());
307+ $this->assertEquals(array(1,4,2,3), $collection->getArrayKeys());
308
309 $collection->sortByMethods('getManufacturerName', SORT_DESC);
310- $this->assertEqual(array(3,2,4,1), $collection->getArrayKeys());
311+ $this->assertEquals(array(3,2,4,1), $collection->getArrayKeys());
312
313 $collection->sortByMethods('getManufacturerName', 'getProductName');
314- $this->assertEqual(array(1,4,2,3), $collection->getArrayKeys());
315+ $this->assertEquals(array(1,4,2,3), $collection->getArrayKeys());
316
317 $collection->sortByMethods('getManufacturerName', 'getProductName', SORT_DESC);
318- $this->assertEqual(array(1,2,4,3), $collection->getArrayKeys());
319+ $this->assertEquals(array(1,2,4,3), $collection->getArrayKeys());
320
321 $collection->sortByMethods('getManufacturerName', SORT_DESC, 'getProductName', SORT_DESC);
322- $this->assertEqual(array(3,2,4,1), $collection->getArrayKeys());
323+ $this->assertEquals(array(3,2,4,1), $collection->getArrayKeys());
324
325 $collection->sortByMethods('getProductName', 'getManufacturerName');
326- $this->assertEqual(array(1,4,2,3), $collection->getArrayKeys());
327+ $this->assertEquals(array(1,4,2,3), $collection->getArrayKeys());
328
329 $collection->sortByMethods('getProductName', 'getManufacturerName', SORT_DESC);
330- $this->assertEqual(array(4,1,2,3), $collection->getArrayKeys());
331+ $this->assertEquals(array(4,1,2,3), $collection->getArrayKeys());
332
333 $collection->sortByMethods('getProductName', SORT_DESC, 'getManufacturerName', SORT_DESC);
334- $this->assertEqual(array(3,2,4,1), $collection->getArrayKeys());
335+ $this->assertEquals(array(3,2,4,1), $collection->getArrayKeys());
336
337 $collection->sortByMethods('getPrice');
338- $this->assertEqual(array(1,2,3,4), $collection->getArrayKeys());
339+ $this->assertEquals(array(1,2,3,4), $collection->getArrayKeys());
340
341 $collection->sortByMethods('getPrice', SORT_DESC);
342- $this->assertEqual(array(4,3,2,1), $collection->getArrayKeys());
343+ $this->assertEquals(array(4,3,2,1), $collection->getArrayKeys());
344
345 $collection->sortByMethods('getPrice', SORT_ASC, 'getProductName', SORT_DESC, 'getManufacturerName');
346- $this->assertEqual(array(1,2,3,4), $collection->getArrayKeys());
347+ $this->assertEquals(array(1,2,3,4), $collection->getArrayKeys());
348
349
350 // test sort empty collection
351@@ -251,7 +250,7 @@
352 foreach ($keyPermutations as $keyPermutation)
353 {
354 $collection->sortByKeys($keyPermutation);
355- $this->assertEqual($keyPermutation, $collection->getArrayKeys());
356+ $this->assertEquals($keyPermutation, $collection->getArrayKeys());
357 }
358 }
359
360@@ -275,15 +274,15 @@
361 $iteratorData[$keyId] = $productName;
362 }
363
364- $this->assertIdentical($manualData, $iteratorData);
365+ $this->assertSame($manualData, $iteratorData);
366
367 // count should work
368- $this->assertIdentical(count($manualData), count($iterator));
369- $this->assertIdentical(count($collection), count($iterator));
370+ $this->assertSame(count($manualData), count($iterator));
371+ $this->assertSame(count($collection), count($iterator));
372
373 // empty should work
374- $this->assertIdentical(empty($manualData), empty($iterator));
375- $this->assertIdentical(empty($collection), empty($iterator));
376+ $this->assertSame(empty($manualData), empty($iterator));
377+ $this->assertSame(empty($collection), empty($iterator));
378 }
379
380 public function testGetKeyValueIteratorWithCustomKeyId()
381@@ -305,15 +304,15 @@
382 $iteratorData[$keyId] = $productName;
383 }
384
385- $this->assertIdentical($manualData, $iteratorData);
386+ $this->assertSame($manualData, $iteratorData);
387
388 // count should work
389- $this->assertIdentical(count($manualData), count($iterator));
390- $this->assertIdentical(count($collection), count($iterator));
391+ $this->assertSame(count($manualData), count($iterator));
392+ $this->assertSame(count($collection), count($iterator));
393
394 // empty should work
395- $this->assertIdentical(empty($manualData), empty($iterator));
396- $this->assertIdentical(empty($collection), empty($iterator));
397+ $this->assertSame(empty($manualData), empty($iterator));
398+ $this->assertSame(empty($collection), empty($iterator));
399 }
400
401 public function testCanRemoveItemsFromCollectionWhileLooping()
402
403=== renamed file 'tests/cough/TestCoughDatabaseFactory.class.php' => 'tests/cough/CoughDatabaseFactoryTest.class.php'
404--- tests/cough/TestCoughDatabaseFactory.class.php 2009-03-24 15:16:02 +0000
405+++ tests/cough/CoughDatabaseFactoryTest.class.php 2010-12-15 07:59:33 +0000
406@@ -1,6 +1,5 @@
407 <?php
408-
409-class TestCoughDatabaseFactory extends UnitTestCase
410+class CoughDatabaseFactoryTest extends PHPUnit_Framework_TestCase
411 {
412 protected $configs = array();
413
414@@ -8,7 +7,7 @@
415 // Set Up
416 //////////////////////////////////////
417
418- public function __construct()
419+ public static function setUpBeforeClass()
420 {
421 $coughRoot = dirname(dirname(dirname(__FILE__)));
422 require_once($coughRoot . '/cough/load.inc.php');
423@@ -16,18 +15,22 @@
424
425 public function setUp()
426 {
427+ include(dirname(dirname(__FILE__)) . '/database_config.inc.php');
428+
429 CoughDatabaseFactory::reset();
430 $this->configs = array(
431 'config1' => array(
432- 'host' => 'localhost',
433- 'user' => 'nobody',
434- 'port' => '3306',
435+ 'host' => $dsn['host'],
436+ 'user' => $dsn['user'],
437+ 'pass' => $dsn['pass'],
438+ 'port' => $dsn['port'],
439 'aliases' => array('testConfigAlias', 'reporting_server' => 'reports')
440 ),
441 'config2' => array(
442- 'host' => 'localhost',
443- 'user' => 'nobody',
444- 'port' => '3307',
445+ 'host' => $dsn['host'],
446+ 'user' => $dsn['user'],
447+ 'pass' => $dsn['pass'],
448+ 'port' => $dsn['port'],
449 'db_name_hash' => array('db_alias' => 'actual_db_name', 'write_server' => 'reports')
450 )
451 );
452@@ -40,17 +43,17 @@
453 public function assertGetDatabaseNameWorks()
454 {
455 // An alias specified without the hash should have alias *and* database name equal to each other.
456- $this->assertIdentical(CoughDatabaseFactory::getDatabaseName('testConfigAlias'), 'testConfigAlias');
457+ $this->assertSame(CoughDatabaseFactory::getDatabaseName('testConfigAlias'), 'testConfigAlias');
458
459 // Specifying an alias with a hash allows access to the value stored therein.
460- $this->assertIdentical(CoughDatabaseFactory::getDatabaseName('reporting_server'), 'reports');
461+ $this->assertSame(CoughDatabaseFactory::getDatabaseName('reporting_server'), 'reports');
462
463 // Trying to access a database name that doesn't have a mapping should return the original value.
464- $this->assertIdentical(CoughDatabaseFactory::getDatabaseName('reports'), 'reports');
465+ $this->assertSame(CoughDatabaseFactory::getDatabaseName('reports'), 'reports');
466
467 // Specifying the db_name_hash allows a more direct way of configuring the aliases and database name mappings
468- $this->assertIdentical(CoughDatabaseFactory::getDatabaseName('db_alias'), 'actual_db_name');
469- $this->assertIdentical(CoughDatabaseFactory::getDatabaseName('write_server'), 'reports');
470+ $this->assertSame(CoughDatabaseFactory::getDatabaseName('db_alias'), 'actual_db_name');
471+ $this->assertSame(CoughDatabaseFactory::getDatabaseName('write_server'), 'reports');
472 }
473
474 public function testAddConfig()
475@@ -99,61 +102,60 @@
476 // test default adapter = "as" and old style "aliases" param
477 $testDbConfig = array(
478 'driver' => 'mysql',
479- 'host' => 'localhost',
480+ 'host' => '',
481 'user' => 'cough_test',
482 'pass' => 'cough_test',
483- 'port' => '3306',
484+ 'port' => ':/opt/local/var/run/mysql5/mysql.sock',
485 'aliases' => array('cough_test1')
486 );
487 CoughDatabaseFactory::addConfig($testDbConfig);
488 $test1Db = CoughDatabaseFactory::getDatabase('cough_test1');
489- $this->assertIsA($test1Db, 'As_Database');
490+ $this->assertInstanceOf('As_Database', $test1Db);
491
492 // test specifying adapter as "as" and new "db_name_hash" param
493 $testDbConfig = array(
494 'adapter' => 'as',
495 'driver' => 'mysql',
496- 'host' => 'localhost',
497+ 'host' => '',
498 'user' => 'cough_test',
499 'pass' => 'cough_test',
500- 'port' => '3306',
501+ 'port' => ':/opt/local/var/run/mysql5/mysql.sock',
502 'db_name_hash' => array('cough_test2' => 'test_cough_object')
503 );
504 CoughDatabaseFactory::addConfig($testDbConfig);
505 $test2Db = CoughDatabaseFactory::getDatabase('cough_test2');
506- $this->assertIsA($test2Db, 'As_Database');
507+ $this->assertInstanceOf('As_Database', $test2Db);
508
509 // test new style aliases param
510 $testDbConfig = array(
511 'driver' => 'mysql',
512- 'host' => 'localhost',
513+ 'host' => '',
514 'user' => 'cough_test',
515 'pass' => 'cough_test',
516- 'port' => '3306',
517+ 'port' => ':/opt/local/var/run/mysql5/mysql.sock',
518 'aliases' => array('cough_test4' => 'test_cough_object')
519 );
520 CoughDatabaseFactory::addConfig($testDbConfig);
521 $test4Db = CoughDatabaseFactory::getDatabase('cough_test4');
522- $this->assertIsA($test4Db, 'As_Database');
523+ $this->assertInstanceOf('As_Database', $test4Db);
524
525 // // test specifying adapter as "pdo"
526 // $testDbConfig = array(
527 // 'adapter' => 'pdo',
528 // 'driver' => 'mysql',
529- // 'host' => 'localhost',
530+ // 'host' => '',
531 // 'user' => 'cough_test',
532 // 'pass' => 'cough_test',
533- // 'port' => '3306',
534+ // 'port' => ':/opt/local/var/run/mysql5/mysql.sock',
535 // 'aliases' => array('cough_test3' => 'test_cough_object')
536 // );
537 // CoughDatabaseFactory::addConfig($testDbConfig);
538 // $test3Db = CoughDatabaseFactory::getDatabase('cough_test3');
539- // $this->assertIsA($test3Db, 'CoughPdoDatabaseAdapter');
540+ // $this->assertInstanceOf('CoughPdoDatabaseAdapter', $test3Db);
541
542 // test getting the same database object back
543 $test1DbReference = CoughDatabaseFactory::getDatabase('cough_test1');
544- $this->assertReference($test1Db, $test1DbReference);
545- $this->assertIdentical($test1Db, $test1DbReference);
546+ $this->assertSame($test1Db, $test1DbReference);
547 $this->assertFalse($test2Db === $test1DbReference);
548 // $this->assertFalse($test3Db === $test1DbReference);
549 }
550
551=== renamed file 'tests/cough/TestCoughInstancePool.class.php' => 'tests/cough/CoughInstancePoolTest.class.php'
552--- tests/cough/TestCoughInstancePool.class.php 2008-08-21 04:18:31 +0000
553+++ tests/cough/CoughInstancePoolTest.class.php 2010-12-15 07:59:33 +0000
554@@ -1,8 +1,7 @@
555 <?php
556-
557-class TestCoughInstancePool extends UnitTestCase
558+class CoughInstancePoolTest extends PHPUnit_Framework_TestCase
559 {
560- public function __construct()
561+ public static function setUpBeforeClass()
562 {
563 $coughRoot = dirname(dirname(dirname(__FILE__)));
564 require_once($coughRoot . '/cough/load.inc.php');
565@@ -31,7 +30,7 @@
566 $this->assertTrue(CoughInstancePool::get('InstancePoolTestObject', $obj->getKeyId()) instanceof InstancePoolTestObject);
567
568 // the item should be a reference to the same thing we gave it
569- $this->assertIdentical($obj, CoughInstancePool::get('InstancePoolTestObject', $obj->getKeyId()));
570+ $this->assertSame($obj, CoughInstancePool::get('InstancePoolTestObject', $obj->getKeyId()));
571
572 // the item should be removeable by passing the object and key
573 CoughInstancePool::remove($obj, $obj->getKeyId());
574@@ -72,18 +71,18 @@
575 CoughInstancePool::add($objB2, $objB2->getKeyId());
576
577 // check they all come back good
578- $this->assertIdentical($objA1, CoughInstancePool::get(get_class($objA1), $objA1->getKeyId()));
579- $this->assertIdentical($objA2, CoughInstancePool::get(get_class($objA2), $objA2->getKeyId()));
580- $this->assertIdentical($objB1, CoughInstancePool::get(get_class($objB1), $objB1->getKeyId()));
581- $this->assertIdentical($objB2, CoughInstancePool::get(get_class($objB2), $objB2->getKeyId()));
582+ $this->assertSame($objA1, CoughInstancePool::get(get_class($objA1), $objA1->getKeyId()));
583+ $this->assertSame($objA2, CoughInstancePool::get(get_class($objA2), $objA2->getKeyId()));
584+ $this->assertSame($objB1, CoughInstancePool::get(get_class($objB1), $objB1->getKeyId()));
585+ $this->assertSame($objB2, CoughInstancePool::get(get_class($objB2), $objB2->getKeyId()));
586
587 // remove two at random and check that they are gone and the others are still good
588 CoughInstancePool::remove(get_class($objB1), $objB1->getKeyId());
589 CoughInstancePool::remove(get_class($objA2), $objA2->getKeyId());
590 $this->assertNull(CoughInstancePool::get(get_class($objB1), $objB1->getKeyId()));
591 $this->assertNull(CoughInstancePool::get(get_class($objA2), $objA2->getKeyId()));
592- $this->assertIdentical($objA1, CoughInstancePool::get(get_class($objA1), $objA1->getKeyId()));
593- $this->assertIdentical($objB2, CoughInstancePool::get(get_class($objB2), $objB2->getKeyId()));
594+ $this->assertSame($objA1, CoughInstancePool::get(get_class($objA1), $objA1->getKeyId()));
595+ $this->assertSame($objB2, CoughInstancePool::get(get_class($objB2), $objB2->getKeyId()));
596 }
597 }
598
599
600=== renamed file 'tests/cough/TestCoughObject.class.php' => 'tests/cough/CoughObjectTest.class.php' (properties changed: +x to -x)
601--- tests/cough/TestCoughObject.class.php 2009-03-24 15:16:02 +0000
602+++ tests/cough/CoughObjectTest.class.php 2010-12-15 07:59:33 +0000
603@@ -1,16 +1,14 @@
604 <?php
605-
606 /**
607- * @todo consider switching to PHPUnit, especially if it has PHP5 strict compatibility.
608 * @todo consider splitting out some of the test methods, and rename them in a
609 * way that indicates requirements rather than what it is doing. The
610- * TestAutoloader.class.php file is a good example. Once we do this, we can also
611+ * AutoloaderTest.class.php file is a good example. Once we do this, we can also
612 * benefit from concepts like Agile Documentation {@link http://www.phpunit.de/manual/3.3/en/other-uses-for-tests.html}
613 **/
614-class TestCoughObject extends UnitTestCase
615+class CoughObjectTest extends PHPUnit_Framework_TestCase
616 {
617- protected $db = null; // the database object
618- protected $coughTestDbResetSql = '';
619+ protected static $db = null; // the database object
620+ protected static $coughTestDbResetSql = '';
621
622 //////////////////////////////////////
623 // Set Up
624@@ -19,23 +17,23 @@
625 /**
626 * Some things we only need to setup once (like generate all the code from the DB)
627 **/
628- public function __construct()
629+ public static function setUpBeforeClass()
630 {
631 error_reporting(E_ALL);
632- $this->includeDependencies();
633- $this->setUpDatabase();
634- $this->loadSetupSql();
635- $this->resetCoughTestDatabase();
636- $this->generateCoughTestClasses();
637- $this->includeCoughTestClasses();
638+ self::includeDependencies();
639+ self::setUpDatabase();
640+ self::loadSetupSql();
641+ self::resetCoughTestDatabase();
642+ self::generateCoughTestClasses();
643+ self::includeCoughTestClasses();
644 }
645
646 /**
647 * Some things we only need to teardown once (like delete all the generated code)
648 **/
649- public function __destruct()
650+ public static function tearDownAfterClass()
651 {
652- $this->removeGeneratedFiles();
653+ self::removeGeneratedFiles();
654 }
655
656 /**
657@@ -45,18 +43,18 @@
658 **/
659 public function setUp()
660 {
661- $this->resetCoughTestDatabase();
662+ self::resetCoughTestDatabase();
663 }
664
665- public function resetCoughTestDatabase()
666+ public static function resetCoughTestDatabase()
667 {
668- foreach ($this->coughTestDbResetSql as $sql)
669+ foreach (self::$coughTestDbResetSql as $sql)
670 {
671- $this->db->query($sql);
672+ self::$db->query($sql);
673 }
674 }
675
676- public function setUpDatabase()
677+ public static function setUpDatabase()
678 {
679 // Use connection information from the generation config (and just add the aliases)
680 include(dirname(__FILE__) . '/config/database_schema_generator.inc.php');
681@@ -66,19 +64,19 @@
682 $testDbConfig['aliases'] = array($dbName);
683
684 CoughDatabaseFactory::addConfig($testDbConfig);
685- $this->db = CoughDatabaseFactory::getDatabase($dbName);
686+ self::$db = CoughDatabaseFactory::getDatabase($dbName);
687 }
688
689- public function loadSetupSql()
690+ public static function loadSetupSql()
691 {
692 // We have to run this sql dump one query at a time
693- $this->coughTestDbResetSql = explode(';', file_get_contents(dirname(__FILE__) . '/config/db_setup.sql'));
694+ self::$coughTestDbResetSql = explode(';', file_get_contents(dirname(__FILE__) . '/config/db_setup.sql'));
695
696 // the last element is a blank string, so get rid of it
697- array_pop($this->coughTestDbResetSql);
698+ array_pop(self::$coughTestDbResetSql);
699 }
700
701- public function includeDependencies()
702+ public static function includeDependencies()
703 {
704 // include Cough + dependencies; this should be the only include necessary
705 $coughRoot = dirname(dirname(dirname(__FILE__)));
706@@ -86,7 +84,7 @@
707 require_once($coughRoot . '/cough_generator/load.inc.php');
708 }
709
710- public function generateCoughTestClasses()
711+ public static function generateCoughTestClasses()
712 {
713 ob_start();
714 $facade = new CoughGeneratorFacade();
715@@ -94,7 +92,7 @@
716 ob_end_clean();
717 }
718
719- public function includeCoughTestClasses()
720+ public static function includeCoughTestClasses()
721 {
722 $classPath = dirname(__FILE__) . '/config/output/';
723 // include Cough generated classes
724@@ -128,7 +126,7 @@
725
726 foreach ($sqlCommands as $sql)
727 {
728- $this->db->query($sql);
729+ self::$db->query($sql);
730 }
731 }
732
733@@ -164,7 +162,7 @@
734 $newBook->setCreationDatetime(date('Y-m-d H:i:s'));
735 $newBook->save();
736
737- $this->assertIdentical($newBook->getBookId(), 1);
738+ $this->assertSame($newBook->getBookId(), 1);
739
740 // test the most basic case (insert with no values)
741 $newBook2 = new Book();
742@@ -202,9 +200,9 @@
743 $book = new Book2($data);
744 $getterData = $book->getFieldsThroughGetters();
745
746- $this->assertEqual('Your title is mine now!', $getterData['title']);
747- $this->assertEqual($data['introduction'], $getterData['introduction']);
748- $this->assertEqual($data['creation_datetime'], $getterData['creation_datetime']);
749+ $this->assertEquals('Your title is mine now!', $getterData['title']);
750+ $this->assertEquals($data['introduction'], $getterData['introduction']);
751+ $this->assertEquals($data['creation_datetime'], $getterData['creation_datetime']);
752 }
753
754 public function testSetKeyId()
755@@ -214,14 +212,14 @@
756 $book1->setKeyId(1);
757 $book2 = new Book();
758 $book2->setBookId(1);
759- $this->assertEqual($book1->getFields(), $book2->getFields());
760+ $this->assertEquals($book1->getFields(), $book2->getFields());
761
762 // do it again, but this time check the entire object state (this means we can't notify children of the change)
763 $book1 = new Book();
764 $book1->setKeyId(1, false); // false => don't notify children of key change
765 $book2 = new Book();
766 $book2->setBookId(1);
767- $this->assertEqual(serialize($book1), serialize($book2));
768+ $this->assertEquals(serialize($book1), serialize($book2));
769 }
770
771 public function testHasKeyId()
772@@ -256,17 +254,17 @@
773 $sameBook = Book::constructByKey($newBook->getBookId());
774
775 // this one fails; see ticket #27, http://trac.coughphp.com/ticket/27
776- //$this->assertIdentical($newBook->getBookId(), $sameBook->getBookId());
777- $this->assertEqual($newBook->getBookId(), $sameBook->getBookId());
778+ //$this->assertSame($newBook->getBookId(), $sameBook->getBookId());
779+ $this->assertEquals($newBook->getBookId(), $sameBook->getBookId());
780
781- $this->assertIdentical($newBook->getTitle(), $sameBook->getTitle());
782+ $this->assertSame($newBook->getTitle(), $sameBook->getTitle());
783
784 // again, this is broke; see ticket #27
785- //$this->assertIdentical($newBook->getAuthorId(), $sameBook->getAuthorId());
786- $this->assertEqual($newBook->getAuthorId(), $sameBook->getAuthorId());
787+ //$this->assertSame($newBook->getAuthorId(), $sameBook->getAuthorId());
788+ $this->assertEquals($newBook->getAuthorId(), $sameBook->getAuthorId());
789
790- $this->assertIdentical($newBook->getIntroduction(), $sameBook->getIntroduction());
791- $this->assertIdentical($newBook->getCreationDatetime(), $sameBook->getCreationDatetime());
792+ $this->assertSame($newBook->getIntroduction(), $sameBook->getIntroduction());
793+ $this->assertSame($newBook->getCreationDatetime(), $sameBook->getCreationDatetime());
794 }
795
796 public function testUpdateObject()
797@@ -278,13 +276,13 @@
798
799 $newAuthor->setName('Mark Twain');
800
801- $this->assertIdentical($newAuthor->getName(), 'Mark Twain');
802+ $this->assertSame($newAuthor->getName(), 'Mark Twain');
803
804 $newAuthor->save();
805
806 $sameAuthor = Author::constructByKey($newAuthor->getAuthorId());
807
808- $this->assertIdentical($sameAuthor->getName(), 'Mark Twain');
809+ $this->assertSame($sameAuthor->getName(), 'Mark Twain');
810 }
811
812 public function testRetireObject()
813@@ -302,7 +300,7 @@
814 // handling. It's mostly meant as a way to keep items from showing up in related
815 // collections, NOT to keep the entitity from being retrieved (just delete it in
816 // that case).
817- $this->assertIsA(Library::constructByKey($newLibrary->getLibraryId()), 'Library');
818+ $this->assertInstanceOf('Library', Library::constructByKey($newLibrary->getLibraryId()));
819 }
820
821 public function testObjectsCanBeDeletedUsingRemoveAndSave()
822@@ -348,11 +346,11 @@
823
824 $ulysses->setAuthor_Object($joyce);
825
826- $this->assertReference($ulysses->getAuthor_Object(), $joyce);
827+ $this->assertSame($ulysses->getAuthor_Object(), $joyce);
828
829 $ulysses->save();
830
831- // $this->assertNotEqual($ulysses->getAuthorId(), $joyce->getAuthorId());
832+ // $this->assertNotEquals($ulysses->getAuthorId(), $joyce->getAuthorId());
833
834 // case 2: author object saved, book is saved
835 $twain = new Author();
836@@ -368,11 +366,11 @@
837
838 $huckFinn->setAuthor_Object($twain);
839
840- $this->assertReference($huckFinn->getAuthor_Object(), $twain);
841+ $this->assertSame($huckFinn->getAuthor_Object(), $twain);
842
843 $huckFinn->save();
844
845- $this->assertNotEqual($huckFinn->getAuthorId(), $twain->getAuthorId());
846+ $this->assertNotEquals($huckFinn->getAuthorId(), $twain->getAuthorId());
847
848 // case 3: author object is anonymous, book is anonymous
849 $murakami = new Author();
850@@ -386,11 +384,11 @@
851
852 $windup->setAuthor_Object($murakami);
853
854- $this->assertReference($windup->getAuthor_Object(), $murakami);
855+ $this->assertSame($windup->getAuthor_Object(), $murakami);
856
857 $windup->save();
858
859- // $this->assertNotEqual($windup->getAuthorId(), $murakami->getAuthorId());
860+ // $this->assertNotEquals($windup->getAuthorId(), $murakami->getAuthorId());
861
862 // case 4: author object is saved, book is anonymous
863 $heinlein = new Author();
864@@ -405,11 +403,11 @@
865
866 $stranger->setAuthor_Object($heinlein);
867
868- $this->assertReference($stranger->getAuthor_Object(), $heinlein);
869+ $this->assertSame($stranger->getAuthor_Object(), $heinlein);
870
871 $stranger->save();
872
873- $this->assertNotEqual($stranger->getAuthorId(), $heinlein->getAuthorId());
874+ $this->assertNotEquals($stranger->getAuthorId(), $heinlein->getAuthorId());
875 }
876
877 public function testAddAndRemoveObject()
878@@ -427,12 +425,12 @@
879
880 $joyce->addBook($ulysses);
881 $booksByJoyce = $joyce->getBook_Collection();
882- $this->assertReference($booksByJoyce[$ulysses->getBookId()], $ulysses);
883+ $this->assertSame($booksByJoyce[$ulysses->getBookId()], $ulysses);
884
885 $joyce->save();
886
887- $this->assertEqual($ulysses->getAuthorId(), $joyce->getAuthorId());
888- $this->assertIdentical($ulysses->getAuthor_Object(), $joyce);
889+ $this->assertEquals($ulysses->getAuthorId(), $joyce->getAuthorId());
890+ $this->assertSame($ulysses->getAuthor_Object(), $joyce);
891
892 // case 2: author object saved, book is saved
893 $twain = new Author();
894@@ -448,12 +446,12 @@
895
896 $twain->addBook($huckFinn);
897 $booksByTwain = $twain->getBook_Collection();
898- $this->assertReference($booksByTwain[$huckFinn->getBookId()], $huckFinn);
899+ $this->assertSame($booksByTwain[$huckFinn->getBookId()], $huckFinn);
900
901 $twain->save();
902
903- $this->assertEqual($huckFinn->getAuthorId(), $twain->getAuthorId());
904- $this->assertIdentical($huckFinn->getAuthor_Object(), $twain);
905+ $this->assertEquals($huckFinn->getAuthorId(), $twain->getAuthorId());
906+ $this->assertSame($huckFinn->getAuthor_Object(), $twain);
907
908 // case 3: author object anonymous, book is anonymous
909 $murakami = new Author();
910@@ -467,19 +465,19 @@
911
912 $murakami->addBook($windup);
913 $booksByMurakami = $murakami->getBook_Collection();
914- $this->assertReference($booksByMurakami->getPosition(0), $windup);
915+ $this->assertSame($booksByMurakami->getPosition(0), $windup);
916
917 $murakami->save();
918
919- $this->assertEqual($windup->getAuthorId(), $murakami->getAuthorId());
920- $this->assertIdentical($windup->getAuthor_Object(), $murakami);
921+ $this->assertEquals($windup->getAuthorId(), $murakami->getAuthorId());
922+ $this->assertSame($windup->getAuthor_Object(), $murakami);
923
924 $this->resetCoughTestDatabase();
925
926 $twain->save();
927
928- $this->assertEqual($huckFinn->getAuthorId(), $twain->getAuthorId());
929- $this->assertIdentical($huckFinn->getAuthor_Object(), $twain);
930+ $this->assertEquals($huckFinn->getAuthorId(), $twain->getAuthorId());
931+ $this->assertSame($huckFinn->getAuthor_Object(), $twain);
932
933 // case 4: author object is saved, book is anonymous
934 $heinlein = new Author();
935@@ -494,12 +492,12 @@
936
937 $heinlein->addBook($stranger);
938 $booksByHeinlein = $heinlein->getBook_Collection();
939- $this->assertReference($booksByHeinlein->getPosition(0), $stranger);
940+ $this->assertSame($booksByHeinlein->getPosition(0), $stranger);
941
942 $heinlein->save();
943
944- $this->assertEqual($stranger->getAuthorId(), $heinlein->getAuthorId());
945- $this->assertIdentical($stranger->getAuthor_Object(), $heinlein);
946+ $this->assertEquals($stranger->getAuthorId(), $heinlein->getAuthorId());
947+ $this->assertSame($stranger->getAuthor_Object(), $heinlein);
948
949 // test remove object
950
951@@ -524,29 +522,29 @@
952 $author->addBook($book);
953 $author->addBook($book2);
954
955- $this->assertEqual(count($author->getBook_Collection()), 2);
956+ $this->assertEquals(count($author->getBook_Collection()), 2);
957
958 // $book2library = new Book2library();
959 // $book2library->setLibrary_Object($library);
960 // $book->addBook2library($book2library);
961 // $book2->addBook2library($book2library);
962
963- // $this->db->getDb()->startLoggingQueries();
964+ // self::$db->getDb()->startLoggingQueries();
965
966 $author->save();
967
968 // $this->dump($author->getBook_Collection());
969- // print_r($this->db->getDb()->getQueryLog());
970+ // print_r(self::$db->getDb()->getQueryLog());
971
972 $this->assertNotNull($author->getAuthorId());
973
974 $this->assertNotNull($book->getBookId());
975 $this->assertNotNull($book->getAuthorId());
976- $this->assertIdentical($book->getAuthorId(), $author->getAuthorId());
977+ $this->assertSame($book->getAuthorId(), $author->getAuthorId());
978
979 $this->assertNotNull($book2->getBookId());
980 $this->assertNotNull($book2->getAuthorId());
981- $this->assertIdentical($book2->getAuthorId(), $author->getAuthorId());
982+ $this->assertSame($book2->getAuthorId(), $author->getAuthorId());
983 }
984
985 public function testManyToMany()
986@@ -600,7 +598,7 @@
987 $sameLibrary = Library::constructByKey($library->getLibraryId());
988 $bookJoinsInTravis = $sameLibrary->getBook2library_Collection();
989 // $this->dump($bookJoinsInTravis);
990- $this->assertEqual(count($bookJoinsInTravis), 2);
991+ $this->assertEquals(count($bookJoinsInTravis), 2);
992
993 // This test is similar to the 4 that are commented out below, but this shows what is different
994 // AND it ignores the creation_datetime and last_modified_datetime differences b/c they are
995@@ -623,23 +621,23 @@
996
997 // these fail because the $book and $book2 don't have some default values set after save like creation_datetime
998 // (which is intentional; call load() after save if you want to get the updated data.)
999- // $this->assertIdentical($bookJoinsInTravis->getPosition(0)->getBook_Object(), $book);
1000- // $this->assertIdentical($bookJoinsInTravis->getPosition(1)->getBook_Object(), $book2);
1001+ // $this->assertSame($bookJoinsInTravis->getPosition(0)->getBook_Object(), $book);
1002+ // $this->assertSame($bookJoinsInTravis->getPosition(1)->getBook_Object(), $book2);
1003
1004- $this->assertEqual($bookJoinsInTravis->getPosition(0)->getBook_Object()->getBookId(), $book->getBookId());
1005- $this->assertEqual($bookJoinsInTravis->getPosition(1)->getBook_Object()->getBookId(), $book2->getBookId());
1006+ $this->assertEquals($bookJoinsInTravis->getPosition(0)->getBook_Object()->getBookId(), $book->getBookId());
1007+ $this->assertEquals($bookJoinsInTravis->getPosition(1)->getBook_Object()->getBookId(), $book2->getBookId());
1008
1009 $sameLibrary2 = Library::constructByKey($library2->getLibraryId());
1010 $bookJoinsInLbj = $sameLibrary2->getBook2library_Collection();
1011- $this->assertEqual(count($bookJoinsInLbj), 2);
1012+ $this->assertEquals(count($bookJoinsInLbj), 2);
1013
1014 // these fail because the $book and $book2 don't have some default values set after save like creation_datetime
1015 // (which is intentional; call load() after save if you want to get the updated data.)
1016- // $this->assertIdentical($bookJoinsInLbj->getPosition(0)->getBook_Object(), $book);
1017- // $this->assertIdentical($bookJoinsInLbj->getPosition(1)->getBook_Object(), $book2);
1018+ // $this->assertSame($bookJoinsInLbj->getPosition(0)->getBook_Object(), $book);
1019+ // $this->assertSame($bookJoinsInLbj->getPosition(1)->getBook_Object(), $book2);
1020
1021- $this->assertEqual($bookJoinsInLbj->getPosition(0)->getBook_Object()->getBookId(), $book->getBookId());
1022- $this->assertEqual($bookJoinsInLbj->getPosition(1)->getBook_Object()->getBookId(), $book2->getBookId());
1023+ $this->assertEquals($bookJoinsInLbj->getPosition(0)->getBook_Object()->getBookId(), $book->getBookId());
1024+ $this->assertEquals($bookJoinsInLbj->getPosition(1)->getBook_Object()->getBookId(), $book2->getBookId());
1025 }
1026
1027 public function testTransactions()
1028@@ -658,7 +656,7 @@
1029 $authors = new Author_Collection();
1030 $authors->load();
1031
1032- $this->assertEqual(count($authors), 1);
1033+ $this->assertEquals(count($authors), 1);
1034 }
1035
1036 public function getFieldMismatches($object1, $object2)
1037
1038=== renamed file 'tests/cough_generator/TestCoughGenerator.class.php' => 'tests/cough_generator/CoughGeneratorTest.class.php'
1039--- tests/cough_generator/TestCoughGenerator.class.php 2009-03-24 15:16:02 +0000
1040+++ tests/cough_generator/CoughGeneratorTest.class.php 2010-12-15 07:59:33 +0000
1041@@ -1,5 +1,4 @@
1042 <?php
1043-
1044 /**
1045 * This unit test's goal is to take three pieces of information (db_setup,
1046 * generator_config, and expected_output) and ensure that the given db_setup and
1047@@ -33,11 +32,11 @@
1048 * @package tests
1049 * @author Anthony Bush
1050 **/
1051-class TestCoughGenerator extends UnitTestCase
1052+class CoughGeneratorTest extends PHPUnit_Framework_TestCase
1053 {
1054- protected $db = null;
1055+ protected static $db = null;
1056
1057- public function __construct()
1058+ public static function setUpBeforeClass()
1059 {
1060 // include cough generator, core cough, and the as_database DAL.
1061 $coughRoot = dirname(dirname(dirname(__FILE__)));
1062@@ -51,10 +50,10 @@
1063 CoughDatabaseFactory::addConfig($coughDbConfig);
1064
1065 // Cache the db object for rest of tests
1066- $this->db = CoughDatabaseFactory::getDatabase($dsn['db_name']);
1067-
1068+ self::$db = CoughDatabaseFactory::getDatabase($dsn['db_name']);
1069+ self::$db->selectDb($dsn['db_name']);
1070 // Clean DB before start
1071- $this->dropAllTables();
1072+ self::dropAllTables();
1073 }
1074
1075 public function executeSqlFile($sqlFile)
1076@@ -66,7 +65,7 @@
1077 array_pop($sqlCommands);
1078
1079 foreach ($sqlCommands as $sql) {
1080- $this->db->query($sql);
1081+ self::$db->query($sql);
1082 }
1083 }
1084
1085@@ -87,12 +86,12 @@
1086 rmdir($classPath);
1087 }
1088
1089- protected function dropAllTables()
1090+ protected static function dropAllTables()
1091 {
1092- $result = $this->db->query('SHOW TABLES');
1093+ $result = self::$db->query('SHOW TABLES');
1094 while ($row = $result->getRow())
1095 {
1096- $this->db->query('DROP TABLE IF EXISTS ' . $this->db->backtick($row['Tables_in_test_cough_object']));
1097+ self::$db->query('DROP TABLE IF EXISTS ' . self::$db->backtick($row['Tables_in_test_cough_object']));
1098 }
1099 }
1100
1101
1102=== renamed file 'tests/dal/TestCoughAsDatabase.class.php' => 'tests/dal/CoughAsDatabaseTest.class.php'
1103--- tests/dal/TestCoughAsDatabase.class.php 2009-03-24 15:02:40 +0000
1104+++ tests/dal/CoughAsDatabaseTest.class.php 2010-12-15 07:59:33 +0000
1105@@ -1,38 +1,37 @@
1106 <?php
1107-
1108-class TestCoughAsDatabase extends UnitTestCase
1109+class CoughAsDatabaseTest extends PHPUnit_Framework_TestCase
1110 {
1111 //////////////////////////////////////
1112 // Set Up
1113 //////////////////////////////////////
1114
1115- protected $db = null;
1116- protected $adapterName = 'as';
1117- protected $resultObjectClassName = 'As_DatabaseResult';
1118+ protected static $db = null;
1119+ protected static $adapterName = 'as';
1120+ protected static $resultObjectClassName = 'As_DatabaseResult';
1121
1122- public function __construct()
1123+ public static function setUpBeforeClass()
1124 {
1125 // include core cough, and the as_database DAL.
1126 require_once(dirname(dirname(dirname(__FILE__))) . '/cough/load.inc.php');
1127- $this->loadAdapterModule();
1128- $this->initDatabase();
1129+ self::loadAdapterModule();
1130+ self::initDatabase();
1131 }
1132
1133- public function loadAdapterModule()
1134+ public static function loadAdapterModule()
1135 {
1136 require_once(dirname(dirname(dirname(__FILE__))) . '/as_database2/load.inc.php');
1137 }
1138
1139- public function initDatabase()
1140+ public static function initDatabase()
1141 {
1142 // setup database
1143 require(dirname(dirname(__FILE__)) . '/database_config.inc.php');
1144 $testDbConfig = $dsn;
1145- $testDbConfig['adapter'] = $this->adapterName;
1146+ $testDbConfig['adapter'] = self::$adapterName;
1147 $testDbConfig['aliases'] = array($dsn['db_name']);
1148 CoughDatabaseFactory::reset();
1149 CoughDatabaseFactory::addConfig($testDbConfig);
1150- $this->db = CoughDatabaseFactory::getDatabase($dsn['db_name']);
1151+ self::$db = CoughDatabaseFactory::getDatabase($dsn['db_name']);
1152 }
1153
1154 public function executeSqlFile($sqlFile)
1155@@ -44,7 +43,7 @@
1156 array_pop($sqlCommands);
1157
1158 foreach ($sqlCommands as $sql) {
1159- $this->db->execute($sql);
1160+ self::$db->execute($sql);
1161 }
1162 }
1163
1164@@ -78,8 +77,8 @@
1165
1166 public function testQuery()
1167 {
1168- $result = $this->db->query('SELECT * FROM person');
1169- $this->assertIsA($result, $this->resultObjectClassName);
1170+ $result = self::$db->query('SELECT * FROM person');
1171+ $this->assertInstanceOf(self::$resultObjectClassName, $result);
1172 $expectedRows = array(
1173 '0' => array(
1174 'person_id' => '1',
1175@@ -102,25 +101,25 @@
1176 'political_party_id' => '99'
1177 )
1178 );
1179- $this->assertIdentical($result->getRows(), $expectedRows);
1180+ $this->assertSame($result->getRows(), $expectedRows);
1181
1182 // test empty result
1183- $result = $this->db->query('SELECT * FROM school_type_empty_table');
1184- $this->assertIdentical($result->getRows(), array());
1185+ $result = self::$db->query('SELECT * FROM school_type_empty_table');
1186+ $this->assertSame($result->getRows(), array());
1187
1188 // test derived field name
1189- $result = $this->db->query('SELECT 3306 AS `port`');
1190+ $result = self::$db->query('SELECT 3306 AS `port`');
1191 $expectedRows = array(array(
1192 'port' => '3306'
1193 ));
1194- $this->assertIdentical($result->getRows(), $expectedRows);
1195+ $this->assertSame($result->getRows(), $expectedRows);
1196
1197 // test select mysql function
1198- $result = $this->db->query('SELECT COUNT(*) FROM person');
1199+ $result = self::$db->query('SELECT COUNT(*) FROM person');
1200 $expectedRows = array(array(
1201 'COUNT(*)' => '3'
1202 ));
1203- $this->assertIdentical($result->getRows(), $expectedRows);
1204+ $this->assertSame($result->getRows(), $expectedRows);
1205 }
1206
1207 public function testExecute()
1208@@ -128,30 +127,30 @@
1209 // test getLastInsertId before we have done any inserts
1210 // NOTE: PDO returns string "0" and As_Database returns integer 0... I would prefer the return value to be
1211 // null, but perhaps this is not a meaningful issue
1212- //$this->assertNull($this->db->getLastInsertId()); // currently fails
1213- $this->assertEqual($this->db->getLastInsertId(), 0);
1214+ //$this->assertNull(self::$db->getLastInsertId()); // currently fails
1215+ $this->assertEquals(self::$db->getLastInsertId(), 0);
1216
1217 // test execute insert
1218- $numAffected = $this->db->execute("INSERT person VALUES ('', 'Venkman', 0, 3)");
1219- $this->assertIdentical($numAffected, 1);
1220+ $numAffected = self::$db->execute("INSERT person VALUES ('', 'Venkman', 0, 3)");
1221+ $this->assertSame($numAffected, 1);
1222
1223 // test getLastInsertId
1224 // NOTE: PDO returns string 12, but As_Database returns integer 12... this may or may not be a discrepancy that
1225 // needs to be resolved
1226- $venkmanPersonId = $this->db->getLastInsertId();
1227- //$this->assertIdentical($venkmanPersonId, 12); // currently fails
1228- $this->assertEqual($venkmanPersonId, 12);
1229+ $venkmanPersonId = self::$db->getLastInsertId();
1230+ //$this->assertSame($venkmanPersonId, 12); // currently fails
1231+ $this->assertEquals($venkmanPersonId, 12);
1232
1233 // test insert succeeded
1234- $result = $this->db->getResult('SELECT person.name FROM person WHERE person.person_id = 12');
1235- $this->assertIdentical($result, 'Venkman');
1236+ $result = self::$db->getResult('SELECT person.name FROM person WHERE person.person_id = 12');
1237+ $this->assertSame($result, 'Venkman');
1238
1239 // test execute update
1240- $numAffected = $this->db->execute('UPDATE person SET political_party_id = 4 WHERE political_party_id = 2');
1241- $this->assertIdentical($numAffected, 2);
1242+ $numAffected = self::$db->execute('UPDATE person SET political_party_id = 4 WHERE political_party_id = 2');
1243+ $this->assertSame($numAffected, 2);
1244
1245 // test update succeeded
1246- $result = $this->db->query('SELECT name FROM person WHERE political_party_id = 4');
1247+ $result = self::$db->query('SELECT name FROM person WHERE political_party_id = 4');
1248 $expectedRows = array(
1249 '0' => array(
1250 'name' => 'Anthony'
1251@@ -161,34 +160,34 @@
1252 'name' => 'Lewis'
1253 )
1254 );
1255- $this->assertIdentical($result->getRows(), $expectedRows);
1256+ $this->assertSame($result->getRows(), $expectedRows);
1257
1258 // test execute delete
1259- $numAffected = $this->db->execute('DELETE FROM person WHERE is_retired = 0');
1260- $this->assertIdentical($numAffected, 4);
1261+ $numAffected = self::$db->execute('DELETE FROM person WHERE is_retired = 0');
1262+ $this->assertSame($numAffected, 4);
1263
1264 // test delete succeeded
1265- $result = $this->db->getResult('SELECT COUNT(*) FROM person');
1266- $this->assertIdentical($result, '0');
1267+ $result = self::$db->getResult('SELECT COUNT(*) FROM person');
1268+ $this->assertSame($result, '0');
1269 }
1270
1271 public function testQuote()
1272 {
1273 // Test handling of magic_quotes_gpc (lack thereof), and escaping of characters
1274 $acidString = "\000\n\r\032!@#^%&!@^%#!*@&#!()))()!( . . . ..\\\\.\\\" \\' // /./ x?? ddfsdfdsf je;;ee //.. ,, SELECT * FROM person balhhh )";
1275- $quotedString = $this->db->quote($acidString);
1276+ $quotedString = self::$db->quote($acidString);
1277 $sql = 'UPDATE person SET person.name = ' . $quotedString;
1278- $this->db->execute($sql);
1279+ self::$db->execute($sql);
1280
1281 // Not all DB layers support LIMIT
1282 // $sql = 'SELECT person.name FROM person LIMIT 1';
1283- $sql = $this->db->getSelectQuery();
1284+ $sql = self::$db->getSelectQuery();
1285 $sql->setSelect('person.name');
1286 $sql->setFrom('person');
1287 $sql->setLimit(1);
1288
1289- $returnedString = $this->db->getResult($sql);
1290- $this->assertEqual($acidString, $returnedString);
1291+ $returnedString = self::$db->getResult($sql);
1292+ $this->assertEquals($acidString, $returnedString);
1293 }
1294 }
1295
1296
1297=== modified file 'tests/database_config.inc.php'
1298--- tests/database_config.inc.php 2008-11-13 03:44:26 +0000
1299+++ tests/database_config.inc.php 2010-12-15 07:59:33 +0000
1300@@ -8,16 +8,22 @@
1301 * <code>
1302 * CREATE DATABASE test_cough_object;
1303 * GRANT USAGE ON `test_cough_object`.* TO `cough_test`@`localhost` IDENTIFIED BY 'cough_test';
1304+ * CREATE DATABASE reports;
1305+ * GRANT USAGE ON `reports`.* TO `cough_test`@`localhost` IDENTIFIED BY 'cough_test';
1306+ * CREATE DATABASE actual_db_name;
1307+ * GRANT USAGE ON `actual_db_name`.* TO `cough_test`@`localhost` IDENTIFIED BY 'cough_test';
1308+ * CREATE DATABASE testConfigAlias;
1309+ * GRANT USAGE ON `testConfigAlias`.* TO `cough_test`@`localhost` IDENTIFIED BY 'cough_test';
1310 * FLUSH PRIVILEGES;
1311 * </code>
1312 *
1313 * @var array
1314 **/
1315 $dsn = array(
1316- 'host' => 'localhost',
1317+ 'host' => '',
1318 'user' => 'cough_test',
1319 'pass' => 'cough_test',
1320- 'port' => 3306,
1321+ 'port' => ':/tmp/mysql.sock',
1322 'driver' => 'mysql',
1323 'db_name' => 'test_cough_object',
1324 );
1325
1326=== added file 'tests/phpunit-after.xml'
1327--- tests/phpunit-after.xml 1970-01-01 00:00:00 +0000
1328+++ tests/phpunit-after.xml 2010-12-15 07:59:33 +0000
1329@@ -0,0 +1,8 @@
1330+<phpunit>
1331+ <testsuites>
1332+ <testsuite name="Autoloader Cache File Test Suite">
1333+ <directory>autoloader/*Test.class.php files</directory>
1334+ <file>autoloader/AutoloaderCacheFileTest.class.php</file>
1335+ </testsuite>
1336+ </testsuites>
1337+</phpunit>
1338\ No newline at end of file
1339
1340=== added file 'tests/phpunit.xml'
1341--- tests/phpunit.xml 1970-01-01 00:00:00 +0000
1342+++ tests/phpunit.xml 2010-12-15 07:59:33 +0000
1343@@ -0,0 +1,23 @@
1344+<phpunit>
1345+ <testsuites>
1346+ <testsuite name="CoughPHP Test Suite">
1347+ <directory>cough/*Test.class.php files</directory>
1348+ <file>cough/CoughCollectionTest.class.php</file>
1349+ <file>cough/CoughDatabaseFactoryTest.class.php</file>
1350+ <file>cough/CoughInstancePoolTest.class.php</file>
1351+ <file>cough/CoughObjectTest.class.php</file>
1352+ </testsuite>
1353+ <testsuite name="CoughPHP Generator Test Suite">
1354+ <directory>cough_generator/*Test.class.php files</directory>
1355+ <file>cough_generator/CoughGeneratorTest.class.php</file>
1356+ </testsuite>
1357+ <testsuite name="CoughPHP DAL Test Suite">
1358+ <directory>dal/*Test.class.php files</directory>
1359+ <file>dal/CoughAsDatabaseTest.class.php</file>
1360+ </testsuite>
1361+ <testsuite name="Autoloader Test Suite">
1362+ <directory>autoloader/*Test.class.php files</directory>
1363+ <file>autoloader/AutoloaderTest.class.php</file>
1364+ </testsuite>
1365+ </testsuites>
1366+</phpunit>
1367\ No newline at end of file

Subscribers

People subscribed via source and target branches