Skip to content

Commit 02c27d3

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

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

tests/Persistence/SqlTest.php

Lines changed: 25 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,28 @@ public function testExport(): void
239237
['surname' => 'Jones'],
240238
], $m->export(['surname']));
241239
}
240+
public function testSameRowFieldStability(): void
241+
{
242+
$this->setDb([
243+
'user' => [
244+
1 => ['name' => 'John', 'surname' => 'Smith'],
245+
2 => ['name' => 'Sarah', 'surname' => 'Jones'],
246+
],
247+
]);
248+
249+
$m = new Model($this->db, ['table' => 'user']);
250+
$m->addField('name');
251+
$m->addField('surname');
252+
$m->addExpression('rand', $this->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform ? 'RANDOM()' : 'RAND()');
253+
$m->addExpression('rand2', new Expression('([] + 1) - 1', [$m->getField('rand')]));
254+
$m->setOnlyFields(['rand', 'rand2']);
255+
256+
$export = $m->export();
257+
$this->assertSame([0, 1], array_keys($export));
258+
$randRow0 = $export[0]['rand'];
259+
$randRow1 = $export[1]['rand'];
260+
$this->assertNotSame($randRow0, $randRow1);
261+
$this->assertNotSame($randRow0, $export[0]['rand2']); // TODO assertSame
262+
$this->assertNotSame($randRow0, $export[1]['rand2']);
263+
}
242264
}

0 commit comments

Comments
 (0)