Skip to content

Commit

Permalink
removed mock Kohana_Database_Query_Builder_Select, replaced with actu…
Browse files Browse the repository at this point in the history
…al instance, passed in Mock Database object to the compile method

Signed-off-by: Jordan Shaw <jshaw@janpak.com>
  • Loading branch information
Jordan Shaw committed Feb 13, 2011
1 parent 19a7dd2 commit 0b23dbd
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions tests/kohana/database/query/builder/SelectTest.php
Expand Up @@ -11,17 +11,44 @@ public function provider_select(){
array('foo','bar'),//from
array(
array('join_table1','on',array('join_table1.col1','=','bar.col1'),'on',array('join_table.col2','=','bar.col2')),
array(array('join_table2','jt2'),array('jt2.col2','=','bar.col2'))
array(array('join_table2','jt2'),'on',array('jt2.col2','=','bar.col2'))
),//joins
array(),//where
array(),//group
array(),//order
'SELECT `col1`, `col2`, `col3` FROM `foo` AS `bar` JOIN `join_table1` ON `join_table1`.`col1` = `bar`.`col1` AND `join_table`.`col2` = `bar`.`col2` JOIN `join_table2` AS `jt2` ON `jt2`.`col2` = `bar`.`col2`'
'SELECT "col1", "col2", "col3" FROM "foo" AS "bar" JOIN "join_table1" ON "join_table1"."col1" = "bar"."col1" AND "join_table"."col2" = "bar"."col2" JOIN "join_table2" AS "jt2" ON "jt2"."col2" = "bar"."col2"'

)
);
}

/**
* Tests Kohana_Database_Query_Builder_Select::test_select()
*
* @test
* @dataProvider provider_select
* @param array $cols select columns
* @param array $table table to apply from
*/
public function test_select(array $select,array $from,array $joins, array $where,array $group, array $order, $expected){
$db = $this->getMockDatabase();
//create an instance of Database_Query_Builder_Select, dupping the compile method with null funcitonality, passing the select arguments
$query = DB::select()->select_array($select);//$this->getMock('Database_Query_Builder_Select',,array($select));
$this->assertAttributeSame($select, '_select', $query);//assert the select array was applied to the object

$query->from($from);
$this->assertAttributeSame(array($from), '_from', $query);//assert the from array was applied to the object

$this->_apply_joins($query,$joins);
//$this->assertAttributeSame($joins,'_join',$query);


$sql = $query->compile($db);

$this->assertEquals($expected,$sql);

}

private function _apply_joins($query,$joins){
foreach($joins as $join){
$table = $join[0];
Expand All @@ -36,8 +63,7 @@ private function _apply_joins($query,$joins){
$func = $join[$i];
$i++;
$args = $join[$i];

$query = $query_reflect->getMethod($func)->invokeArgs($query,$args);
$query_reflect->getMethod($func)->invokeArgs($query,$args);
}


Expand All @@ -54,34 +80,6 @@ private function _apply_where($query,$where){

}

/**
* Tests Kohana_Database_Query_Builder_Select::test_select()
*
* @test
* @dataProvider provider_select
* @param array $cols select columns
* @param array $table table to apply from
*/
public function test_select(array $select,array $from,array $joins, array $where,array $group, array $order, $expected){
$db = $this->getMockDatabase();

//create an instance of Database_Query_Builder_Select, dupping the compile method with null funcitonality, passing the select arguments
$query = $this->getMock('Database_Query_Builder_Select',array('compile'),array($select));
$this->assertAttributeSame($select, '_select', $query);//assert the select array was applied to the object

$query->from($from);
$this->assertAttributeSame(array($from), '_from', $query);//assert the from array was applied to the object

//$this->_apply_joins($query,$joins);
//$this->assertAttributeSame($joins,'_join',$query);
$query->expects($this->once())
->method('compile')
->with($db)
->will($this->returnValue($expected));//set expectations for the compile() method behavior

$sql = $query->compile($db);

}


}
Expand Down

0 comments on commit 0b23dbd

Please sign in to comment.