|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: bug #216 |
| 5 | + * @dataProvider? ../databases.ini |
| 6 | + */ |
| 7 | + |
| 8 | +declare(strict_types=1); |
| 9 | + |
| 10 | +use Tester\Assert; |
| 11 | + |
| 12 | +require __DIR__ . '/../../../bootstrap.php'; |
| 13 | + |
| 14 | +//Prepare connection |
| 15 | +$options = Tester\Environment::loadData() + ['user' => null, 'password' => null]; |
| 16 | + |
| 17 | +try { |
| 18 | + $connection = new Nette\Database\Connection($options['dsn'], $options['user'], $options['password']); |
| 19 | +} catch (PDOException $e) { |
| 20 | + Tester\Environment::skip("Connection to '$options[dsn]' failed. Reason: " . $e->getMessage()); |
| 21 | +} |
| 22 | + |
| 23 | +if (strpos($options['dsn'], 'sqlite::memory:') === false) { |
| 24 | + Tester\Environment::lock($options['dsn'], TEMP_DIR); |
| 25 | +} |
| 26 | + |
| 27 | +$driverName = $connection->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME); |
| 28 | +$cacheMemoryStorage = new Nette\Caching\Storages\MemoryStorage; |
| 29 | + |
| 30 | +$structure = new Nette\Database\Structure($connection, $cacheMemoryStorage); |
| 31 | +$conventions = new Nette\Database\Conventions\StaticConventions(); |
| 32 | +$context = new Nette\Database\Context($connection, $structure, $conventions, $cacheMemoryStorage); |
| 33 | + |
| 34 | +//Testing |
| 35 | +Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); |
| 36 | + |
| 37 | +$book = $context->table('author')->insert([ |
| 38 | + 'name' => $context->literal('LOWER(?)', 'Eddard Stark'), |
| 39 | + 'web' => 'http://example.com', |
| 40 | + 'born' => new \DateTime('2011-11-11'), |
| 41 | +]); // INSERT INTO `author` (`name`, `web`) VALUES (LOWER('Eddard Stark'), 'http://example.com', '2011-11-11 00:00:00') |
| 42 | +// id = 14 |
| 43 | + |
| 44 | +Assert::type(Nette\Database\Table\ActiveRow::class, $book); |
| 45 | +Assert::equal('eddard stark', $book->name); |
| 46 | +Assert::equal(new Nette\Utils\DateTime('2011-11-11'), $book->born); |
0 commit comments