2010-08-03 14:42:32 +02:00
|
|
|
<?php
|
2017-06-09 22:20:47 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-10-08 02:13:22 +02:00
|
|
|
use Dibi\Fluent;
|
2017-07-11 12:27:26 +02:00
|
|
|
use Tester\Assert;
|
2010-08-03 14:42:32 +02:00
|
|
|
|
2012-10-18 23:00:12 +02:00
|
|
|
require __DIR__ . '/bootstrap.php';
|
2010-08-03 14:42:32 +02:00
|
|
|
|
|
|
|
|
2015-10-08 02:13:22 +02:00
|
|
|
$conn = new Dibi\Connection($config);
|
2010-08-03 14:42:32 +02:00
|
|
|
|
2015-10-08 02:13:22 +02:00
|
|
|
$fluent = new Fluent($conn);
|
2010-08-03 14:42:32 +02:00
|
|
|
$fluent->select('*')->from('table')->where('x=1');
|
|
|
|
$dolly = clone $fluent;
|
|
|
|
$dolly->where('y=1');
|
|
|
|
$dolly->clause('FOO');
|
|
|
|
|
2015-06-19 03:11:36 +02:00
|
|
|
Assert::same(reformat('SELECT * FROM [table] WHERE x=1'), (string) $fluent);
|
|
|
|
Assert::same(reformat('SELECT * FROM [table] WHERE x=1 AND y=1 FOO'), (string) $dolly);
|
2010-08-03 14:42:32 +02:00
|
|
|
|
|
|
|
|
2015-10-08 02:13:22 +02:00
|
|
|
$fluent = new Fluent($conn);
|
2015-06-19 03:11:36 +02:00
|
|
|
$fluent->select('id')->from('table')->where('id = %i', 1);
|
2010-08-03 14:42:32 +02:00
|
|
|
$dolly = clone $fluent;
|
2015-06-19 03:11:36 +02:00
|
|
|
$dolly->where('cd = %i', 5);
|
2010-08-03 14:42:32 +02:00
|
|
|
|
2015-06-19 03:11:36 +02:00
|
|
|
Assert::same(reformat('SELECT [id] FROM [table] WHERE id = 1'), (string) $fluent);
|
|
|
|
Assert::same(reformat('SELECT [id] FROM [table] WHERE id = 1 AND cd = 5'), (string) $dolly);
|
2010-08-03 14:42:32 +02:00
|
|
|
|
|
|
|
|
2015-10-08 02:13:22 +02:00
|
|
|
$fluent = new Fluent($conn);
|
2015-06-19 03:11:36 +02:00
|
|
|
$fluent->select('*')->from('table');
|
2010-08-03 14:42:32 +02:00
|
|
|
$dolly = clone $fluent;
|
2015-06-19 03:11:36 +02:00
|
|
|
$dolly->removeClause('select')->select('count(*)');
|
2010-08-03 14:42:32 +02:00
|
|
|
|
2015-06-19 03:11:36 +02:00
|
|
|
Assert::same(reformat('SELECT * FROM [table]'), (string) $fluent);
|
|
|
|
Assert::same(reformat('SELECT count(*) FROM [table]'), (string) $dolly);
|