|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @dataProvider? ../../databases.ini |
| 4 | + */ |
| 5 | + |
| 6 | +use Tester\Assert; |
| 7 | + |
| 8 | +require __DIR__ . '/../../connect.inc.php'; // create $connection |
| 9 | + |
| 10 | +Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test4.sql"); |
| 11 | + |
| 12 | +//Insert into table without auto_increament primary key |
| 13 | +test(function () use ($context) { |
| 14 | + |
| 15 | + $inserted = $context->table('simple_pk')->insert([ |
| 16 | + 'id' => 8, |
| 17 | + 'name' => 'Michal' |
| 18 | + ]); |
| 19 | + |
| 20 | + Assert::equal(8, $inserted->id); |
| 21 | + Assert::equal('Michal', $inserted->name); |
| 22 | +}); |
| 23 | + |
| 24 | +//Insert into table with composite primary key |
| 25 | +test(function () use ($context) { |
| 26 | + |
| 27 | + $inserted = $context->table('composite_pk')->insert([ |
| 28 | + 'id1' => 8, |
| 29 | + 'id2' => 10, |
| 30 | + 'name' => 'Michal' |
| 31 | + ]); |
| 32 | + |
| 33 | + Assert::equal(8, $inserted->id1); |
| 34 | + Assert::equal(10, $inserted->id2); |
| 35 | + Assert::equal('Michal', $inserted->name); |
| 36 | +}); |
| 37 | + |
| 38 | +//Insert into table with composite primary key and one of them is auto_increment |
| 39 | +test(function () use ($context, $driverName) { |
| 40 | + |
| 41 | + //Sqlite doesn't allow this type of table and sqlsrv's driver don't implement reflection |
| 42 | + if ($driverName == 'mysql' || $driverName == 'pgsql') { |
| 43 | + $inserted = $context->table('composite_pk_ai')->insert([ |
| 44 | + 'id2' => 10, |
| 45 | + 'name' => 'Michal' |
| 46 | + ]); |
| 47 | + |
| 48 | + Assert::equal(10, $inserted->id2); |
| 49 | + Assert::equal('Michal', $inserted->name); |
| 50 | + } |
| 51 | +}); |
0 commit comments