diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..682a5ca --- /dev/null +++ b/tests/README.md @@ -0,0 +1,5 @@ +# How to run a test + +``` +phpunit --bootstrap=load.php Test*.php +``` diff --git a/tests/TestQuery.php b/tests/TestQuery.php new file mode 100644 index 0000000..aef064a --- /dev/null +++ b/tests/TestQuery.php @@ -0,0 +1,72 @@ +select( 'field' ); + $query->from( 'table' ); + + $query->where( 'condition1' ); + + $query->openBracket() + ->setGlue( 'OR' ); + + $query->where( 'condition2' ); + + $query->openBracket(); + + $query->where( 'condition3' ); + $query->where( 'condition4' ); + + $query->closeBracket(); + + $query->where( 'condition5' ); + + $query->closeBracket() + ->setGlue( 'AND' ); + + $query->where( 'condition6' ); + $query->where( 'condition7' ); + + $this->assertEquals( + 'SELECT field FROM `table` AS `table` WHERE condition1 AND (condition2 OR (condition3 OR condition4) OR condition5) AND condition6 AND condition7', + $query->getQuery() + ); + } + + /** + * Test the EXISTS + */ + public function testExists() { + + // create a couple for dummy query builders + $query = new Query( new DBDummy() ); + $query2 = new Query( new DBDummy() ); + + $query->from( 'one' ); + + $query2->from( 'two' ) + ->whereInt( 'two_field', 2 ) + ->compare( 'one.a', '<', 'two.b' ); + + $query->whereExists( $query2 ); + + $this->assertEquals( + 'SELECT * FROM `one` AS `one` WHERE EXISTS (SELECT * FROM `two` AS `two` WHERE two_field = 2 AND one.a < two.b)', + $query->getQuery() + ); + } + +} diff --git a/tests/load.php b/tests/load.php new file mode 100644 index 0000000..91aec96 --- /dev/null +++ b/tests/load.php @@ -0,0 +1,19 @@ +