123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- /**
- * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-01 at 06:23:13.
- */
- class PDO_Query_Test extends PHPUnit_Framework_TestCase
- {
- /**
- * @var Query_PDO_Driver
- */
- protected $object;
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
- $stub = (object) array('db_type' => 'mysql');
- $this->object = new \PHPixie\DB\PDO\Query($stub, 'select');
- }
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
- }
- /**
- * @covers Query_PDO_Driver::escape_field
- * @todo Implement testEscape_field().
- */
- public function testEscape_field()
- {
- $this->object->add_alias();
- $this->assertEquals('test', $this->object->escape_field(new \PHPixie\DB\Expression('test')));
- $this->assertEquals('`a0`.*', $this->object->escape_field('*'));
- $this->assertEquals('`a0`.`test`', $this->object->escape_field('test'));
- $this->assertEquals('`test`.`test`', $this->object->escape_field('test.test'));
- }
- /**
- * @covers Query_PDO_Driver::escape_value
- * @todo Implement testEscape_value().
- */
- public function testEscape_value()
- {
- $params = array();
- $this->assertEquals('test', $this->object->escape_value(new \PHPixie\DB\Expression('test'), $params));
- $this->assertEquals('?', $this->object->escape_value('korova', $params));
- $this->assertArrayHasKey(0, $params);
- $this->assertEquals('korova', $params[0]);
- }
- /**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQuerySelect1()
- {
- $query = $this->object
- ->table('fairies')
- ->where('a', 7)
- ->where('b', '<', 8)
- ->where('c', '>', 3)
- ->where('or', array('d', '>', 11))
- ->where(array(
- array('e', 9),
- array('or', array(
- array('f', 10),
- array('g', 11),
- )),
- array('or', array(
- array('h', 12),
- array('or', array('i', 13)),
- ))
- ))
- ->order_by('id', 'desc')
- ->group_by('id')
- ->having('j', '<', new \PHPixie\DB\Expression('korova'))
- ->having('or', array('l', '>', 11))
- ->having(array(
- array('m', 9),
- array('or', array(
- array('n', 10),
- array('o', 11),
- ))
- ))
- ->limit(5)
- ->offset(6)
- ->query();
- $this->assertEquals("SELECT * FROM `fairies` WHERE `fairies`.`a` = ? AND `fairies`.`b` < ? AND `fairies`.`c` > ? OR `fairies`.`d` > ? AND ( `fairies`.`e` = ? OR ( `fairies`.`f` = ? AND `fairies`.`g` = ? ) OR ( `fairies`.`h` = ? OR `fairies`.`i` = ? ) ) GROUP BY `fairies`.`id` HAVING `fairies`.`j` < korova OR `fairies`.`l` > ? AND ( `fairies`.`m` = ? OR ( `fairies`.`n` = ? AND `fairies`.`o` = ? ) ) ORDER BY `fairies`.`id` DESC LIMIT 5 OFFSET 6 ", current($query));
- }
- /**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQuerySelect2()
- {
- $query = $this->object
- ->table('fairies')
- ->where('a', 7)
- ->join('test', array('fairies.test_id', 'test.id'))
- ->join('test2', array(
- array('fairies.test2_id', 'test.test_id'),
- array('fairies.test3_id', 'test.id')
- ), 'inner')
- ->order_by('id', 'desc')
- ->query();
- $this->assertEquals("SELECT * FROM `fairies` LEFT JOIN `test` ON `fairies`.`test_id` = `test`.`id` INNER JOIN `test2` ON ( `fairies`.`test2_id` = `test`.`test_id` AND `fairies`.`test3_id` = `test`.`id` ) WHERE `fairies`.`a` = ? ORDER BY `fairies`.`id` DESC ", current($query));
- }
- /**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryDelete()
- {
- $query = $this->object
- ->type('delete')
- ->table('fairies')
- ->where('id', 1)
- ->query();
- $this->assertEquals("DELETE fairies.* FROM `fairies` WHERE `fairies`.`id` = ? ", current($query));
- }
- /**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryInsert()
- {
- $query = $this->object
- ->type('insert')
- ->table('fairies')
- ->data(array('id' => 1, 'name' => 'Trixie'))
- ->query();
- $this->assertEquals("INSERT INTO `fairies` (`id`, `name`) VALUES(?, ?)", current($query));
- }
- /**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryUpdate()
- {
- $query = $this->object
- ->type('update')
- ->table('fairies')
- ->data(array('id' => 1, 'name' => 'Trixie'))
- ->query();
- $this->assertEquals("UPDATE `fairies` SET `id` = ?, `name` = ? ", current($query));
- }
- /**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryCount()
- {
- $query = $this->object
- ->type('count')
- ->table('fairies')
- ->where('id', 8)
- ->query();
- $this->assertEquals("SELECT COUNT(*) as `count` FROM `fairies` WHERE `fairies`.`id` = ? ", current($query));
- }
- /**
- * @covers Query_PDO_Driver::add_alias
- * @todo Implement testQuery().
- */
- public function testAlias()
- {
- $this->object->table('fairies');
- $this->assertEquals('fairies', $this->object->last_alias());
- $this->object->add_alias();
- $this->assertEquals('a0', $this->object->last_alias());
- }
- /**
- * @covers Query_PDO_Driver::__call
- * @todo Implement testQuery().
- */
- public function testCall()
- {
- $this->object->table('fairies');
- $this->assertEquals('fairies', $this->object->table());
- $except = false;
- try {
- $this->object->limit('fairies');
- } catch (Exception $e) {
- $except = true;
- }
- $this->assertEquals(true, $except);
- }
- public function testUnion()
- {
- $stub = (object) array('db_type' => 'mysql');
- $subquery = new \PHPixie\DB\PDO\Query($stub, 'select');
- $subquery->table('fairies');
- $this->object->table('fairies');
- $this->object->where('id', '>', 7);
- $this->object->union($subquery);
- $this->object->union($subquery);
- $this->assertEquals('(SELECT * FROM `fairies` WHERE `fairies`.`id` > ? ) UNION ALL (SELECT * FROM `fairies` ) UNION ALL (SELECT * FROM `fairies` ) ', current($this->object->query()));
- }
- public function testSubselect()
- {
- $stub = (object) array('db_type' => 'mysql');
- $subquery = new \PHPixie\DB\PDO\Query($stub, 'select');
- $subquery->fields('id')->table('fairies');
- $this->object->table('fairies')->where('id', 7)->where('id', 'in', $subquery);
- $this->assertEquals('SELECT * FROM `fairies` WHERE `fairies`.`id` = ? AND `fairies`.`id` in (SELECT `fairies`.`id` FROM `fairies` ) ', current($this->object->query()));
- }
- public function testSubtable()
- {
- $stub = (object) array('db_type' => 'mysql');
- $subquery = new \PHPixie\DB\PDO\Query($stub, 'select');
- $subquery->fields('id')->table('fairies');
- $this->object->table($subquery)->where('id', 7);
- $this->assertEquals('SELECT * FROM (SELECT `fairies`.`id` FROM `fairies` ) AS a0 WHERE `a0`.`id` = ? ', current($this->object->query()));
- }
- public function testJoinSubtable()
- {
- $stub = (object) array('db_type' => 'mysql');
- $subquery = new \PHPixie\DB\PDO\Query($stub, 'select');
- $subquery->table('fairies');
- $this->object->table($subquery);
- $this->object->join('pixies', array('fairies.id', '=', 'pixie.id'));
- $this->object->join(array('fairies', 'fae'), array('fairies.id', '=', 'fae.id'));
- $this->object->join(array($subquery, 'fae2'), array('fairies.id', '=', 'fae2.id'));
- $this->assertEquals('SELECT * FROM (SELECT * FROM `fairies` ) AS a0 LEFT JOIN `pixies` ON `fairies`.`id` = `pixie`.`id` LEFT JOIN `fairies` AS fae ON `fairies`.`id` = `fae`.`id` LEFT JOIN (SELECT * FROM `fairies` ) AS fae2 ON `fairies`.`id` = `fae2`.`id` ', current($this->object->query()));
- }
- public function testExpressionSelect()
- {
- $this->object->table('fairies')->where('id', 'in', new \PHPixie\DB\Expression("(SELECT id from fairies)"));
- $this->assertEquals('SELECT * FROM `fairies` WHERE `fairies`.`id` in (SELECT id from fairies) ', current($this->object->query()));
- }
-
- public function testExpressionQuery()
- {
- $this->object->table('fairies')->where(new \PHPixie\DB\Expression('fairies.id'), 5);
- $this->assertEquals('SELECT * FROM `fairies` WHERE fairies.id = ? ', current($this->object->query()));
- }
- }
|