From 0084e7360ba877e8a16c4bdf79c86bd8440c6242 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 29 Aug 2024 04:54:35 +0200 Subject: [PATCH] merging Connection & Explorer classes into one (BC break) --- readme.md | 2 +- src/Bridges/DatabaseDI/DatabaseExtension.php | 26 ++---- src/Bridges/DatabaseTracy/ConnectionPanel.php | 14 +-- src/Database/{Connection.php => Explorer.php} | 86 ++++++++++++++++--- src/Database/Factory.php | 4 +- src/Database/Helpers.php | 18 ++-- src/Database/Result.php | 10 +-- src/Database/SqlPreprocessor.php | 6 +- src/compatibility.php | 8 ++ .../Database.DI/DatabaseExtension.basic.phpt | 14 +-- .../DatabaseExtension.multiple.phpt | 17 +--- tests/Database.Tracy/panel.html | 8 +- .../Database/Connection.exceptions.mysql.phpt | 4 +- .../Connection.exceptions.postgre.phpt | 4 +- .../Connection.exceptions.sqlite.phpt | 4 +- tests/Database/Connection.fetch.phpt | 2 +- .../Connection.getInsertId().mysql.phpt | 2 +- .../Connection.getInsertId().postgre.phpt | 2 +- .../Connection.getInsertId().sqlite.phpt | 2 +- .../Connection.getInsertId().sqlsrv.phpt | 2 +- tests/Database/Connection.preprocess.phpt | 2 +- tests/Database/Connection.query.phpt | 2 +- tests/Database/Connection.transaction.phpt | 18 ++-- .../Drivers/MySqlDriver.formatLike.phpt | 2 +- .../Drivers/PgSqlDriver.formatLike.phpt | 2 +- .../Drivers/SqliteDriver.formatLike.phpt | 2 +- .../Drivers/SqlsrvDriver.formatLike.phpt | 2 +- tests/Database/Engine.postgre.10.phpt | 2 +- tests/Database/Engine.postgre.phpt | 2 +- tests/Database/Engine.reflection.phpt | 7 +- tests/Database/Explorer.fetch.phpt | 3 +- tests/Database/Explorer.query.phpt | 3 +- tests/Database/Explorer.transaction.phpt | 3 +- .../Explorer/ActiveRow.__toString().phpt | 3 +- .../Explorer/Explorer.aggregation.phpt | 3 +- .../Database/Explorer/Explorer.backjoin.phpt | 5 +- .../Explorer/Explorer.basic.camelCase.phpt | 3 +- tests/Database/Explorer/Explorer.basic.phpt | 3 +- .../Explorer/Explorer.cache.observer.phpt | 15 ++-- .../Explorer/Explorer.cache.observer2.phpt | 7 +- tests/Database/Explorer/Explorer.cache.phpt | 5 +- .../Explorer/Explorer.cache.rows.phpt | 3 +- tests/Database/Explorer/Explorer.cache2.phpt | 3 +- .../Explorer/Explorer.columnRefetch.phpt | 3 +- .../Explorer.discoveredReflection.phpt | 7 +- .../Explorer/Explorer.join-condition.phpt | 6 +- tests/Database/Explorer/Explorer.join.phpt | 5 +- tests/Database/Explorer/Explorer.limit.phpt | 3 +- .../Explorer/Explorer.limit.sqlsrv.phpt | 5 +- .../Explorer/Explorer.multi-primary-key.phpt | 3 +- .../Explorer/Explorer.placeholders.phpt | 3 +- tests/Database/Explorer/Explorer.ref().phpt | 7 +- .../Explorer/Explorer.related().caching.phpt | 3 +- .../Database/Explorer/Explorer.related().phpt | 3 +- .../Explorer/Explorer.self-reference.phpt | 5 +- .../Database/Explorer/Explorer.subquery.phpt | 3 +- .../Database/Explorer/Explorer.update().phpt | 3 +- .../Explorer/GroupedSelection.insert().phpt | 3 +- .../Database/Explorer/Selection.delete().phpt | 3 +- .../Database/Explorer/Selection.fetch().phpt | 3 +- .../Explorer/Selection.fetchAssoc().phpt | 3 +- .../Explorer/Selection.fetchField().phpt | 3 +- .../Explorer/Selection.fetchPairs().phpt | 3 +- tests/Database/Explorer/Selection.get().phpt | 3 +- .../Database/Explorer/Selection.group().phpt | 3 +- .../Explorer/Selection.insert().multi.phpt | 3 +- .../Database/Explorer/Selection.insert().phpt | 3 +- .../Selection.insert().primaryKeys.phpt | 3 +- .../Database/Explorer/Selection.order().phpt | 3 +- tests/Database/Explorer/Selection.page().phpt | 5 +- .../Explorer/Selection.whereOr().phpt | 3 +- .../Explorer/SqlBuilder.addAlias().phpt | 5 +- .../Explorer/SqlBuilder.addWhere().phpt | 5 +- .../SqlBuilder.parseJoinConditions().phpt | 5 +- .../Explorer/SqlBuilder.parseJoins().phpt | 9 +- .../Explorer/bugs/ActiveRow.__isset().phpt | 3 +- .../bugs/Selection.emptyResultSet.phpt | 3 +- ...Selection.getReferencingTable.pkTypes.phpt | 3 +- tests/Database/Explorer/bugs/bug1356.phpt | 5 +- tests/Database/Explorer/bugs/bug170.phpt | 3 +- tests/Database/Explorer/bugs/bug187.phpt | 3 +- tests/Database/Explorer/bugs/bug216.phpt | 3 +- .../Explorer/bugs/deleteCacheBug.phpt | 3 +- tests/Database/Explorer/bugs/query.count.phpt | 7 +- .../staticReflection.undeclaredColumn.phpt | 7 +- tests/Database/Explorer/bugs/view.bug.phpt | 7 +- tests/Database/Helpers.dumpSql.phpt | 2 +- tests/Database/Helpers.loadFromFile.phpt | 2 +- tests/Database/Reflection.columns.mysql.phpt | 2 +- .../Database/Reflection.columns.postgre.phpt | 2 +- tests/Database/Reflection.columns.sqlite.phpt | 2 +- tests/Database/Reflection.columns.sqlsrv.phpt | 2 +- tests/Database/Reflection.phpt | 2 +- tests/Database/Result.fetch().phpt | 2 +- tests/Database/Result.fetchAll().phpt | 2 +- tests/Database/Result.fetchAssoc().phpt | 2 +- tests/Database/Result.fetchField().phpt | 2 +- tests/Database/Result.fetchList().phpt | 2 +- tests/Database/Result.fetchPairs().phpt | 2 +- .../ResultSet.normalizeRow.mysql.phpt | 2 +- .../ResultSet.normalizeRow.postgre.phpt | 2 +- .../ResultSet.normalizeRow.sqlite.phpt | 2 +- .../ResultSet.normalizeRow.sqlsrv.phpt | 2 +- tests/Database/Row.phpt | 2 +- tests/Database/SqlPreprocessor.enum.phpt | 2 +- tests/Database/SqlPreprocessor.phpt | 2 +- tests/Database/connection.option.lazy.phpt | 19 +--- tests/Database/connection.options.mysql.phpt | 30 +++---- tests/Database/connection.options.sqlite.phpt | 10 +-- tests/Database/connection.options.sqlsrv.phpt | 12 +-- tests/bootstrap.php | 10 +-- 111 files changed, 302 insertions(+), 328 deletions(-) rename src/Database/{Connection.php => Explorer.php} (81%) diff --git a/readme.md b/readme.md index 647b53b74..43f65343d 100644 --- a/readme.md +++ b/readme.md @@ -59,7 +59,7 @@ Database Core To create a new database connection just create a new instance of `Nette\Database\Connection` class: ```php -$database = new Nette\Database\Connection($dsn, $user, $password); // the same arguments as uses PDO +$database = new Nette\Database\Explorer($dsn, $user, $password); // the same arguments as uses PDO ``` Connection allows you to easily query your database by calling `query` method: diff --git a/src/Bridges/DatabaseDI/DatabaseExtension.php b/src/Bridges/DatabaseDI/DatabaseExtension.php index 7efa8da7b..779df049c 100644 --- a/src/Bridges/DatabaseDI/DatabaseExtension.php +++ b/src/Bridges/DatabaseDI/DatabaseExtension.php @@ -93,38 +93,30 @@ private function setupDatabase(\stdClass $config, string $name): void $cacheId = 'Nette.Database.' . hash('xxh128', $name . $config->dsn); $cache = new Statement(Nette\Caching\Cache::class, [1 => $cacheId]); - $connection = $builder->addDefinition($this->prefix("$name.connection")) - ->setFactory(Nette\Database\Connection::class, [$config->dsn, $config->user, $config->password, $config->options]) + $explorer = $builder->addDefinition($this->prefix($name)) + ->setFactory(Nette\Database\Explorer::class, [$config->dsn, $config->user, $config->password, $config->options]) + ->addSetup('setCache', [$cache]) ->setAutowired($config->autowired); - $structure = $builder->addDefinition($this->prefix("$name.structure")) - ->setFactory(Nette\Database\Structure::class) - ->setArguments([new Statement([$connection, 'getDatabaseEngine']), $cache]) - ->setAutowired($config->autowired); - - if (!$config->conventions) { - $conventions = null; + if (!$config->conventions || $config->conventions === 'discovered') { } elseif (is_string($config->conventions)) { $conventions = $builder->addDefinition($this->prefix("$name.conventions")) ->setFactory(preg_match('#^[a-z]+$#Di', $config->conventions) ? 'Nette\Database\Conventions\\' . ucfirst($config->conventions) . 'Conventions' : $config->conventions) - ->setArguments(strtolower($config->conventions) === 'discovered' ? [$structure] : []) ->setAutowired($config->autowired); + $explorer->addSetup('setConventions', [$conventions]); } else { - $conventions = Nette\DI\Helpers::filterArguments([$config->conventions])[0]; + $explorer->addSetup('setConventions', [Nette\DI\Helpers::filterArguments([$config->conventions])[0]]); } - $builder->addDefinition($this->prefix("$name.explorer")) - ->setFactory(Nette\Database\Explorer::class, [$connection, $structure, $conventions, $cache]) - ->setAutowired($config->autowired); - - $builder->addAlias($this->prefix("$name.context"), $this->prefix("$name.explorer")); + $builder->addAlias($this->prefix("$name.connection"), $this->prefix($name)); + $builder->addAlias($this->prefix("$name.context"), $this->prefix($name)); + $builder->addAlias($this->prefix("$name.explorer"), $this->prefix($name)); if ($this->name === 'database') { - $builder->addAlias($this->prefix($name), $this->prefix("$name.connection")); $builder->addAlias("nette.database.$name", $this->prefix($name)); $builder->addAlias("nette.database.$name.context", $this->prefix("$name.explorer")); } diff --git a/src/Bridges/DatabaseTracy/ConnectionPanel.php b/src/Bridges/DatabaseTracy/ConnectionPanel.php index 542a7b7ae..ba6abdcc8 100644 --- a/src/Bridges/DatabaseTracy/ConnectionPanel.php +++ b/src/Bridges/DatabaseTracy/ConnectionPanel.php @@ -10,8 +10,8 @@ namespace Nette\Bridges\DatabaseTracy; use Nette; -use Nette\Database\Connection; use Nette\Database\DriverException; +use Nette\Database\Explorer; use Nette\Database\Helpers; use Nette\Database\Result; use Tracy; @@ -34,7 +34,7 @@ class ConnectionPanel implements Tracy\IBarPanel public static function initialize( - Connection $connection, + Explorer $explorer, bool $addBarPanel = true, string $name = '', bool $explain = true, @@ -46,7 +46,7 @@ public static function initialize( $blueScreen->addPanel(self::renderException(...)); if ($addBarPanel) { - $panel = new self($connection, $blueScreen); + $panel = new self($explorer, $blueScreen); $panel->explain = $explain; $panel->name = $name; $bar ??= Tracy\Debugger::getBar(); @@ -57,14 +57,14 @@ public static function initialize( } - public function __construct(Connection $connection, Tracy\BlueScreen $blueScreen) + public function __construct(Explorer $explorer, Tracy\BlueScreen $blueScreen) { - $connection->onQuery[] = $this->logQuery(...); + $explorer->onQuery[] = $this->logQuery(...); $this->blueScreen = $blueScreen; } - private function logQuery(Connection $connection, $result): void + private function logQuery(Explorer $connection, $result): void { if ($this->disabled) { return; @@ -82,7 +82,7 @@ private function logQuery(Connection $connection, $result): void && preg_match('~\.(php.?|phtml)$~', $row['file']) && !$this->blueScreen->isCollapsed($row['file'])) && ($row['class'] ?? '') !== self::class - && !is_a($row['class'] ?? '', Connection::class, allow_string: true) + && !is_a($row['class'] ?? '', Explorer::class, allow_string: true) ) { $source = [$row['file'], (int) $row['line']]; break; diff --git a/src/Database/Connection.php b/src/Database/Explorer.php similarity index 81% rename from src/Database/Connection.php rename to src/Database/Explorer.php index dd5914f9c..6cf59d4ff 100644 --- a/src/Database/Connection.php +++ b/src/Database/Explorer.php @@ -11,13 +11,14 @@ use JetBrains\PhpStorm\Language; use Nette; +use Nette\Caching\Cache; use Nette\Utils\Arrays; /** - * Represents a connection between PHP and a database server. + * The central access point to Nette Database functionality. */ -class Connection +class Explorer { /** @var array Occurs after connection is established */ public array $onConnect = []; @@ -31,22 +32,28 @@ class Connection private TypeConverter $typeConverter; private ?SqlLiteral $query = null; private int $transactionDepth = 0; + private ?Cache $cache = null; + private ?Conventions $conventions = null; + private ?IStructure $structure = null; public function __construct( - private readonly string $dsn, - ?string $user = null, - #[\SensitiveParameter] - ?string $password = null, - array $options = [], + Drivers\Driver|string $driver, ) { - $lazy = $options['lazy'] ?? false; - unset($options['lazy']); + if (is_string($driver)) { // compatibility with version 3.x + [$dsn, $user, $password, $options] = func_get_args() + [null, null, null, []]; - Factory::configure($this, $options); - $this->driver = Factory::createDriverFromDsn($dsn, $user, $password, $options); - if (!$lazy) { - $this->connect(); + $lazy = $options['lazy'] ?? false; + unset($options['lazy']); + + Factory::configure($this, $options); + $this->driver = Factory::createDriverFromDsn($dsn, $user, $password, $options); + if (!$lazy) { + $this->connect(); + } + + } else { + $this->driver = $driver; } } @@ -346,4 +353,57 @@ public static function literal(string $value, ...$params): SqlLiteral { return new SqlLiteral($value, $params); } + + + /********************* active row ****************d*g**/ + + + public function table(string $table): Table\Selection + { + return new Table\Selection($this, $table); + } + + + public function setCache(Cache $cache): static + { + if (isset($this->structure)) { + throw new \LogicException('Cannot set cache after structure is created.'); + } + $this->cache = $cache; + return $this; + } + + + /** @internal */ + public function getCache(): ?Cache + { + return $this->cache; + } + + + public function setConventions(Conventions $conventions): static + { + if (isset($this->conventions)) { + throw new \LogicException('Conventions are already set.'); + } + $this->conventions = $conventions; + return $this; + } + + + /** @internal */ + public function getConventions(): Conventions + { + return $this->conventions ??= new Conventions\DiscoveredConventions($this->getStructure()); + } + + + /** @internal */ + public function getStructure(): IStructure + { + return $this->structure ??= new Structure($this->getDatabaseEngine(), $this->getCache()); + } } + + +class_exists(Connection::class); diff --git a/src/Database/Factory.php b/src/Database/Factory.php index 7fdc9db50..520e60453 100644 --- a/src/Database/Factory.php +++ b/src/Database/Factory.php @@ -55,9 +55,9 @@ public static function createDriverFromDsn( /** @internal */ - public static function configure(Connection $connection, array $options): void + public static function configure(Explorer $explorer, array $options): void { - $converter = $connection->getTypeConverter(); + $converter = $explorer->getTypeConverter(); foreach (self::TypeConverterOptions as $opt) { if (isset($options[$opt])) { $converter->$opt = (bool) $options[$opt]; diff --git a/src/Database/Helpers.php b/src/Database/Helpers.php index 275bd5c36..fab2ebbce 100644 --- a/src/Database/Helpers.php +++ b/src/Database/Helpers.php @@ -75,7 +75,7 @@ public static function dumpResult(Result $result): void /** * Returns syntax highlighted SQL command. */ - public static function dumpSql(SqlLiteral $query, ?Connection $connection = null): string + public static function dumpSql(SqlLiteral $query, ?Explorer $explorer = null): string { $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|OFFSET|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE'; $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|[RI]?LIKE|REGEXP|TRUE|FALSE'; @@ -110,7 +110,7 @@ public static function dumpSql(SqlLiteral $query, ?Connection $connection = null // parameters $params = $query->getParameters(); - $sql = preg_replace_callback('#\?#', function () use ($params, $connection): string { + $sql = preg_replace_callback('#\?#', function () use ($params, $explorer): string { static $i = 0; $param = $params[$i++] ?? null; if ($param === null) { @@ -128,7 +128,7 @@ public static function dumpSql(SqlLiteral $query, ?Connection $connection = null } elseif (is_string($param)) { $length = Nette\Utils\Strings::length($param); $truncated = Nette\Utils\Strings::truncate($param, self::$maxLength); - $text = htmlspecialchars($connection ? $connection->quote($truncated) : '\'' . $truncated . '\'', ENT_NOQUOTES, 'UTF-8'); + $text = htmlspecialchars($explorer ? $explorer->quote($truncated) : '\'' . $truncated . '\'', ENT_NOQUOTES, 'UTF-8'); return '' . $text . ''; } elseif (is_resource($param)) { @@ -157,7 +157,7 @@ public static function dumpSql(SqlLiteral $query, ?Connection $connection = null * @param ?array $onProgress * @return int count of commands */ - public static function loadFromFile(Connection $connection, string $file, ?callable $onProgress = null): int + public static function loadFromFile(Explorer $explorer, string $file, ?callable $onProgress = null): int { @set_time_limit(0); // @ function may be disabled @@ -170,7 +170,7 @@ public static function loadFromFile(Connection $connection, string $file, ?calla $count = $size = 0; $delimiter = ';'; $sql = ''; - $driver = $connection->getConnection(); // native query without logging + $connection = $explorer->getConnection(); // native query without logging while (($s = fgets($handle)) !== false) { $size += strlen($s); if (!strncasecmp($s, 'DELIMITER ', 10)) { @@ -178,7 +178,7 @@ public static function loadFromFile(Connection $connection, string $file, ?calla } elseif (str_ends_with($ts = rtrim($s), $delimiter)) { $sql .= substr($ts, 0, -strlen($delimiter)); - $driver->query($sql); + $connection->query($sql); $sql = ''; $count++; if ($onProgress) { @@ -190,7 +190,7 @@ public static function loadFromFile(Connection $connection, string $file, ?calla } if (rtrim($sql) !== '') { - $driver->query($sql); + $connection->query($sql); $count++; if ($onProgress) { $onProgress($count, isset($stat['size']) ? 100 : null); @@ -204,7 +204,7 @@ public static function loadFromFile(Connection $connection, string $file, ?calla /** @deprecated use Nette\Bridges\DatabaseTracy\ConnectionPanel::initialize() */ public static function createDebugPanel( - Connection $connection, + Explorer $connection, bool $explain, string $name, Tracy\Bar $bar, @@ -218,7 +218,7 @@ public static function createDebugPanel( /** @deprecated use Nette\Bridges\DatabaseTracy\ConnectionPanel::initialize() */ public static function initializeTracy( - Connection $connection, + Explorer $connection, bool $addBarPanel = false, string $name = '', bool $explain = true, diff --git a/src/Database/Result.php b/src/Database/Result.php index f071e822d..eae7d777e 100644 --- a/src/Database/Result.php +++ b/src/Database/Result.php @@ -27,7 +27,7 @@ class Result implements \Iterator public function __construct( - private readonly Connection $connection, + private readonly Explorer $explorer, private readonly SqlLiteral $query, private readonly ?Drivers\Result $result, private float $time, @@ -36,10 +36,10 @@ public function __construct( /** @deprecated */ - public function getConnection(): Connection + public function getConnection(): Explorer { trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - return $this->connection; + return $this->explorer; } @@ -237,8 +237,8 @@ private function normalizeRow(array $row): array private function resolveColumnConverters(): array { $res = []; - $engine = $this->connection->getDatabaseEngine(); - $converter = $this->connection->getTypeConverter(); + $engine = $this->explorer->getDatabaseEngine(); + $converter = $this->explorer->getTypeConverter(); foreach ($this->result->getColumnsInfo() as $meta) { $res[$meta['name']] = isset($meta['nativeType']) ? $engine->resolveColumnConverter($meta, $converter) diff --git a/src/Database/SqlPreprocessor.php b/src/Database/SqlPreprocessor.php index 690b6075f..3bfa4cd34 100644 --- a/src/Database/SqlPreprocessor.php +++ b/src/Database/SqlPreprocessor.php @@ -59,10 +59,10 @@ class SqlPreprocessor private ?string $arrayMode; - public function __construct(Connection $connection) + public function __construct(Explorer $explorer) { - $this->connection = $connection->getConnection(); - $this->engine = $connection->getDatabaseEngine(); + $this->connection = $explorer->getConnection(); + $this->engine = $explorer->getDatabaseEngine(); } diff --git a/src/compatibility.php b/src/compatibility.php index 135582033..5d86f6f0d 100644 --- a/src/compatibility.php +++ b/src/compatibility.php @@ -26,3 +26,11 @@ class ResultSet extends Result } elseif (!class_exists(ResultSet::class)) { class_alias(Result::class, ResultSet::class); } + +if (false) { + class Connection extends Explorer + { + } +} elseif (!class_exists(Connection::class)) { + class_alias(Explorer::class, Connection::class); +} diff --git a/tests/Database.DI/DatabaseExtension.basic.phpt b/tests/Database.DI/DatabaseExtension.basic.phpt index 8e2cd9282..be78a0435 100644 --- a/tests/Database.DI/DatabaseExtension.basic.phpt +++ b/tests/Database.DI/DatabaseExtension.basic.phpt @@ -36,18 +36,12 @@ test('', function () { $container = new Container1; $container->initialize(); - $connection = $container->getService('database.default'); - Assert::type(Nette\Database\Connection::class, $connection); - - $explorer = $container->getService('database.default.explorer'); + $explorer = $container->getService('database.default'); Assert::type(Nette\Database\Explorer::class, $explorer); - Assert::same($connection, $explorer->getConnection()); - Assert::same($container->getService('database.default.context'), $explorer); - - Assert::type(Nette\Database\Structure::class, $explorer->getStructure()); - Assert::type(Nette\Database\Conventions\DiscoveredConventions::class, $explorer->getConventions()); + Assert::type(Nette\Caching\Cache::class, $explorer->getCache()); // aliases - Assert::same($connection, $container->getService('nette.database.default')); + Assert::same($explorer, $container->getService('database.default.explorer')); + Assert::same($explorer, $container->getService('nette.database.default')); Assert::same($explorer, $container->getService('nette.database.default.context')); }); diff --git a/tests/Database.DI/DatabaseExtension.multiple.phpt b/tests/Database.DI/DatabaseExtension.multiple.phpt index 43bb58a47..48b786d28 100644 --- a/tests/Database.DI/DatabaseExtension.multiple.phpt +++ b/tests/Database.DI/DatabaseExtension.multiple.phpt @@ -45,22 +45,13 @@ test('', function () { $container = new Container1; $container->initialize(); - $connection = $container->getService('database.first'); - Assert::type(Nette\Database\Connection::class, $connection); - Assert::same($connection, $container->getByType(Nette\Database\Connection::class)); - - $explorer = $container->getService('database.first.explorer'); + $explorer = $container->getService('database.first'); Assert::type(Nette\Database\Explorer::class, $explorer); Assert::same($explorer, $container->getByType(Nette\Database\Explorer::class)); - Assert::same($connection, $explorer->getConnection()); - Assert::same($container->getService('database.first.context'), $explorer); - - Assert::type(Nette\Database\Structure::class, $explorer->getStructure()); - Assert::same($explorer->getStructure(), $container->getByType(Nette\Database\IStructure::class)); - Assert::type(Nette\Database\Conventions\DiscoveredConventions::class, $explorer->getConventions()); - Assert::same($explorer->getConventions(), $container->getByType(Nette\Database\Conventions::class)); + Assert::type(Nette\Caching\Cache::class, $explorer->getCache()); // aliases - Assert::same($connection, $container->getService('nette.database.first')); + Assert::same($explorer, $container->getService('database.first.explorer')); + Assert::same($explorer, $container->getService('nette.database.first')); Assert::same($explorer, $container->getService('nette.database.first.context')); }); diff --git a/tests/Database.Tracy/panel.html b/tests/Database.Tracy/panel.html index 39316ae03..3722349a9 100644 --- a/tests/Database.Tracy/panel.html +++ b/tests/Database.Tracy/panel.html @@ -7,20 +7,20 @@

Queries: 4, time: %a% ms, foo

%A% %A%
BEGIN TRANSACTION
- %a%Connection.php:%d% + %a%Explorer.php:%d% %A%
SELECT 1
%A%
- %a%Connection.php:%d% + %a%Explorer.php:%d% 0 %A%
COMMIT
- %a%Connection.php:%d% + %a%Explorer.php:%d% @@ -28,7 +28,7 @@

Queries: 4, time: %a% ms, foo

ERROR
SELECT
- %a%Connection.php:%d% + %a%Explorer.php:%d% diff --git a/tests/Database/Connection.exceptions.mysql.phpt b/tests/Database/Connection.exceptions.mysql.phpt index eedcc1a82..bc19f1b93 100644 --- a/tests/Database/Connection.exceptions.mysql.phpt +++ b/tests/Database/Connection.exceptions.mysql.phpt @@ -11,13 +11,13 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); test('Exception thrown for invalid database credentials', function () { $options = Tester\Environment::loadData(); $e = Assert::exception( - fn() => new Nette\Database\Connection($options['dsn'], 'unknown', 'unknown'), + fn() => new Nette\Database\Explorer($options['dsn'], 'unknown', 'unknown'), Nette\Database\ConnectionException::class, '%a% Access denied for user %a%', 1045, diff --git a/tests/Database/Connection.exceptions.postgre.phpt b/tests/Database/Connection.exceptions.postgre.phpt index aa437e599..c376df31e 100644 --- a/tests/Database/Connection.exceptions.postgre.phpt +++ b/tests/Database/Connection.exceptions.postgre.phpt @@ -11,14 +11,14 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); test('Exception thrown for invalid database credentials', function () { $options = Tester\Environment::loadData(); $e = Assert::exception( - fn() => new Nette\Database\Connection($options['dsn'], 'unknown', 'unknown'), + fn() => new Nette\Database\Explorer($options['dsn'], 'unknown', 'unknown'), Nette\Database\ConnectionException::class, null, 7, diff --git a/tests/Database/Connection.exceptions.sqlite.phpt b/tests/Database/Connection.exceptions.sqlite.phpt index ad2a8778c..957c80ef5 100644 --- a/tests/Database/Connection.exceptions.sqlite.phpt +++ b/tests/Database/Connection.exceptions.sqlite.phpt @@ -11,13 +11,13 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); test('Exception thrown for unable to open database file', function () { $e = Assert::exception( - fn() => new Nette\Database\Connection('sqlite:.'), + fn() => new Nette\Database\Explorer('sqlite:.'), Nette\Database\ConnectionException::class, 'SQLSTATE[HY000] [14] unable to open database file', 14, diff --git a/tests/Database/Connection.fetch.phpt b/tests/Database/Connection.fetch.phpt index e4e09421f..0d1bffaf6 100644 --- a/tests/Database/Connection.fetch.phpt +++ b/tests/Database/Connection.fetch.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Connection.getInsertId().mysql.phpt b/tests/Database/Connection.getInsertId().mysql.phpt index 1dee7e83d..ffd7a71ff 100644 --- a/tests/Database/Connection.getInsertId().mysql.phpt +++ b/tests/Database/Connection.getInsertId().mysql.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $connection->query(' CREATE TEMPORARY TABLE noprimarykey ( diff --git a/tests/Database/Connection.getInsertId().postgre.phpt b/tests/Database/Connection.getInsertId().postgre.phpt index 60dc58b73..41e2f10d5 100644 --- a/tests/Database/Connection.getInsertId().postgre.phpt +++ b/tests/Database/Connection.getInsertId().postgre.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $connection->query(' CREATE TEMPORARY TABLE "primarykey" ( diff --git a/tests/Database/Connection.getInsertId().sqlite.phpt b/tests/Database/Connection.getInsertId().sqlite.phpt index fcfac3213..131431fca 100644 --- a/tests/Database/Connection.getInsertId().sqlite.phpt +++ b/tests/Database/Connection.getInsertId().sqlite.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $connection->query(' CREATE TABLE [noprimarykey] ( diff --git a/tests/Database/Connection.getInsertId().sqlsrv.phpt b/tests/Database/Connection.getInsertId().sqlsrv.phpt index c54444189..627fa45d0 100644 --- a/tests/Database/Connection.getInsertId().sqlsrv.phpt +++ b/tests/Database/Connection.getInsertId().sqlsrv.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $connection->query("IF OBJECT_ID('noprimarykey', 'U') IS NOT NULL DROP TABLE noprimarykey"); $connection->query(' diff --git a/tests/Database/Connection.preprocess.phpt b/tests/Database/Connection.preprocess.phpt index 5f8cd5547..1a59e3f80 100644 --- a/tests/Database/Connection.preprocess.phpt +++ b/tests/Database/Connection.preprocess.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Assert::same(['SELECT name FROM author', []], $connection->preprocess('SELECT name FROM author')); diff --git a/tests/Database/Connection.query.phpt b/tests/Database/Connection.query.phpt index 7fba6e7ff..7e4633b61 100644 --- a/tests/Database/Connection.query.phpt +++ b/tests/Database/Connection.query.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Connection.transaction.phpt b/tests/Database/Connection.transaction.phpt index 91d6f6fdc..26a3fc9bc 100644 --- a/tests/Database/Connection.transaction.phpt +++ b/tests/Database/Connection.transaction.phpt @@ -7,12 +7,12 @@ declare(strict_types=1); -use Nette\Database\Connection; +use Nette\Database\Explorer; use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); @@ -27,7 +27,7 @@ test('', function () use ($connection) { test('', function () use ($connection) { Assert::exception( - fn() => $connection->transaction(function (Connection $connection) { + fn() => $connection->transaction(function (Explorer $connection) { $connection->query('DELETE FROM book'); throw new Exception('my exception'); }), @@ -52,13 +52,13 @@ test('nested transaction() call fail', function () use ($connection) { $base = (int) $connection->query('SELECT COUNT(*) AS cnt FROM author')->fetchField(); Assert::exception( - fn() => $connection->transaction(function (Connection $connection) { + fn() => $connection->transaction(function (Explorer $connection) { $connection->query('INSERT INTO author', [ 'name' => 'A', 'web' => '', ]); - $connection->transaction(function (Connection $connection2) { + $connection->transaction(function (Explorer $connection2) { $connection2->query('INSERT INTO author', [ 'name' => 'B', 'web' => '', @@ -77,7 +77,7 @@ test('nested transaction() call fail', function () use ($connection) { test('nested transaction() call success', function () use ($connection) { $base = (int) $connection->query('SELECT COUNT(*) AS cnt FROM author')->fetchField(); - $connection->transaction(function (Connection $connection) { + $connection->transaction(function (Explorer $connection) { $connection->query('INSERT INTO author', [ 'name' => 'A', 'web' => '', @@ -97,18 +97,18 @@ test('beginTransaction(), commit() & rollBack() calls are forbidden in transacti Assert::exception( fn() => $connection->transaction(fn() => $connection->beginTransaction()), LogicException::class, - Connection::class . '::beginTransaction() call is forbidden inside a transaction() callback', + Explorer::class . '::beginTransaction() call is forbidden inside a transaction() callback', ); Assert::exception( fn() => $connection->transaction(fn() => $connection->commit()), LogicException::class, - Connection::class . '::commit() call is forbidden inside a transaction() callback', + Explorer::class . '::commit() call is forbidden inside a transaction() callback', ); Assert::exception( fn() => $connection->transaction(fn() => $connection->rollBack()), LogicException::class, - Connection::class . '::rollBack() call is forbidden inside a transaction() callback', + Explorer::class . '::rollBack() call is forbidden inside a transaction() callback', ); }); diff --git a/tests/Database/Drivers/MySqlDriver.formatLike.phpt b/tests/Database/Drivers/MySqlDriver.formatLike.phpt index c0593f62f..eafbe25ac 100644 --- a/tests/Database/Drivers/MySqlDriver.formatLike.phpt +++ b/tests/Database/Drivers/MySqlDriver.formatLike.phpt @@ -10,7 +10,7 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $engine = $connection->getDatabaseEngine(); Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A_B', 0)))->fetchField()); diff --git a/tests/Database/Drivers/PgSqlDriver.formatLike.phpt b/tests/Database/Drivers/PgSqlDriver.formatLike.phpt index 44f77eb9f..53da23d3c 100644 --- a/tests/Database/Drivers/PgSqlDriver.formatLike.phpt +++ b/tests/Database/Drivers/PgSqlDriver.formatLike.phpt @@ -10,7 +10,7 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $tests = function ($connection) { $engine = $connection->getDatabaseEngine(); diff --git a/tests/Database/Drivers/SqliteDriver.formatLike.phpt b/tests/Database/Drivers/SqliteDriver.formatLike.phpt index 0f50071fe..cc6b565e2 100644 --- a/tests/Database/Drivers/SqliteDriver.formatLike.phpt +++ b/tests/Database/Drivers/SqliteDriver.formatLike.phpt @@ -10,7 +10,7 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $engine = $connection->getDatabaseEngine(); Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A_B', 0)))->fetchField()); diff --git a/tests/Database/Drivers/SqlsrvDriver.formatLike.phpt b/tests/Database/Drivers/SqlsrvDriver.formatLike.phpt index 682430aac..fe78a94e9 100644 --- a/tests/Database/Drivers/SqlsrvDriver.formatLike.phpt +++ b/tests/Database/Drivers/SqlsrvDriver.formatLike.phpt @@ -10,7 +10,7 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $engine = $connection->getDatabaseEngine(); Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($engine->formatLike('A_B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); diff --git a/tests/Database/Engine.postgre.10.phpt b/tests/Database/Engine.postgre.10.phpt index 6d4519adc..c6e64379e 100644 --- a/tests/Database/Engine.postgre.10.phpt +++ b/tests/Database/Engine.postgre.10.phpt @@ -12,7 +12,7 @@ use Tester\Environment; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $ver = $connection->query('SHOW server_version')->fetchField(); if (version_compare($ver, '10') < 0) { diff --git a/tests/Database/Engine.postgre.phpt b/tests/Database/Engine.postgre.phpt index 0084766ce..89fc5dd90 100644 --- a/tests/Database/Engine.postgre.phpt +++ b/tests/Database/Engine.postgre.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); function names($columns): array diff --git a/tests/Database/Engine.reflection.phpt b/tests/Database/Engine.reflection.phpt index a5b39538a..43d0449ed 100644 --- a/tests/Database/Engine.reflection.phpt +++ b/tests/Database/Engine.reflection.phpt @@ -13,12 +13,11 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/files/{$driverName}-nette_test1.sql"); -$engine = $connection->getDatabaseEngine(); +$engine = $explorer->getDatabaseEngine(); $tables = $engine->getTables(); $tables = array_filter($tables, fn($t) => in_array($t['name'], ['author', 'book', 'book_tag', 'tag'], true)); usort($tables, fn($a, $b) => strcmp($a['name'], $b['name'])); @@ -98,7 +97,7 @@ $expectedColumns = [ switch ($driverName) { case 'mysql': - $version = $connection->getServerVersion(); + $version = $explorer->getServerVersion(); if (version_compare($version, '8.0', '>=')) { $expectedColumns[0]['size'] = null; } diff --git a/tests/Database/Explorer.fetch.phpt b/tests/Database/Explorer.fetch.phpt index 8b07a8e1b..0a6fe9a8b 100644 --- a/tests/Database/Explorer.fetch.phpt +++ b/tests/Database/Explorer.fetch.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/files/{$driverName}-nette_test1.sql"); test('fetch', function () use ($explorer) { diff --git a/tests/Database/Explorer.query.phpt b/tests/Database/Explorer.query.phpt index bf4f9342c..e36c76148 100644 --- a/tests/Database/Explorer.query.phpt +++ b/tests/Database/Explorer.query.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer.transaction.phpt b/tests/Database/Explorer.transaction.phpt index adbf31b1d..7dddcc567 100644 --- a/tests/Database/Explorer.transaction.phpt +++ b/tests/Database/Explorer.transaction.phpt @@ -13,9 +13,8 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/ActiveRow.__toString().phpt b/tests/Database/Explorer/ActiveRow.__toString().phpt index f3a29d9d7..ce25195b6 100644 --- a/tests/Database/Explorer/ActiveRow.__toString().phpt +++ b/tests/Database/Explorer/ActiveRow.__toString().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.aggregation.phpt b/tests/Database/Explorer/Explorer.aggregation.phpt index e04fea142..79d31bdee 100644 --- a/tests/Database/Explorer/Explorer.aggregation.phpt +++ b/tests/Database/Explorer/Explorer.aggregation.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.backjoin.phpt b/tests/Database/Explorer/Explorer.backjoin.phpt index 73f982dd0..7fdcf7f61 100644 --- a/tests/Database/Explorer/Explorer.backjoin.phpt +++ b/tests/Database/Explorer/Explorer.backjoin.phpt @@ -13,10 +13,9 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$engine = $connection->getDatabaseEngine(); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +$engine = $explorer->getDatabaseEngine(); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.basic.camelCase.phpt b/tests/Database/Explorer/Explorer.basic.camelCase.phpt index 6fe3432fc..4f3a072b6 100644 --- a/tests/Database/Explorer/Explorer.basic.camelCase.phpt +++ b/tests/Database/Explorer/Explorer.basic.camelCase.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test2.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test2.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.basic.phpt b/tests/Database/Explorer/Explorer.basic.phpt index 4a1d833be..c109645fc 100644 --- a/tests/Database/Explorer/Explorer.basic.phpt +++ b/tests/Database/Explorer/Explorer.basic.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.cache.observer.phpt b/tests/Database/Explorer/Explorer.cache.observer.phpt index 278972883..931a926a8 100644 --- a/tests/Database/Explorer/Explorer.cache.observer.phpt +++ b/tests/Database/Explorer/Explorer.cache.observer.phpt @@ -13,21 +13,24 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); $cache = Mockery::mock(Nette\Caching\Cache::class); +$cache->shouldReceive('load')->withAnyArgs()->once()->andReturn([]); $cache->shouldReceive('load')->withAnyArgs()->once()->andReturn(['id' => true]); $cache->shouldReceive('load')->withAnyArgs()->times(4)->andReturn(['id' => true, 'author_id' => true]); +$cache->shouldReceive('save')->with('structure', Mockery::any()); $cache->shouldReceive('save')->with(Mockery::any(), ['id' => true, 'author_id' => true, 'title' => true]); - -$explorer = new Nette\Database\Explorer($connection, $explorer->getStructure(), $explorer->getConventions(), $cache); +$explorer->setCache($cache); $queries = 0; -$connection->onQuery[] = function ($dao, Result $result) use (&$queries) { - if (!preg_match('#SHOW|CONSTRAINT_NAME|pg_catalog|sys\.|SET|PRAGMA|FROM sqlite_#i', $result->getQuery()->getSql())) { +$explorer->onQuery[] = function ($explorer, $result) use (&$queries) { + if ( + $result instanceof Result + && !preg_match('#SHOW|CONSTRAINT_NAME|pg_catalog|sys\.|SET|PRAGMA|FROM sqlite_#i', $result->getQuery()->getSql()) + ) { $queries++; } }; diff --git a/tests/Database/Explorer/Explorer.cache.observer2.phpt b/tests/Database/Explorer/Explorer.cache.observer2.phpt index e81555b38..0e7ce2ea1 100644 --- a/tests/Database/Explorer/Explorer.cache.observer2.phpt +++ b/tests/Database/Explorer/Explorer.cache.observer2.phpt @@ -14,9 +14,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); class CacheMock extends Cache @@ -32,7 +31,7 @@ class CacheMock extends Cache } $cache = new CacheMock(new MemoryStorage); -$explorer = new Nette\Database\Explorer($connection, $explorer->getStructure(), $explorer->getConventions(), $cache); +$explorer->setCache($cache); for ($i = 0; $i < 2; ++$i) { $authors = $explorer->table('author'); @@ -53,4 +52,4 @@ for ($i = 0; $i < 2; ++$i) { } Assert::same(reformat('SELECT [id], [name] FROM [author]'), $sql); -Assert::same(2, $cache->writes); +Assert::same(3, $cache->writes); // Structure + 2x Selection diff --git a/tests/Database/Explorer/Explorer.cache.phpt b/tests/Database/Explorer/Explorer.cache.phpt index 20e94bad9..9ec981e47 100644 --- a/tests/Database/Explorer/Explorer.cache.phpt +++ b/tests/Database/Explorer/Explorer.cache.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('Testing Selection caching', function () use ($explorer) { @@ -198,7 +197,7 @@ test('Test saving the union of needed cols, the second call is not subset', func test('Test multiple use of same selection', function () use ($explorer) { $sql = []; - $explorer->getConnection()->onQuery[] = function ($_, $result) use (&$sql) { + $explorer->onQuery[] = function ($_, $result) use (&$sql) { $sql[] = $result->getQueryString(); }; diff --git a/tests/Database/Explorer/Explorer.cache.rows.phpt b/tests/Database/Explorer/Explorer.cache.rows.phpt index 78761af63..19ba71027 100644 --- a/tests/Database/Explorer/Explorer.cache.rows.phpt +++ b/tests/Database/Explorer/Explorer.cache.rows.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); $selections = []; diff --git a/tests/Database/Explorer/Explorer.cache2.phpt b/tests/Database/Explorer/Explorer.cache2.phpt index c174b7779..5f6202526 100644 --- a/tests/Database/Explorer/Explorer.cache2.phpt +++ b/tests/Database/Explorer/Explorer.cache2.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); $res = []; diff --git a/tests/Database/Explorer/Explorer.columnRefetch.phpt b/tests/Database/Explorer/Explorer.columnRefetch.phpt index 4ff46a398..e49d7917e 100644 --- a/tests/Database/Explorer/Explorer.columnRefetch.phpt +++ b/tests/Database/Explorer/Explorer.columnRefetch.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); $books = $explorer->table('book')->order('id DESC')->limit(2); diff --git a/tests/Database/Explorer/Explorer.discoveredReflection.phpt b/tests/Database/Explorer/Explorer.discoveredReflection.phpt index eed582dab..f427a8e5c 100644 --- a/tests/Database/Explorer/Explorer.discoveredReflection.phpt +++ b/tests/Database/Explorer/Explorer.discoveredReflection.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { @@ -90,10 +89,10 @@ test('', function () use ($explorer) { }); -test('', function () use ($connection, $explorer, $driverName) { +test('', function () use ($explorer, $driverName) { if ( $driverName === 'mysql' && - ($lowerCase = $connection->query('SHOW VARIABLES LIKE "lower_case_table_names"')->fetch()) && + ($lowerCase = $explorer->query('SHOW VARIABLES LIKE "lower_case_table_names"')->fetch()) && $lowerCase->Value != 0 ) { // tests case-insensitive reflection diff --git a/tests/Database/Explorer/Explorer.join-condition.phpt b/tests/Database/Explorer/Explorer.join-condition.phpt index 1e92b43e6..9b22801ac 100644 --- a/tests/Database/Explorer/Explorer.join-condition.phpt +++ b/tests/Database/Explorer/Explorer.join-condition.phpt @@ -13,10 +13,10 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$engine = $connection->getDatabaseEngine(); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +$engine = $explorer->getDatabaseEngine(); + test('', function () use ($explorer, $engine) { $schema = $engine->isSupported(Engine::SupportSchema) ? '[public].' diff --git a/tests/Database/Explorer/Explorer.join.phpt b/tests/Database/Explorer/Explorer.join.phpt index d0638f2b1..39f63fa64 100644 --- a/tests/Database/Explorer/Explorer.join.phpt +++ b/tests/Database/Explorer/Explorer.join.phpt @@ -13,10 +13,9 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$engine = $connection->getDatabaseEngine(); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +$engine = $explorer->getDatabaseEngine(); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.limit.phpt b/tests/Database/Explorer/Explorer.limit.phpt index ccf1bec6a..95b733982 100644 --- a/tests/Database/Explorer/Explorer.limit.phpt +++ b/tests/Database/Explorer/Explorer.limit.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); Assert::same( diff --git a/tests/Database/Explorer/Explorer.limit.sqlsrv.phpt b/tests/Database/Explorer/Explorer.limit.sqlsrv.phpt index c8ef3a7b2..a803010e6 100644 --- a/tests/Database/Explorer/Explorer.limit.sqlsrv.phpt +++ b/tests/Database/Explorer/Explorer.limit.sqlsrv.phpt @@ -12,11 +12,10 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$version2008 = $connection->getServerVersion() < 11; +$version2008 = $explorer->getServerVersion() < 11; Assert::same( $version2008 diff --git a/tests/Database/Explorer/Explorer.multi-primary-key.phpt b/tests/Database/Explorer/Explorer.multi-primary-key.phpt index d914c028a..decc738f8 100644 --- a/tests/Database/Explorer/Explorer.multi-primary-key.phpt +++ b/tests/Database/Explorer/Explorer.multi-primary-key.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.placeholders.phpt b/tests/Database/Explorer/Explorer.placeholders.phpt index 52ce83415..858c6dd55 100644 --- a/tests/Database/Explorer/Explorer.placeholders.phpt +++ b/tests/Database/Explorer/Explorer.placeholders.phpt @@ -13,9 +13,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('Leave literals lower-cased, also not-delimiting them is tested.', function () use ($explorer, $driverName) { diff --git a/tests/Database/Explorer/Explorer.ref().phpt b/tests/Database/Explorer/Explorer.ref().phpt index a8a017087..e2cfdd36a 100644 --- a/tests/Database/Explorer/Explorer.ref().phpt +++ b/tests/Database/Explorer/Explorer.ref().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); Assert::same('Jakub Vrana', $explorer->table('book')->get(1)->ref('author')->name); @@ -36,10 +35,10 @@ test('', function () use ($explorer) { Assert::null($explorer->table('book')->get(2)->ref('author', 'translator_id')); }); -test('', function () use ($explorer, $connection) { +test('', function () use ($explorer) { $counter = 0; - $connection->onQuery[] = function ($connection, $result) use (&$counter) { + $explorer->onQuery[] = function ($explorer, $result) use (&$counter) { $counter++; }; diff --git a/tests/Database/Explorer/Explorer.related().caching.phpt b/tests/Database/Explorer/Explorer.related().caching.phpt index d6995923d..f1322ca3b 100644 --- a/tests/Database/Explorer/Explorer.related().caching.phpt +++ b/tests/Database/Explorer/Explorer.related().caching.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.related().phpt b/tests/Database/Explorer/Explorer.related().phpt index 84455a402..daf9c3462 100644 --- a/tests/Database/Explorer/Explorer.related().phpt +++ b/tests/Database/Explorer/Explorer.related().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.self-reference.phpt b/tests/Database/Explorer/Explorer.self-reference.phpt index 345043024..6d13a2710 100644 --- a/tests/Database/Explorer/Explorer.self-reference.phpt +++ b/tests/Database/Explorer/Explorer.self-reference.phpt @@ -12,15 +12,14 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); $explorer->query('UPDATE book SET next_volume = 3 WHERE id IN (2,4)'); -test('', function () use ($connection, $explorer) { +test('', function () use ($explorer) { $book = $explorer->table('book')->get(4); Assert::same('Nette', $book->volume->title); Assert::same('Nette', $book->ref('book', 'next_volume')->title); diff --git a/tests/Database/Explorer/Explorer.subquery.phpt b/tests/Database/Explorer/Explorer.subquery.phpt index 314188f0d..744a5ecc6 100644 --- a/tests/Database/Explorer/Explorer.subquery.phpt +++ b/tests/Database/Explorer/Explorer.subquery.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Explorer.update().phpt b/tests/Database/Explorer/Explorer.update().phpt index 008bae316..0c966779f 100644 --- a/tests/Database/Explorer/Explorer.update().phpt +++ b/tests/Database/Explorer/Explorer.update().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); $author = $explorer->table('author')->get(12); // SELECT * FROM `author` WHERE (`id` = ?) diff --git a/tests/Database/Explorer/GroupedSelection.insert().phpt b/tests/Database/Explorer/GroupedSelection.insert().phpt index 60c239637..b24d7b307 100644 --- a/tests/Database/Explorer/GroupedSelection.insert().phpt +++ b/tests/Database/Explorer/GroupedSelection.insert().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.delete().phpt b/tests/Database/Explorer/Selection.delete().phpt index f5292bb95..f3ba7f959 100644 --- a/tests/Database/Explorer/Selection.delete().phpt +++ b/tests/Database/Explorer/Selection.delete().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.fetch().phpt b/tests/Database/Explorer/Selection.fetch().phpt index ec71f3887..594debe55 100644 --- a/tests/Database/Explorer/Selection.fetch().phpt +++ b/tests/Database/Explorer/Selection.fetch().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.fetchAssoc().phpt b/tests/Database/Explorer/Selection.fetchAssoc().phpt index 6280b9cb6..63e66b7b9 100644 --- a/tests/Database/Explorer/Selection.fetchAssoc().phpt +++ b/tests/Database/Explorer/Selection.fetchAssoc().phpt @@ -13,9 +13,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.fetchField().phpt b/tests/Database/Explorer/Selection.fetchField().phpt index 5eb29cc3b..ff35ca756 100644 --- a/tests/Database/Explorer/Selection.fetchField().phpt +++ b/tests/Database/Explorer/Selection.fetchField().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.fetchPairs().phpt b/tests/Database/Explorer/Selection.fetchPairs().phpt index 89fc97028..832ed2e3f 100644 --- a/tests/Database/Explorer/Selection.fetchPairs().phpt +++ b/tests/Database/Explorer/Selection.fetchPairs().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.get().phpt b/tests/Database/Explorer/Selection.get().phpt index 138afd97e..b153cc479 100644 --- a/tests/Database/Explorer/Selection.get().phpt +++ b/tests/Database/Explorer/Selection.get().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.group().phpt b/tests/Database/Explorer/Selection.group().phpt index ec51d7da7..68cb0ef2b 100644 --- a/tests/Database/Explorer/Selection.group().phpt +++ b/tests/Database/Explorer/Selection.group().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.insert().multi.phpt b/tests/Database/Explorer/Selection.insert().multi.phpt index 99dbcdcb7..0a032e008 100644 --- a/tests/Database/Explorer/Selection.insert().multi.phpt +++ b/tests/Database/Explorer/Selection.insert().multi.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.insert().phpt b/tests/Database/Explorer/Selection.insert().phpt index 69e219c90..4f5599278 100644 --- a/tests/Database/Explorer/Selection.insert().phpt +++ b/tests/Database/Explorer/Selection.insert().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); $book = $explorer->table('author')->insert([ diff --git a/tests/Database/Explorer/Selection.insert().primaryKeys.phpt b/tests/Database/Explorer/Selection.insert().primaryKeys.phpt index 885a89e37..0562d6af7 100644 --- a/tests/Database/Explorer/Selection.insert().primaryKeys.phpt +++ b/tests/Database/Explorer/Selection.insert().primaryKeys.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test4.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test4.sql"); test('Insert into table with simple primary index (autoincrement)', function () use ($explorer) { $simplePkAutoincrementResult = $explorer->table('simple_pk_autoincrement')->insert([ diff --git a/tests/Database/Explorer/Selection.order().phpt b/tests/Database/Explorer/Selection.order().phpt index f264baa84..5633bbfb7 100644 --- a/tests/Database/Explorer/Selection.order().phpt +++ b/tests/Database/Explorer/Selection.order().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/Selection.page().phpt b/tests/Database/Explorer/Selection.page().phpt index 614b84b02..b4cce1ccb 100644 --- a/tests/Database/Explorer/Selection.page().phpt +++ b/tests/Database/Explorer/Selection.page().phpt @@ -12,13 +12,12 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -if ($driverName === 'sqlsrv' && $connection->getServerVersion() < 11) { +if ($driverName === 'sqlsrv' && $explorer->getServerVersion() < 11) { Tester\Environment::skip('Offset is supported since SQL Server 2012'); } -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); //public function page($page, $itemsPerPage, &$numOfPages = null) diff --git a/tests/Database/Explorer/Selection.whereOr().phpt b/tests/Database/Explorer/Selection.whereOr().phpt index 9cc8b1058..2279db58a 100644 --- a/tests/Database/Explorer/Selection.whereOr().phpt +++ b/tests/Database/Explorer/Selection.whereOr().phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('without question mark', function () use ($explorer) { $count = $explorer->table('book')->whereOr([ diff --git a/tests/Database/Explorer/SqlBuilder.addAlias().phpt b/tests/Database/Explorer/SqlBuilder.addAlias().phpt index 3b253b6da..adb9a41d3 100644 --- a/tests/Database/Explorer/SqlBuilder.addAlias().phpt +++ b/tests/Database/Explorer/SqlBuilder.addAlias().phpt @@ -14,9 +14,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); class SqlBuilderMock extends SqlBuilder { @@ -32,7 +31,7 @@ class SqlBuilderMock extends SqlBuilder } } -$engine = $connection->getDatabaseEngine(); +$engine = $explorer->getDatabaseEngine(); test('test duplicated table names throw exception', function () use ($explorer, $engine) { diff --git a/tests/Database/Explorer/SqlBuilder.addWhere().phpt b/tests/Database/Explorer/SqlBuilder.addWhere().phpt index 9c3541bef..92b43343e 100644 --- a/tests/Database/Explorer/SqlBuilder.addWhere().phpt +++ b/tests/Database/Explorer/SqlBuilder.addWhere().phpt @@ -15,9 +15,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); test('test paramateres with null', function () use ($explorer) { @@ -243,7 +242,7 @@ Assert::exception(function () use ($explorer) { }, Nette\InvalidArgumentException::class, 'Column operator does not accept array argument.'); -test('', function () use ($driverName, $explorer, $connection) { +test('', function () use ($driverName, $explorer) { $structure = $explorer->getStructure(); switch ($driverName) { case 'mysql': diff --git a/tests/Database/Explorer/SqlBuilder.parseJoinConditions().phpt b/tests/Database/Explorer/SqlBuilder.parseJoinConditions().phpt index 17e6909e7..b1c6f9f5f 100644 --- a/tests/Database/Explorer/SqlBuilder.parseJoinConditions().phpt +++ b/tests/Database/Explorer/SqlBuilder.parseJoinConditions().phpt @@ -14,9 +14,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); class SqlBuilderMock extends SqlBuilder { @@ -44,7 +43,7 @@ class SqlBuilderMock extends SqlBuilder } } -$engine = $connection->getDatabaseEngine(); +$engine = $explorer->getDatabaseEngine(); test('test circular reference', function () use ($explorer) { $sqlBuilder = new SqlBuilderMock('author', $explorer); diff --git a/tests/Database/Explorer/SqlBuilder.parseJoins().phpt b/tests/Database/Explorer/SqlBuilder.parseJoins().phpt index c77b37f44..3fabed91b 100644 --- a/tests/Database/Explorer/SqlBuilder.parseJoins().phpt +++ b/tests/Database/Explorer/SqlBuilder.parseJoins().phpt @@ -15,9 +15,8 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test2.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test2.sql"); class SqlBuilderMock extends SqlBuilder @@ -37,7 +36,7 @@ class SqlBuilderMock extends SqlBuilder $structure = $explorer->getStructure(); $conventions = new DiscoveredConventions($structure); $sqlBuilder = new SqlBuilderMock('nUsers', $explorer); -$engine = $connection->getDatabaseEngine(); +$engine = $explorer->getDatabaseEngine(); $joins = []; @@ -46,7 +45,7 @@ $sqlBuilder->parseJoins($joins, $query); $join = $sqlBuilder->buildQueryJoins($joins); Assert::same('WHERE priorit.id IS NULL', $query); -$tables = $connection->getDatabaseEngine()->getTables(); +$tables = $explorer->getDatabaseEngine()->getTables(); if (!in_array($tables[0]['name'], ['npriorities', 'ntopics', 'nusers', 'nusers_ntopics', 'nusers_ntopics_alt'], true)) { if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( @@ -75,7 +74,7 @@ if (!in_array($tables[0]['name'], ['npriorities', 'ntopics', 'nusers', 'nusers_n } -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); $structure->rebuild(); $sqlBuilder = new SqlBuilderMock('author', $explorer); diff --git a/tests/Database/Explorer/bugs/ActiveRow.__isset().phpt b/tests/Database/Explorer/bugs/ActiveRow.__isset().phpt index bac634f6a..a26087efd 100644 --- a/tests/Database/Explorer/bugs/ActiveRow.__isset().phpt +++ b/tests/Database/Explorer/bugs/ActiveRow.__isset().phpt @@ -11,9 +11,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/bugs/Selection.emptyResultSet.phpt b/tests/Database/Explorer/bugs/Selection.emptyResultSet.phpt index e0b42ed08..ff3974cee 100644 --- a/tests/Database/Explorer/bugs/Selection.emptyResultSet.phpt +++ b/tests/Database/Explorer/bugs/Selection.emptyResultSet.phpt @@ -11,9 +11,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/bugs/Selection.getReferencingTable.pkTypes.phpt b/tests/Database/Explorer/bugs/Selection.getReferencingTable.pkTypes.phpt index cc4621b7b..fe38a5be9 100644 --- a/tests/Database/Explorer/bugs/Selection.getReferencingTable.pkTypes.phpt +++ b/tests/Database/Explorer/bugs/Selection.getReferencingTable.pkTypes.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test5.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test5.sql"); test('referencing table with integer primary key', function () use ($explorer) { diff --git a/tests/Database/Explorer/bugs/bug1356.phpt b/tests/Database/Explorer/bugs/bug1356.phpt index 9e70d15cd..9e26a2eda 100644 --- a/tests/Database/Explorer/bugs/bug1356.phpt +++ b/tests/Database/Explorer/bugs/bug1356.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); $books = $explorer->table('book')->limit(1); @@ -31,7 +30,7 @@ foreach ($books as $book) { } Assert::same(reformat([ - 'sqlsrv' => $connection->getServerVersion() < 11 + 'sqlsrv' => $explorer->getServerVersion() < 11 ? 'SELECT TOP 1 * FROM [book] ORDER BY [book].[id]' : 'SELECT * FROM [book] ORDER BY [book].[id] OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY', 'SELECT * FROM [book] ORDER BY [book].[id] LIMIT 1', diff --git a/tests/Database/Explorer/bugs/bug170.phpt b/tests/Database/Explorer/bugs/bug170.phpt index 53c020d17..098400e78 100644 --- a/tests/Database/Explorer/bugs/bug170.phpt +++ b/tests/Database/Explorer/bugs/bug170.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-bug170.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-bug170.sql"); Assert::noError(function () use ($explorer) { // this bug is about picking the right foreign key to specified table regardless FKs definition order diff --git a/tests/Database/Explorer/bugs/bug187.phpt b/tests/Database/Explorer/bugs/bug187.phpt index a5210b55a..e1a44fd41 100644 --- a/tests/Database/Explorer/bugs/bug187.phpt +++ b/tests/Database/Explorer/bugs/bug187.phpt @@ -13,9 +13,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-bug187.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-bug187.sql"); foreach ([true, false] as $published) { $where = $published diff --git a/tests/Database/Explorer/bugs/bug216.phpt b/tests/Database/Explorer/bugs/bug216.phpt index 23db5de1e..8f085c919 100644 --- a/tests/Database/Explorer/bugs/bug216.phpt +++ b/tests/Database/Explorer/bugs/bug216.phpt @@ -12,9 +12,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); $book = $explorer->table('author')->insert([ 'name' => $explorer->literal('LOWER(?)', 'Eddard Stark'), diff --git a/tests/Database/Explorer/bugs/deleteCacheBug.phpt b/tests/Database/Explorer/bugs/deleteCacheBug.phpt index fd1912a48..227f9c4a2 100644 --- a/tests/Database/Explorer/bugs/deleteCacheBug.phpt +++ b/tests/Database/Explorer/bugs/deleteCacheBug.phpt @@ -11,9 +11,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { for ($i = 0; $i < 2; $i++) { diff --git a/tests/Database/Explorer/bugs/query.count.phpt b/tests/Database/Explorer/bugs/query.count.phpt index 52dd15ce5..d26c4339b 100644 --- a/tests/Database/Explorer/bugs/query.count.phpt +++ b/tests/Database/Explorer/bugs/query.count.phpt @@ -11,20 +11,19 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); // add additional tags (not relevant to other tests) $explorer->query("INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (1, 24, 'private');"); $explorer->query("INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (2, 24, 'private');"); $explorer->query("INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (2, 22, 'private');"); -test('', function () use ($connection, $explorer) { +test('', function () use ($explorer) { $explorer->table('author')->get(11); // have to build cache first $count = 0; - $connection->onQuery[] = function () use (&$count) { + $explorer->onQuery[] = function () use (&$count) { $count++; }; diff --git a/tests/Database/Explorer/bugs/staticReflection.undeclaredColumn.phpt b/tests/Database/Explorer/bugs/staticReflection.undeclaredColumn.phpt index 0ff25ccdf..2f3ca74c2 100644 --- a/tests/Database/Explorer/bugs/staticReflection.undeclaredColumn.phpt +++ b/tests/Database/Explorer/bugs/staticReflection.undeclaredColumn.phpt @@ -12,13 +12,10 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -$conventions = new Nette\Database\Conventions\StaticConventions; -$cache = new Nette\Caching\Cache(new Nette\Caching\Storages\MemoryStorage); -$explorer = new Nette\Database\Explorer($explorer->getConnection(), $explorer->getStructure(), $conventions, $cache); +$explorer->setConventions(new Nette\Database\Conventions\StaticConventions); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); test('', function () use ($explorer) { diff --git a/tests/Database/Explorer/bugs/view.bug.phpt b/tests/Database/Explorer/bugs/view.bug.phpt index 0837c9d93..32cd165b4 100644 --- a/tests/Database/Explorer/bugs/view.bug.phpt +++ b/tests/Database/Explorer/bugs/view.bug.phpt @@ -11,9 +11,8 @@ use Tester\Assert; require __DIR__ . '/../../../bootstrap.php'; $explorer = connectToDB(); -$connection = $explorer->getConnection(); -Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); +Nette\Database\Helpers::loadFromFile($explorer, __DIR__ . "/../../files/{$driverName}-nette_test1.sql"); $explorer->query('CREATE VIEW books_view AS SELECT * FROM book'); @@ -22,8 +21,8 @@ test('', function () use ($explorer) { Assert::same(1, $selection->count()); }); -test('', function () use ($connection) { - $engine = $connection->getDatabaseEngine(); +test('', function () use ($explorer) { + $engine = $explorer->getDatabaseEngine(); $columns = $engine->getColumns('books_view'); $columnsNames = array_map(fn($item) => $item['name'], $columns); Assert::same(['id', 'author_id', 'translator_id', 'title', 'next_volume'], $columnsNames); diff --git a/tests/Database/Helpers.dumpSql.phpt b/tests/Database/Helpers.dumpSql.phpt index e080bfa90..360961b2d 100644 --- a/tests/Database/Helpers.dumpSql.phpt +++ b/tests/Database/Helpers.dumpSql.phpt @@ -12,7 +12,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Helpers.loadFromFile.phpt b/tests/Database/Helpers.loadFromFile.phpt index 1f6c616cc..d0cc8ba43 100644 --- a/tests/Database/Helpers.loadFromFile.phpt +++ b/tests/Database/Helpers.loadFromFile.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-delimiter.sql'); $arr = $connection->query('SELECT name, id FROM author ORDER BY id')->fetchAll(); diff --git a/tests/Database/Reflection.columns.mysql.phpt b/tests/Database/Reflection.columns.mysql.phpt index 9f969eced..07ab45e8b 100644 --- a/tests/Database/Reflection.columns.mysql.phpt +++ b/tests/Database/Reflection.columns.mysql.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql'); diff --git a/tests/Database/Reflection.columns.postgre.phpt b/tests/Database/Reflection.columns.postgre.phpt index 49d5ca894..81c219838 100644 --- a/tests/Database/Reflection.columns.postgre.phpt +++ b/tests/Database/Reflection.columns.postgre.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/pgsql-nette_test3.sql'); diff --git a/tests/Database/Reflection.columns.sqlite.phpt b/tests/Database/Reflection.columns.sqlite.phpt index bd8b6ecb6..c2b7e8855 100644 --- a/tests/Database/Reflection.columns.sqlite.phpt +++ b/tests/Database/Reflection.columns.sqlite.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlite-nette_test3.sql'); diff --git a/tests/Database/Reflection.columns.sqlsrv.phpt b/tests/Database/Reflection.columns.sqlsrv.phpt index 246007031..1d7ce8952 100644 --- a/tests/Database/Reflection.columns.sqlsrv.phpt +++ b/tests/Database/Reflection.columns.sqlsrv.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette_test3.sql'); diff --git a/tests/Database/Reflection.phpt b/tests/Database/Reflection.phpt index d73dc3580..9afcd4116 100644 --- a/tests/Database/Reflection.phpt +++ b/tests/Database/Reflection.phpt @@ -12,7 +12,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Result.fetch().phpt b/tests/Database/Result.fetch().phpt index 36d5adb2a..a62214044 100644 --- a/tests/Database/Result.fetch().phpt +++ b/tests/Database/Result.fetch().phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Result.fetchAll().phpt b/tests/Database/Result.fetchAll().phpt index 6ae7375ab..0609c94cf 100644 --- a/tests/Database/Result.fetchAll().phpt +++ b/tests/Database/Result.fetchAll().phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Result.fetchAssoc().phpt b/tests/Database/Result.fetchAssoc().phpt index f7b60babe..2b33f8287 100644 --- a/tests/Database/Result.fetchAssoc().phpt +++ b/tests/Database/Result.fetchAssoc().phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Result.fetchField().phpt b/tests/Database/Result.fetchField().phpt index 83e8473e8..f54d3b6cb 100644 --- a/tests/Database/Result.fetchField().phpt +++ b/tests/Database/Result.fetchField().phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Result.fetchList().phpt b/tests/Database/Result.fetchList().phpt index e60176a71..3885b942b 100644 --- a/tests/Database/Result.fetchList().phpt +++ b/tests/Database/Result.fetchList().phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/Result.fetchPairs().phpt b/tests/Database/Result.fetchPairs().phpt index 601bb155e..6927dfb8a 100644 --- a/tests/Database/Result.fetchPairs().phpt +++ b/tests/Database/Result.fetchPairs().phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); diff --git a/tests/Database/ResultSet.normalizeRow.mysql.phpt b/tests/Database/ResultSet.normalizeRow.mysql.phpt index b3c6388b4..e078dfbf6 100644 --- a/tests/Database/ResultSet.normalizeRow.mysql.phpt +++ b/tests/Database/ResultSet.normalizeRow.mysql.phpt @@ -12,7 +12,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql'); diff --git a/tests/Database/ResultSet.normalizeRow.postgre.phpt b/tests/Database/ResultSet.normalizeRow.postgre.phpt index fd24a2315..eac4f0e84 100644 --- a/tests/Database/ResultSet.normalizeRow.postgre.phpt +++ b/tests/Database/ResultSet.normalizeRow.postgre.phpt @@ -12,7 +12,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/pgsql-nette_test3.sql'); diff --git a/tests/Database/ResultSet.normalizeRow.sqlite.phpt b/tests/Database/ResultSet.normalizeRow.sqlite.phpt index 347cf977b..5e92fcd3a 100644 --- a/tests/Database/ResultSet.normalizeRow.sqlite.phpt +++ b/tests/Database/ResultSet.normalizeRow.sqlite.phpt @@ -12,7 +12,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlite-nette_test3.sql'); diff --git a/tests/Database/ResultSet.normalizeRow.sqlsrv.phpt b/tests/Database/ResultSet.normalizeRow.sqlsrv.phpt index 555e2131b..4ff795da7 100644 --- a/tests/Database/ResultSet.normalizeRow.sqlsrv.phpt +++ b/tests/Database/ResultSet.normalizeRow.sqlsrv.phpt @@ -12,7 +12,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette_test3.sql'); diff --git a/tests/Database/Row.phpt b/tests/Database/Row.phpt index ea63dbe3b..c254282e8 100644 --- a/tests/Database/Row.phpt +++ b/tests/Database/Row.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); test('numeric field', function () use ($connection) { $row = $connection->fetch("SELECT 123 AS {$connection->getDatabaseEngine()->delimite('123')}, NULL as nullcol"); diff --git a/tests/Database/SqlPreprocessor.enum.phpt b/tests/Database/SqlPreprocessor.enum.phpt index 91c787cff..0dc4cc250 100644 --- a/tests/Database/SqlPreprocessor.enum.phpt +++ b/tests/Database/SqlPreprocessor.enum.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); enum EnumInt: int { diff --git a/tests/Database/SqlPreprocessor.phpt b/tests/Database/SqlPreprocessor.phpt index f51d5ef02..ee8daccc2 100644 --- a/tests/Database/SqlPreprocessor.phpt +++ b/tests/Database/SqlPreprocessor.phpt @@ -12,7 +12,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$connection = connectToDB()->getConnection(); +$connection = connectToDB(); $preprocessor = new Nette\Database\SqlPreprocessor($connection); test('basic', function () use ($preprocessor) { diff --git a/tests/Database/connection.option.lazy.phpt b/tests/Database/connection.option.lazy.phpt index 05156e771..b8ee1a5dc 100644 --- a/tests/Database/connection.option.lazy.phpt +++ b/tests/Database/connection.option.lazy.phpt @@ -7,9 +7,6 @@ declare(strict_types=1); -use Nette\Caching\Cache; -use Nette\Caching\Storages\DevNullStorage; -use Nette\Database\Structure; use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -17,25 +14,15 @@ require __DIR__ . '/../bootstrap.php'; test('non lazy', function () { Assert::exception( - fn() => new Nette\Database\Connection('xxx', 'user', 'password'), + fn() => new Nette\Database\Explorer('xxx', 'user', 'password'), LogicException::class, "Unknown PDO driver 'xxx'.", ); }); -test('lazy & explorer', function () { - $connection = new Nette\Database\Connection('mysql:', 'user', 'password', ['lazy' => true]); - $explorer = new Nette\Database\Explorer($connection, new Structure($connection->getDatabaseEngine(), new Cache(new DevNullStorage))); - Assert::exception( - fn() => $explorer->query('SELECT ?', 10), - Nette\Database\DriverException::class, - ); -}); - - test('lazy', function () { - $connection = new Nette\Database\Connection('mysql:', 'user', 'password', ['lazy' => true]); + $connection = new Nette\Database\Explorer('mysql:', 'user', 'password', ['lazy' => true]); Assert::exception( fn() => $connection->quote('x'), Nette\Database\DriverException::class, @@ -48,7 +35,7 @@ test('connect & disconnect', function () { $connections = 1; try { - $connection = new Nette\Database\Connection($options['dsn'], $options['username'], $options['password']); + $connection = new Nette\Database\Explorer($options['dsn'], $options['username'], $options['password']); } catch (Nette\Database\DriverException $e) { Tester\Environment::skip("Connection to '$options[dsn]' failed. Reason: " . $e->getMessage()); } diff --git a/tests/Database/connection.options.mysql.phpt b/tests/Database/connection.options.mysql.phpt index 9040f52fb..9e20c290d 100644 --- a/tests/Database/connection.options.mysql.phpt +++ b/tests/Database/connection.options.mysql.phpt @@ -13,13 +13,13 @@ require __DIR__ . '/../bootstrap.php'; test('default charset', function () { - $connection = connectToDB(['charset' => null])->getConnection(); + $connection = connectToDB(['charset' => null]); $row = $connection->fetch("SHOW VARIABLES LIKE 'character_set_client'"); Assert::same('utf8mb4', $row->Value); }); test('custom charset', function () { - $connection = connectToDB(['charset' => 'latin2'])->getConnection(); + $connection = connectToDB(['charset' => 'latin2']); $row = $connection->fetch("SHOW VARIABLES LIKE 'character_set_client'"); Assert::same('latin2', $row->Value); }); @@ -27,28 +27,28 @@ test('custom charset', function () { test('custom sqlmode', function () { $desiredMode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'; - $connection = connectToDB(['sqlmode' => $desiredMode])->getConnection(); + $connection = connectToDB(['sqlmode' => $desiredMode]); $field = $connection->fetchField('SELECT @@sql_mode'); Assert::same($desiredMode, $field); }); test('default convertBoolean', function () { - $connection = connectToDB(['convertBoolean' => null])->getConnection(); + $connection = connectToDB(['convertBoolean' => null]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same(true, $row->bool); }); test('convertBoolean = true', function () { - $connection = connectToDB(['convertBoolean' => true])->getConnection(); + $connection = connectToDB(['convertBoolean' => true]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same(true, $row->bool); }); test('convertBoolean = false', function () { - $connection = connectToDB(['convertBoolean' => false])->getConnection(); + $connection = connectToDB(['convertBoolean' => false]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same(1, $row->bool); @@ -56,45 +56,45 @@ test('convertBoolean = false', function () { test('default newDateTime', function () { - $connection = connectToDB(['newDateTime' => null])->getConnection(); + $connection = connectToDB(['newDateTime' => null]); $field = $connection->fetchField('SELECT NOW()'); Assert::type(Nette\Database\DateTime::class, $field); }); test('newDateTime = false', function () { - $connection = connectToDB(['newDateTime' => false])->getConnection(); + $connection = connectToDB(['newDateTime' => false]); $field = $connection->fetchField('SELECT NOW()'); Assert::type(Nette\Utils\DateTime::class, $field); }); test('newDateTime = true', function () { - $connection = connectToDB(['newDateTime' => true])->getConnection(); + $connection = connectToDB(['newDateTime' => true]); $field = $connection->fetchField('SELECT NOW()'); Assert::type(Nette\Database\DateTime::class, $field); }); test('default convertDateTime', function () { - $connection = connectToDB(['convertDateTime' => null])->getConnection(); + $connection = connectToDB(['convertDateTime' => null]); $field = $connection->fetchField('SELECT NOW()'); Assert::type(Nette\Database\DateTime::class, $field); }); test('convertDateTime = false', function () { - $connection = connectToDB(['convertDateTime' => false])->getConnection(); + $connection = connectToDB(['convertDateTime' => false]); $field = $connection->fetchField('SELECT NOW()'); Assert::type('string', $field); }); test('convertDateTime = true', function () { - $connection = connectToDB(['convertDateTime' => true])->getConnection(); + $connection = connectToDB(['convertDateTime' => true]); $field = $connection->fetchField('SELECT NOW()'); Assert::type(Nette\Database\DateTime::class, $field); }); test('default convertDecimal', function () { - $connection = connectToDB(['convertDecimal' => null])->getConnection(); + $connection = connectToDB(['convertDecimal' => null]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same(1, $row->decimal); @@ -105,7 +105,7 @@ test('default convertDecimal', function () { }); test('convertDecimal = false', function () { - $connection = connectToDB(['convertDecimal' => false])->getConnection(); + $connection = connectToDB(['convertDecimal' => false]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same('1', $row->decimal); @@ -116,7 +116,7 @@ test('convertDecimal = false', function () { }); test('convertDecimal = true', function () { - $connection = connectToDB(['convertDecimal' => true])->getConnection(); + $connection = connectToDB(['convertDecimal' => true]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same(1, $row->decimal); diff --git a/tests/Database/connection.options.sqlite.phpt b/tests/Database/connection.options.sqlite.phpt index ce3967361..352803206 100644 --- a/tests/Database/connection.options.sqlite.phpt +++ b/tests/Database/connection.options.sqlite.phpt @@ -13,20 +13,20 @@ require __DIR__ . '/../bootstrap.php'; test('formatDateTime', function () { - $connection = connectToDB(['formatDateTime' => 'U'])->getConnection(); + $connection = connectToDB(['formatDateTime' => 'U']); $engine = $connection->getDatabaseEngine(); Assert::same('254358000', $engine->formatDateTime(new DateTime('1978-01-23 00:00:00'))); }); test('formatDateTime', function () { - $connection = connectToDB(['formatDateTime' => 'Y-m-d'])->getConnection(); + $connection = connectToDB(['formatDateTime' => 'Y-m-d']); $engine = $connection->getDatabaseEngine(); Assert::same('1978-01-23', $engine->formatDateTime(new DateTime('1978-01-23 00:00:00'))); }); test('default convertDateTime', function () { - $connection = connectToDB(['convertDateTime' => null])->getConnection(); + $connection = connectToDB(['convertDateTime' => null]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlite-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::type(Nette\Database\DateTime::class, $row->date); @@ -34,7 +34,7 @@ test('default convertDateTime', function () { }); test('convertDateTime = false', function () { - $connection = connectToDB(['convertDateTime' => false])->getConnection(); + $connection = connectToDB(['convertDateTime' => false]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlite-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::type('int', $row->date); @@ -42,7 +42,7 @@ test('convertDateTime = false', function () { }); test('convertDateTime = true', function () { - $connection = connectToDB(['convertDateTime' => true])->getConnection(); + $connection = connectToDB(['convertDateTime' => true]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlite-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::type(Nette\Database\DateTime::class, $row->date); diff --git a/tests/Database/connection.options.sqlsrv.phpt b/tests/Database/connection.options.sqlsrv.phpt index b23e8dd1f..39369c69a 100644 --- a/tests/Database/connection.options.sqlsrv.phpt +++ b/tests/Database/connection.options.sqlsrv.phpt @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; test('default convertDecimal', function () { - $connection = connectToDB(['convertDecimal' => null])->getConnection(); + $connection = connectToDB(['convertDecimal' => null]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same(1, $row->decimal); @@ -22,7 +22,7 @@ test('default convertDecimal', function () { }); test('convertDecimal = true', function () { - $connection = connectToDB(['convertDecimal' => true])->getConnection(); + $connection = connectToDB(['convertDecimal' => true]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same(1, $row->decimal); @@ -31,7 +31,7 @@ test('convertDecimal = true', function () { }); test('convertDecimal = false', function () { - $connection = connectToDB(['convertDecimal' => false])->getConnection(); + $connection = connectToDB(['convertDecimal' => false]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::same('1', $row->decimal); @@ -41,21 +41,21 @@ test('convertDecimal = false', function () { test('default convertBoolean', function () { - $connection = connectToDB(['convertBoolean' => null])->getConnection(); + $connection = connectToDB(['convertBoolean' => null]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::equal(true, $row->bit); }); test('convertBoolean = true', function () { - $connection = connectToDB(['convertBoolean' => true])->getConnection(); + $connection = connectToDB(['convertBoolean' => true]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::equal(true, $row->bit); }); test('convertBoolean = false', function () { - $connection = connectToDB(['convertBoolean' => false])->getConnection(); + $connection = connectToDB(['convertBoolean' => false]); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette_test3.sql'); $row = $connection->fetch('SELECT * FROM types'); Assert::equal(1, $row->bit); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 67666e853..7281d6784 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -35,17 +35,13 @@ function connectToDB(array $options = []): Nette\Database\Explorer } try { - $connection = new Nette\Database\Connection($args['dsn'], $args['username'], $args['password'], $args['options']); + $explorer = new Nette\Database\Explorer($args['dsn'], $args['username'], $args['password'], $args['options']); } catch (Nette\Database\ConnectionException $e) { Tester\Environment::skip("Connection to '$args[dsn]' failed. Reason: " . $e->getMessage()); } - $driverName = $connection->getConnection()->getNativeConnection()->getAttribute(PDO::ATTR_DRIVER_NAME); - - $cacheMemoryStorage = new Nette\Caching\Cache(new Nette\Caching\Storages\MemoryStorage); - $structure = new Nette\Database\Structure($connection->getDatabaseEngine(), $cacheMemoryStorage); - $conventions = new Nette\Database\Conventions\DiscoveredConventions($structure); - $explorer = new Nette\Database\Explorer($connection, $structure, $conventions, $cacheMemoryStorage); + $driverName = $explorer->getConnection()->getNativeConnection()->getAttribute(PDO::ATTR_DRIVER_NAME); + $explorer->setCache(new Nette\Caching\Cache(new Nette\Caching\Storages\MemoryStorage)); echo "Driver: $driverName\n"; $GLOBALS['driverName'] = $driverName;