Skip to content

Commit a71f25e

Browse files
committed
Add test (WIP with asserNotSame)
1 parent 5c411d2 commit a71f25e

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

tests/Persistence/SqlTest.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Atk4\Data\Exception;
88
use Atk4\Data\Model;
99
use Atk4\Data\Schema\TestCase;
10+
use Atk4\Data\Persistence\Sql\Expression;
1011

1112
class SqlTest extends TestCase
1213
{
@@ -213,9 +214,6 @@ public function testPersistenceDelete(): void
213214
$this->assertSame('Smith', $m2->get('surname'));
214215
}
215216

216-
/**
217-
* Test export.
218-
*/
219217
public function testExport(): void
220218
{
221219
$this->setDb([
@@ -239,4 +237,38 @@ public function testExport(): void
239237
['surname' => 'Jones'],
240238
], $m->export(['surname']));
241239
}
240+
241+
public function testSameRowFieldStability(): void
242+
{
243+
$this->setDb([
244+
'user' => [
245+
1 => ['name' => 'John', 'surname' => 'Smith'],
246+
2 => ['name' => 'Sarah', 'surname' => 'Jones'],
247+
],
248+
]);
249+
250+
$m = new Model($this->db, ['table' => 'user']);
251+
$m->addField('name');
252+
$m->addField('surname');
253+
$m->addExpression(
254+
'rand',
255+
[
256+
'sqlite' => 'random()',
257+
'mysql' => 'rand()',
258+
'postgresql' => 'random()',
259+
'mssql' => 'rand()',
260+
'oracle' => 'dbms_random.random',
261+
][$this->c->getDatabasePlatform()->getName()]
262+
);
263+
$m->addExpression('rand2', new Expression('([] + 1) - 1', [$m->getField('rand')]));
264+
$m->setOnlyFields(['rand', 'rand2']);
265+
266+
$export = $m->export();
267+
$this->assertSame([0, 1], array_keys($export));
268+
$randRow0 = $export[0]['rand'];
269+
$randRow1 = $export[1]['rand'];
270+
$this->assertNotSame($randRow0, $randRow1);
271+
$this->assertNotSame($randRow0, $export[0]['rand2']); // TODO assertSame
272+
$this->assertNotSame($randRow0, $export[1]['rand2']);
273+
}
242274
}

0 commit comments

Comments
 (0)