1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-24 02:43:09 +01:00
php-dibi/tests/dibi/DibiFluent.cloning.phpt

40 lines
999 B
Plaintext
Raw Normal View History

2010-08-03 14:42:32 +02:00
<?php
/**
* Test: Cloning of DibiFluent
*
* @author David Grudl
*/
2012-10-18 23:00:12 +02:00
require __DIR__ . '/bootstrap.php';
2010-08-03 14:42:32 +02:00
2012-10-18 22:09:48 +02:00
dibi::connect($config['sqlite3']);
2010-08-03 14:42:32 +02:00
$fluent = new DibiFluent(dibi::getConnection());
$fluent->select('*')->from('table')->where('x=1');
$dolly = clone $fluent;
$dolly->where('y=1');
$dolly->clause('FOO');
2012-10-18 22:09:48 +02:00
Assert::same( 'SELECT * FROM [table] WHERE x=1', (string) $fluent );
Assert::same( 'SELECT * FROM [table] WHERE x=1 AND y=1 FOO', (string) $dolly );
2010-08-03 14:42:32 +02:00
$fluent = dibi::select('id')->from('table')->where('id = %i',1);
$dolly = clone $fluent;
$dolly->where('cd = %i',5);
2012-10-18 22:09:48 +02:00
Assert::same( 'SELECT [id] FROM [table] WHERE id = 1', (string) $fluent );
Assert::same( 'SELECT [id] FROM [table] WHERE id = 1 AND cd = 5', (string) $dolly );
2010-08-03 14:42:32 +02:00
$fluent = dibi::select("*")->from("table");
$dolly = clone $fluent;
$dolly->removeClause("select")->select("count(*)");
2012-10-18 22:09:48 +02:00
Assert::same( 'SELECT * FROM [table]', (string) $fluent );
Assert::same( 'SELECT count(*) FROM [table]', (string) $dolly );