Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2012-09-16 Alexey S. Denisov
* DAOTest splitted to more Test classes in new db directory

2012-09-12 Alexey S. Denisov
* main/Net/GenericUri.class.php
main/Net/HttpUrl.class.php
Expand Down
77 changes: 39 additions & 38 deletions test/AllTests.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
/* $Id$ */

if (!extension_loaded('onphp')) {
echo 'Trying to load onPHP extension.. ';

Expand All @@ -11,32 +9,36 @@
}
}

$config = dirname(__FILE__).'/config.inc.php';
date_default_timezone_set('Europe/Moscow');
define('ONPHP_TEST_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);

include is_readable($config) ? $config : $config.'.tpl';
require ONPHP_TEST_PATH.'../global.inc.php.tpl';

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

final class TestSuite extends PHPUnit_Framework_TestSuite
{
public function setUp()
{
if (AllTests::$workers) {
$worker = array_pop(AllTests::$workers);
echo "\nProcessing with {$worker}\n";
Cache::dropWorkers();
Cache::setDefaultWorker($worker);
} else {
$this->markTestSuiteSkipped('No more workers available.');
}
}

public function tearDown()
{
echo "\n";
}
}
mb_internal_encoding(ENCODING);
mb_regex_encoding(ENCODING);

set_include_path(
// current path
get_include_path().PATH_SEPARATOR
.ONPHP_TEST_PATH.'misc'.PATH_SEPARATOR
);

$testPathes = array(
ONPHP_TEST_PATH.'core'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Ip'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Net'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR.'Routers'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR.'AMQP'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'db'.DIRECTORY_SEPARATOR,
);

$config = dirname(__FILE__).'/config.inc.php';

include is_readable($config) ? $config : $config.'.tpl';

final class AllTests
{
Expand All @@ -53,13 +55,12 @@ public static function suite()
{
$suite = new TestSuite('onPHP-'.ONPHP_VERSION);

foreach (self::$paths as $testPath)
foreach (glob($testPath.'*Test'.EXT_CLASS, GLOB_BRACE) as $file)
$suite->addTestFile($file);

// meta, DB and DAOs ordered tests portion
if (self::$dbs) {
try {
/**
* @todo fail - constructor with argument, but static method 'me' - without
*/
Singleton::getInstance('DBTestPool', self::$dbs)->connect();
} catch (Exception $e) {
Singleton::dropInstance('DBTestPool');
Expand Down Expand Up @@ -97,7 +98,9 @@ public static function suite()
.ONPHP_META_PROTO_DIR
);

$daoTest = new DAOTest();
$dBCreator = DBTestCreator::create()->
setSchemaPath(ONPHP_META_AUTO_DIR.'schema.php')->
setTestPool(DBTestPool::me());

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

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

try {
$daoTest->drop();
} catch (DatabaseException $e) {
// previous shutdown was clean
}
$dBCreator->dropDB(true);

$daoTest->create()->fill(false);
$dBCreator->createDB()->fillDB();

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

$daoTest->drop();
$dBCreator->dropDB();
}

DBPool::me()->dropDefault();
}

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

return $suite;
}
Expand Down
25 changes: 0 additions & 25 deletions test/config.inc.php.tpl
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
<?php
date_default_timezone_set('Europe/Moscow');
define('ONPHP_TEST_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);

require ONPHP_TEST_PATH.'../global.inc.php.tpl';

define('ENCODING', 'UTF-8');

mb_internal_encoding(ENCODING);
mb_regex_encoding(ENCODING);

set_include_path(
// current path
get_include_path().PATH_SEPARATOR
.ONPHP_TEST_PATH.'misc'.PATH_SEPARATOR
);

$testPathes = array(
ONPHP_TEST_PATH.'core'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Ip'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Net'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR.'Routers'.DIRECTORY_SEPARATOR,
ONPHP_TEST_PATH.'main'.DIRECTORY_SEPARATOR.'Utils'.DIRECTORY_SEPARATOR.'AMQP'.DIRECTORY_SEPARATOR,
);

$dbs = array(
'PgSQL' => array(
Expand Down
127 changes: 127 additions & 0 deletions test/db/CacheAndLazyDBTest.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
class CacheAndLazyDBTest extends TestCaseDAO
{
public function testWorkingWithCache()
{
foreach (DBTestPool::me()->getPool() as $db) {
DBPool::me()->setDefault($db);

$item =
TestItem::create()->
setName('testItem1');

TestItem::dao()->add($item);

$encapsulant =
TestEncapsulant::create()->
setName('testEncapsulant1');

TestEncapsulant::dao()->add($encapsulant);

$subItem1 =
TestSubItem::create()->
setName('testSubItem1')->
setEncapsulant($encapsulant)->
setItem($item);

$subItem2 =
TestSubItem::create()->
setName('testSubItem2')->
setEncapsulant($encapsulant)->
setItem($item);

TestSubItem::dao()->add($subItem1);
TestSubItem::dao()->add($subItem2);

$items =
Criteria::create(TestItem::dao())->
getList();

foreach ($items as $item) {
foreach ($item->getSubItems()->getList() as $subItem) {
$this->assertEquals(
$subItem->getEncapsulant()->getName(),
'testEncapsulant1'
);
}
}

$encapsulant = TestEncapsulant::dao()->getById(1);

$encapsulant->setName('testEncapsulant1_changed');

TestEncapsulant::dao()->save($encapsulant);

// drop identityMap
TestEncapsulant::dao()->dropIdentityMap();
TestSubItem::dao()->dropIdentityMap();
TestItem::dao()->dropIdentityMap();

$items =
Criteria::create(TestItem::dao())->
getList();

foreach ($items as $item) {
foreach ($item->getSubItems()->getList() as $subItem) {
$this->assertEquals(
$subItem->getEncapsulant()->getName(),
'testEncapsulant1_changed'
);
}
}

// drop identityMap
TestEncapsulant::dao()->dropIdentityMap();
TestSubItem::dao()->dropIdentityMap();
TestItem::dao()->dropIdentityMap();

$subItem = TestSubItem::dao()->getById(1);

$this->assertEquals(
$subItem->getEncapsulant()->getName(),
'testEncapsulant1_changed'
);

// drop identityMap
TestEncapsulant::dao()->dropIdentityMap();
TestSubItem::dao()->dropIdentityMap();
TestItem::dao()->dropIdentityMap();

$subItems =
Criteria::create(TestSubItem::dao())->
getList();

foreach ($subItems as $subItem) {
$this->assertEquals(
$subItem->getEncapsulant()->getName(),
'testEncapsulant1_changed'
);
}
}
}

public function testLazy()
{
foreach (DBTestPool::me()->getPool() as $db) {
DBPool::me()->setDefault($db);

$parent = TestParentObject::create();
$child = TestChildObject::create()->setParent($parent);

$parent->dao()->add($parent);

$child->dao()->add($child);

$this->assertEquals(
$parent->getId(),
Criteria::create(TestChildObject::dao())->
setProjection(
Projection::property('parent.id', 'parentId')
)->
add(Expression::eq('id', $child->getId()))->
getCustom('parentId')
);
}
}
}
?>
Loading