1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-23 18:33:45 +01:00
php-dibi/tests/dibi/Fluent.cloning.phpt

38 lines
1.0 KiB
PHP
Raw Normal View History

2010-08-03 14:42:32 +02:00
<?php
2017-06-09 22:20:47 +02:00
declare(strict_types=1);
use Dibi\Fluent;
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
$conn = new Dibi\Connection($config);
2010-08-03 14:42:32 +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
$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
$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);