Permalink
Browse files

Initial. Refs gh-83

  • Loading branch information...
1 parent 03bbfd0 commit 521308c9c079be20709f21222acc4b08c3c01b3d @piotras piotras committed Mar 1, 2012
@@ -0,0 +1,27 @@
+<?php
+if (gc_enabled()) {
+ echo "Disabling Zend Garbage Collection to prevent segfaults, see:\n";
+ echo " https://bugs.php.net/bug.php?id=51091\n";
+ echo " https://github.com/midgardproject/midgard-php5/issues/50\n";
+ gc_disable();
+}
+
+//PHPUnit 3.4 compat
+if (method_exists('PHPUnit_Util_Filter', 'addDirectoryToFilter')) {
+ require_once 'PHPUnit/Framework.php';
+}
+
+$config = new MidgardConfig();
+$config->dbtype = $GLOBALS['midgard2.configuration.db.type'];
+$config->database = $GLOBALS['midgard2.configuration.db.name'];
+$config->dbdir = $GLOBALS['midgard2.configuration.db.dir'];
+$config->blobdir = $GLOBALS['midgard2.configuration.db.blobdir'];
+$config->loglevel = $GLOBALS['midgard2.configuration.loglevel'];
+
+$mgd = midgard_connection::get_instance();
+var_dump($mgd->open_config ($config));
+
+class MidgardTest extends PHPUnit_Framework_TestCase
+{
+
+}
View
@@ -0,0 +1,13 @@
+extension=midgard2.so
+
+[midgard2]
+midgard.engine = On
+;midgard.http = On
+;midgard.superglobals_compat = On
+;midgard.configuration = "openpsa2"
+;midgard.configuration_file="/etc/midgard2/conf.d/midgard2"
+;midgard.memory_debug = On
+;midgard.valgrind_friendly = On
+midgard.glib_loghandler = On
+
+include_path = ".:/usr/share/php"
@@ -0,0 +1,35 @@
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="false"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="bootstrap.php">
+ <php>
+ <var name="midgard2.configuration.db.type" value="SQLite" />
+ <var name="midgard2.configuration.db.name" value="midgard_php5" />
+ <var name="midgard2.configuration.db.dir" value="/tmp" />
+ <var name="midgard2.configuration.db.init" value="true" />
+ <var name="midgard2.configuration.blobdir" value="/tmp/midgard-php5-blobs" />
+ <var name="midgard2.configuration.loglevel" value="warn" />
+ </php>
+
+ <testsuites>
+ <testsuite name="midgard-php5">
+ <directory>tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>../</directory>
+ <exclude>
+ <directory>../tests</directory>
+ <directory>.</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>
@@ -0,0 +1,30 @@
+<?php
+
+class StorageTest extends MidgardTest
+{
+ /* Test database initialization */
+ public function testCreateBaseStorage()
+ {
+ $this->assertTrue(MidgardStorage::create_base_storage());
+ }
+
+ public function testCreateTypesStorage()
+ {
+ $re = new ReflectionExtension('midgard2');
+ $classes = $re->getClasses();
+ foreach ($classes as $refclass) {
+ if ($refclass->isAbstract() || $refclass->isInterface()) {
+ continue;
+ }
+
+ $type = $refclass->getName();
+ if (!is_subclass_of($type, 'MidgardDBObject')) {
+ continue;
+ }
+
+ $this->assertTrue(MidgardStorage::create_class_storage($type));
+ }
+ }
+}
+
+?>
@@ -0,0 +1,43 @@
+<?php
+
+class SqlQueryColumnTest extends MidgardTest
+{
+ protected $column = null;
+ protected $queryProperty = null;
+
+ public function setUp()
+ {
+ if ($this->column === null) {
+ $this->queryProperty = new MidgardQueryProperty("title");
+ $this->column = new MidgardSqlQueryColumn($this->queryProperty, "t1", "The name");
+ }
+ }
+
+ public function testInheritance()
+ {
+ $this->assertInstanceOf("MidgardSqlQueryColumn", $this->column);
+ $this->assertInstanceOf("MidgardQueryColumn", $this->column);
+ }
+
+ public function testGetQueryProperty()
+ {
+ $this->assertEquals($this->column->get_query_property(), $this->queryProperty);
+ $this->assertInstanceOf("MidgardQueryProperty", $this->column->get_query_property());
+ }
+
+ public function testGetName()
+ {
+ /* writable only property */
+ $this->assertEquals($this->column->name, null);
+ $this->assertEquals($this->column->get_name(), "The name");
+ }
+
+ public function testGetQualifier()
+ {
+ /* writable only property */
+ $this->assertEquals($this->column->qualifier, null);
+ $this->assertEquals($this->column->get_qualifier(), "t1");
+ }
+}
+
+?>
@@ -0,0 +1,105 @@
+<?php
+
+class SqlQuerySelectDataTest extends MidgardTest
+{
+ protected $select = null;
+
+ public function setUp()
+ {
+ if ($this->select === null) {
+ $this->select = new MidgardSqlQuerySelectData(midgard_connection::get_instance());
+ }
+ }
+
+ public function testInheritance()
+ {
+ $this->assertInstanceOf("MidgardSqlQuerySelectData", $this->select);
+ $this->assertInstanceOf("MidgardQueryExecutor", $this->select);
+ }
+
+ public function testAddColumn()
+ {
+ $column = new MidgardSqlQueryColumn(
+ new MidgardQueryProperty("title"),
+ "t1",
+ "title_a"
+ );
+ $this->select->add_column($column);
+ }
+
+ public function testGetColumns()
+ {
+ // t1.property_a AS name_a
+ $column = new MidgardSqlQueryColumn(
+ new MidgardQueryProperty("property_a"),
+ "t1",
+ "name_a"
+ );
+ $this->select->add_column($column);
+
+ // t2.property_b AS name_b
+ $column = new MidgardSqlQueryColumn(
+ new MidgardQueryProperty("property_b"),
+ "t2",
+ "name_b"
+ );
+ $this->select->add_column($column);
+
+ // t3.property_c AS name_c
+ $column = new MidgardSqlQueryColumn(
+ new MidgardQueryProperty("property_c"),
+ "t3",
+ "name_c"
+ );
+ $this->select->add_column($column);
+
+ $columns = $this->select->get_columns();
+ $this->assertInternalType('array', $columns);
+ $this->assertCount(3, $columns);
+
+ $names = array("name_a", "name_b","name_c");
+ $qualifiers = array("t1", "t2", "t3");
+
+ foreach ($columns as $column) {
+ $this->assertNotNull($column->get_name());
+ $this->assertContains($column->get_name(), $names);
+ $this->assertNotNull($column->get_qualifier());
+ $this->assertContains($column->get_qualifier(), $qualifiers);
+ }
+ }
+
+ private function addColumns()
+ {
+ $storage = new MidgardQueryStorage("midgard_person");
+ $column = new MidgardSqlQueryColumn(
+ new MidgardQueryProperty("firstname", $storage),
+ "p",
+ "fname"
+ );
+ $this->select->add_column($column);
+
+ $column = new MidgardSqlQueryColumn(
+ new MidgardQueryProperty("lastname", $storage),
+ "p",
+ "lname"
+ );
+ $this->select->add_column($column);
+ }
+
+ public function testExecute()
+ {
+ $this->addColumns();
+ $this->select->execute();
+ }
+
+ public function testGetQueryResult()
+ {
+ $this->addColumns();
+ $this->select->execute();
+ $result = $this->select->get_query_result();
+ $this->assertInstanceOf("MidgardQueryResult", $result);
+ $this->assertInstanceOf("MidgardSqlQueryResult", $result);
+ }
+}
+
+?>

0 comments on commit 521308c

Please sign in to comment.