Skip to content

Commit 1cdc0ac

Browse files
committed
Merge pull request #134 from AlexeyDsov/testUp
DAOTest splitted to more Test classes in new db directory
2 parents 34f6d40 + 90c3eb8 commit 1cdc0ac

20 files changed

+1220
-1092
lines changed

doc/ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2012-09-16 Alexey S. Denisov
2+
* DAOTest splitted to more Test classes in new db directory
3+
14
2012-09-12 Alexey S. Denisov
25
* main/Net/GenericUri.class.php
36
main/Net/HttpUrl.class.php

test/AllTests.php

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<?php
2-
/* $Id$ */
3-
42
if (!extension_loaded('onphp')) {
53
echo 'Trying to load onPHP extension.. ';
64

@@ -11,32 +9,36 @@
119
}
1210
}
1311

14-
$config = dirname(__FILE__).'/config.inc.php';
12+
date_default_timezone_set('Europe/Moscow');
13+
define('ONPHP_TEST_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
1514

16-
include is_readable($config) ? $config : $config.'.tpl';
15+
require ONPHP_TEST_PATH.'../global.inc.php.tpl';
1716

18-
// provide fake spooked class
19-
class Spook extends IdentifiableObject {/*_*/}
17+
define('ENCODING', 'UTF-8');
2018

21-
final class TestSuite extends PHPUnit_Framework_TestSuite
22-
{
23-
public function setUp()
24-
{
25-
if (AllTests::$workers) {
26-
$worker = array_pop(AllTests::$workers);
27-
echo "\nProcessing with {$worker}\n";
28-
Cache::dropWorkers();
29-
Cache::setDefaultWorker($worker);
30-
} else {
31-
$this->markTestSuiteSkipped('No more workers available.');
32-
}
33-
}
34-
35-
public function tearDown()
36-
{
37-
echo "\n";
38-
}
39-
}
19+
mb_internal_encoding(ENCODING);
20+
mb_regex_encoding(ENCODING);
21+
22+
set_include_path(
23+
// current path
24+
get_include_path().PATH_SEPARATOR
25+
.ONPHP_TEST_PATH.'misc'.PATH_SEPARATOR
26+
);
27+
28+
$testPathes = array(
29+
ONPHP_TEST_PATH.'core'.DIRECTORY_SEPARATOR,
30+
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR,
31+
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Ip'.DIRECTORY_SEPARATOR,
32+
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Net'.DIRECTORY_SEPARATOR,
33+
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR,
34+
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR.'Routers'.DIRECTORY_SEPARATOR,
35+
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR.'AMQP'.DIRECTORY_SEPARATOR,
36+
ONPHP_TEST_PATH.'db'.DIRECTORY_SEPARATOR,
37+
);
38+
39+
$config = dirname(__FILE__).'/config.inc.php';
40+
41+
include is_readable($config) ? $config : $config.'.tpl';
4042

4143
final class AllTests
4244
{
@@ -53,13 +55,12 @@ public static function suite()
5355
{
5456
$suite = new TestSuite('onPHP-'.ONPHP_VERSION);
5557

56-
foreach (self::$paths as $testPath)
57-
foreach (glob($testPath.'*Test'.EXT_CLASS, GLOB_BRACE) as $file)
58-
$suite->addTestFile($file);
59-
6058
// meta, DB and DAOs ordered tests portion
6159
if (self::$dbs) {
6260
try {
61+
/**
62+
* @todo fail - constructor with argument, but static method 'me' - without
63+
*/
6364
Singleton::getInstance('DBTestPool', self::$dbs)->connect();
6465
} catch (Exception $e) {
6566
Singleton::dropInstance('DBTestPool');
@@ -97,7 +98,9 @@ public static function suite()
9798
.ONPHP_META_PROTO_DIR
9899
);
99100

100-
$daoTest = new DAOTest();
101+
$dBCreator = DBTestCreator::create()->
102+
setSchemaPath(ONPHP_META_AUTO_DIR.'schema.php')->
103+
setTestPool(DBTestPool::me());
101104

102105
$out = MetaConfiguration::me()->getOutput();
103106

@@ -109,24 +112,22 @@ public static function suite()
109112
info(get_class($db), true)->
110113
infoLine(' connector.');
111114

112-
try {
113-
$daoTest->drop();
114-
} catch (DatabaseException $e) {
115-
// previous shutdown was clean
116-
}
115+
$dBCreator->dropDB(true);
117116

118-
$daoTest->create()->fill(false);
117+
$dBCreator->createDB()->fillDB();
119118

120119
MetaConfiguration::me()->checkIntegrity();
121120
$out->newLine();
122121

123-
$daoTest->drop();
122+
$dBCreator->dropDB();
124123
}
125124

126125
DBPool::me()->dropDefault();
127126
}
128127

129-
$suite->addTestSuite('DAOTest');
128+
foreach (self::$paths as $testPath)
129+
foreach (glob($testPath.'*Test'.EXT_CLASS, GLOB_BRACE) as $file)
130+
$suite->addTestFile($file);
130131

131132
return $suite;
132133
}

test/config.inc.php.tpl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,4 @@
11
<?php
2-
date_default_timezone_set('Europe/Moscow');
3-
define('ONPHP_TEST_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
4-
5-
require ONPHP_TEST_PATH.'../global.inc.php.tpl';
6-
7-
define('ENCODING', 'UTF-8');
8-
9-
mb_internal_encoding(ENCODING);
10-
mb_regex_encoding(ENCODING);
11-
12-
set_include_path(
13-
// current path
14-
get_include_path().PATH_SEPARATOR
15-
.ONPHP_TEST_PATH.'misc'.PATH_SEPARATOR
16-
);
17-
18-
$testPathes = array(
19-
ONPHP_TEST_PATH.'core'.DIRECTORY_SEPARATOR,
20-
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR,
21-
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Ip'.DIRECTORY_SEPARATOR,
22-
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Net'.DIRECTORY_SEPARATOR,
23-
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR,
24-
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR.'Routers'.DIRECTORY_SEPARATOR,
25-
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR.'AMQP'.DIRECTORY_SEPARATOR,
26-
);
272

283
$dbs = array(
294
'PgSQL' => array(
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
class CacheAndLazyDBTest extends TestCaseDAO
3+
{
4+
public function testWorkingWithCache()
5+
{
6+
foreach (DBTestPool::me()->getPool() as $db) {
7+
DBPool::me()->setDefault($db);
8+
9+
$item =
10+
TestItem::create()->
11+
setName('testItem1');
12+
13+
TestItem::dao()->add($item);
14+
15+
$encapsulant =
16+
TestEncapsulant::create()->
17+
setName('testEncapsulant1');
18+
19+
TestEncapsulant::dao()->add($encapsulant);
20+
21+
$subItem1 =
22+
TestSubItem::create()->
23+
setName('testSubItem1')->
24+
setEncapsulant($encapsulant)->
25+
setItem($item);
26+
27+
$subItem2 =
28+
TestSubItem::create()->
29+
setName('testSubItem2')->
30+
setEncapsulant($encapsulant)->
31+
setItem($item);
32+
33+
TestSubItem::dao()->add($subItem1);
34+
TestSubItem::dao()->add($subItem2);
35+
36+
$items =
37+
Criteria::create(TestItem::dao())->
38+
getList();
39+
40+
foreach ($items as $item) {
41+
foreach ($item->getSubItems()->getList() as $subItem) {
42+
$this->assertEquals(
43+
$subItem->getEncapsulant()->getName(),
44+
'testEncapsulant1'
45+
);
46+
}
47+
}
48+
49+
$encapsulant = TestEncapsulant::dao()->getById(1);
50+
51+
$encapsulant->setName('testEncapsulant1_changed');
52+
53+
TestEncapsulant::dao()->save($encapsulant);
54+
55+
// drop identityMap
56+
TestEncapsulant::dao()->dropIdentityMap();
57+
TestSubItem::dao()->dropIdentityMap();
58+
TestItem::dao()->dropIdentityMap();
59+
60+
$items =
61+
Criteria::create(TestItem::dao())->
62+
getList();
63+
64+
foreach ($items as $item) {
65+
foreach ($item->getSubItems()->getList() as $subItem) {
66+
$this->assertEquals(
67+
$subItem->getEncapsulant()->getName(),
68+
'testEncapsulant1_changed'
69+
);
70+
}
71+
}
72+
73+
// drop identityMap
74+
TestEncapsulant::dao()->dropIdentityMap();
75+
TestSubItem::dao()->dropIdentityMap();
76+
TestItem::dao()->dropIdentityMap();
77+
78+
$subItem = TestSubItem::dao()->getById(1);
79+
80+
$this->assertEquals(
81+
$subItem->getEncapsulant()->getName(),
82+
'testEncapsulant1_changed'
83+
);
84+
85+
// drop identityMap
86+
TestEncapsulant::dao()->dropIdentityMap();
87+
TestSubItem::dao()->dropIdentityMap();
88+
TestItem::dao()->dropIdentityMap();
89+
90+
$subItems =
91+
Criteria::create(TestSubItem::dao())->
92+
getList();
93+
94+
foreach ($subItems as $subItem) {
95+
$this->assertEquals(
96+
$subItem->getEncapsulant()->getName(),
97+
'testEncapsulant1_changed'
98+
);
99+
}
100+
}
101+
}
102+
103+
public function testLazy()
104+
{
105+
foreach (DBTestPool::me()->getPool() as $db) {
106+
DBPool::me()->setDefault($db);
107+
108+
$parent = TestParentObject::create();
109+
$child = TestChildObject::create()->setParent($parent);
110+
111+
$parent->dao()->add($parent);
112+
113+
$child->dao()->add($child);
114+
115+
$this->assertEquals(
116+
$parent->getId(),
117+
Criteria::create(TestChildObject::dao())->
118+
setProjection(
119+
Projection::property('parent.id', 'parentId')
120+
)->
121+
add(Expression::eq('id', $child->getId()))->
122+
getCustom('parentId')
123+
);
124+
}
125+
}
126+
}
127+
?>

0 commit comments

Comments
 (0)