Skip to content

Commit

Permalink
Add test (WIP with asserNotSame)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Nov 26, 2021
1 parent 5c411d2 commit 02c27d3
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions tests/Persistence/SqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Atk4\Data\Exception;
use Atk4\Data\Model;
use Atk4\Data\Schema\TestCase;
use Atk4\Data\Persistence\Sql\Expression;

class SqlTest extends TestCase
{
Expand Down Expand Up @@ -213,9 +214,6 @@ public function testPersistenceDelete(): void
$this->assertSame('Smith', $m2->get('surname'));
}

/**
* Test export.
*/
public function testExport(): void
{
$this->setDb([
Expand All @@ -239,4 +237,28 @@ public function testExport(): void
['surname' => 'Jones'],
], $m->export(['surname']));
}
public function testSameRowFieldStability(): void
{
$this->setDb([
'user' => [
1 => ['name' => 'John', 'surname' => 'Smith'],
2 => ['name' => 'Sarah', 'surname' => 'Jones'],
],
]);

$m = new Model($this->db, ['table' => 'user']);
$m->addField('name');
$m->addField('surname');
$m->addExpression('rand', $this->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform ? 'RANDOM()' : 'RAND()');
$m->addExpression('rand2', new Expression('([] + 1) - 1', [$m->getField('rand')]));
$m->setOnlyFields(['rand', 'rand2']);

$export = $m->export();
$this->assertSame([0, 1], array_keys($export));
$randRow0 = $export[0]['rand'];
$randRow1 = $export[1]['rand'];
$this->assertNotSame($randRow0, $randRow1);
$this->assertNotSame($randRow0, $export[0]['rand2']); // TODO assertSame
$this->assertNotSame($randRow0, $export[1]['rand2']);
}
}

0 comments on commit 02c27d3

Please sign in to comment.