diff --git a/.travis.yml b/.travis.yml index 791b48285..02dd9f774 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ matrix: script: - vendor/bin/tester tests -s -p php -c tests/php-unix.ini - - php code-checker/src/code-checker.php + - php temp/code-checker/src/code-checker.php --short-arrays after_failure: # Print *.actual content @@ -24,7 +24,7 @@ after_failure: before_script: # Install Nette Tester & Code Checker - composer install --no-interaction --prefer-source - - composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source + - composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source # Create databases.ini - cp ./tests/Database/databases.sample.ini ./tests/Database/databases.ini diff --git a/src/Bridges/DatabaseDI/DatabaseExtension.php b/src/Bridges/DatabaseDI/DatabaseExtension.php index a4020cfe3..02d8b2fce 100644 --- a/src/Bridges/DatabaseDI/DatabaseExtension.php +++ b/src/Bridges/DatabaseDI/DatabaseExtension.php @@ -18,7 +18,7 @@ */ class DatabaseExtension extends Nette\DI\CompilerExtension { - public $databaseDefaults = array( + public $databaseDefaults = [ 'dsn' => NULL, 'user' => NULL, 'password' => NULL, @@ -28,7 +28,7 @@ class DatabaseExtension extends Nette\DI\CompilerExtension 'reflection' => NULL, // BC 'conventions' => 'discovered', // Nette\Database\Conventions\DiscoveredConventions 'autowired' => NULL, - ); + ]; /** @var bool */ private $debugMode; @@ -44,7 +44,7 @@ public function loadConfiguration() { $configs = $this->getConfig(); if (isset($configs['dsn'])) { - $configs = array('default' => $configs); + $configs = ['default' => $configs]; } $defaults = $this->databaseDefaults; @@ -72,12 +72,12 @@ private function setupDatabase($config, $name) } $connection = $container->addDefinition($this->prefix("$name.connection")) - ->setClass('Nette\Database\Connection', array($config['dsn'], $config['user'], $config['password'], $config['options'])) + ->setClass('Nette\Database\Connection', [$config['dsn'], $config['user'], $config['password'], $config['options']]) ->setAutowired($config['autowired']); $structure = $container->addDefinition($this->prefix("$name.structure")) ->setClass('Nette\Database\Structure') - ->setArguments(array($connection)) + ->setArguments([$connection]) ->setAutowired($config['autowired']); if (!empty($config['reflection'])) { @@ -98,24 +98,24 @@ private function setupDatabase($config, $name) ->setClass(preg_match('#^[a-z]+\z#i', $config['conventions']) ? 'Nette\Database\Conventions\\' . ucfirst($config['conventions']) . 'Conventions' : $config['conventions']) - ->setArguments(strtolower($config['conventions']) === 'discovered' ? array($structure) : array()) + ->setArguments(strtolower($config['conventions']) === 'discovered' ? [$structure] : []) ->setAutowired($config['autowired']); } else { - $tmp = Nette\DI\Compiler::filterArguments(array($config['conventions'])); + $tmp = Nette\DI\Compiler::filterArguments([$config['conventions']]); $conventions = reset($tmp); } $container->addDefinition($this->prefix("$name.context")) - ->setClass('Nette\Database\Context', array($connection, $structure, $conventions)) + ->setClass('Nette\Database\Context', [$connection, $structure, $conventions]) ->setAutowired($config['autowired']); if ($config['debugger']) { - $connection->addSetup('@Tracy\BlueScreen::addPanel', array( + $connection->addSetup('@Tracy\BlueScreen::addPanel', [ 'Nette\Bridges\DatabaseTracy\ConnectionPanel::renderException' - )); + ]); if ($this->debugMode) { - $connection->addSetup('Nette\Database\Helpers::createDebugPanel', array($connection, !empty($config['explain']), $name)); + $connection->addSetup('Nette\Database\Helpers::createDebugPanel', [$connection, !empty($config['explain']), $name]); } } diff --git a/src/Bridges/DatabaseTracy/ConnectionPanel.php b/src/Bridges/DatabaseTracy/ConnectionPanel.php index a5325a44b..f66400265 100644 --- a/src/Bridges/DatabaseTracy/ConnectionPanel.php +++ b/src/Bridges/DatabaseTracy/ConnectionPanel.php @@ -29,7 +29,7 @@ class ConnectionPanel extends Nette\Object implements Tracy\IBarPanel private $count = 0; /** @var array */ - private $queries = array(); + private $queries = []; /** @var string */ public $name; @@ -43,7 +43,7 @@ class ConnectionPanel extends Nette\Object implements Tracy\IBarPanel public function __construct(Nette\Database\Connection $connection) { - $connection->onQuery[] = array($this, 'logQuery'); + $connection->onQuery[] = [$this, 'logQuery']; } @@ -63,18 +63,18 @@ public function logQuery(Nette\Database\Connection $connection, $result) ) { continue; } - $source = array($row['file'], (int) $row['line']); + $source = [$row['file'], (int) $row['line']]; break; } } if ($result instanceof Nette\Database\ResultSet) { $this->totalTime += $result->getTime(); if ($this->count < $this->maxQueries) { - $this->queries[] = array($connection, $result->getQueryString(), $result->getParameters(), $source, $result->getTime(), $result->getRowCount(), NULL); + $this->queries[] = [$connection, $result->getQueryString(), $result->getParameters(), $source, $result->getTime(), $result->getRowCount(), NULL]; } } elseif ($result instanceof \PDOException && $this->count < $this->maxQueries) { - $this->queries[] = array($connection, $result->queryString, NULL, $source, NULL, NULL, $result->getMessage()); + $this->queries[] = [$connection, $result->queryString, NULL, $source, NULL, NULL, $result->getMessage()]; } } @@ -90,10 +90,10 @@ public static function renderException($e) } elseif ($item = Tracy\Helpers::findTrace($e->getTrace(), 'PDO::prepare')) { $sql = $item['args'][0]; } - return isset($sql) ? array( + return isset($sql) ? [ 'tab' => 'SQL', 'panel' => Helpers::dumpSql($sql), - ) : NULL; + ] : NULL; } @@ -118,7 +118,7 @@ public function getPanel() $name = $this->name; $count = $this->count; $totalTime = $this->totalTime; - $queries = array(); + $queries = []; foreach ($this->queries as $query) { list($connection, $sql, $params, $source, $time, $rows, $error) = $query; $explain = NULL; diff --git a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml index 00810e145..41e85d552 100644 --- a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml +++ b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml @@ -12,7 +12,7 @@ use Nette, #tracy-debug .nette-DbConnectionPanel-source { color: #BBB !important } -

Queries: getDsn(), ENT_QUOTES, 'UTF-8') ?>">Queries:

@@ -25,24 +25,24 @@ use Nette, - ERROR + ERROR
explain - + $foo): ?> - + - + @@ -50,7 +50,7 @@ use Nette, - +
diff --git a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.tab.phtml b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.tab.phtml index 9781b57ab..0b416d816 100644 --- a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.tab.phtml +++ b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.tab.phtml @@ -5,7 +5,7 @@ namespace Nette\Bridges\DatabaseTracy; use Nette; ?> - - - + + + diff --git a/src/Database/Connection.php b/src/Database/Connection.php index 2b43c6ce4..05fed7532 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -50,7 +50,7 @@ public function __construct($dsn, $user = NULL, $password = NULL, array $options if (func_num_args() > 4) { // compatibility $options['driverClass'] = func_get_arg(4); } - $this->params = array($dsn, $user, $password); + $this->params = [$dsn, $user, $password]; $this->options = (array) $options; if (empty($options['lazy'])) { @@ -183,7 +183,7 @@ public function query($statement) $args = is_array($statement) ? $statement : func_get_args(); // accepts arrays only internally list($statement, $params) = count($args) > 1 ? $this->preprocessor->process($args) - : array($args[0], array()); + : [$args[0], []]; try { $result = new ResultSet($this, $statement, $params); @@ -216,7 +216,7 @@ public function preprocess($statement) $this->connect(); return func_num_args() > 1 ? $this->preprocessor->process(func_get_args()) - : array($statement, array()); + : [$statement, []]; } diff --git a/src/Database/Conventions/DiscoveredConventions.php b/src/Database/Conventions/DiscoveredConventions.php index a8c7106f5..1bf5278ff 100644 --- a/src/Database/Conventions/DiscoveredConventions.php +++ b/src/Database/Conventions/DiscoveredConventions.php @@ -36,7 +36,7 @@ public function getPrimary($table) public function getHasManyReference($nsTable, $key) { - $candidates = $columnCandidates = array(); + $candidates = $columnCandidates = []; $targets = $this->structure->getHasManyReference($nsTable); $table = preg_replace('#^(.*\.)?(.*)$#', '$2', $nsTable); @@ -48,13 +48,13 @@ public function getHasManyReference($nsTable, $key) foreach ($targetColumns as $targetColumn) { if (stripos($targetColumn, $table) !== FALSE) { - $columnCandidates[] = $candidate = array($targetNsTable, $targetColumn); + $columnCandidates[] = $candidate = [$targetNsTable, $targetColumn]; if (strcmp($targetTable, $key) === 0 || strcmp($targetNsTable, $key) === 0) { return $candidate; } } - $candidates[] = array($targetTable, array($targetNsTable, $targetColumn)); + $candidates[] = [$targetTable, [$targetNsTable, $targetColumn]]; } } @@ -89,7 +89,7 @@ public function getBelongsToReference($table, $key) foreach ($tableColumns as $column => $targetTable) { if (stripos($column, $key) !== FALSE) { - return array($targetTable, $column); + return [$targetTable, $column]; } } diff --git a/src/Database/Conventions/StaticConventions.php b/src/Database/Conventions/StaticConventions.php index ef21a9c3e..12beea866 100644 --- a/src/Database/Conventions/StaticConventions.php +++ b/src/Database/Conventions/StaticConventions.php @@ -52,20 +52,20 @@ public function getPrimary($table) public function getHasManyReference($table, $key) { $table = $this->getColumnFromTable($table); - return array( + return [ sprintf($this->table, $key, $table), sprintf($this->foreign, $table, $key), - ); + ]; } public function getBelongsToReference($table, $key) { $table = $this->getColumnFromTable($table); - return array( + return [ sprintf($this->table, $key, $table), sprintf($this->foreign, $key, $table), - ); + ]; } diff --git a/src/Database/Drivers/MsSqlDriver.php b/src/Database/Drivers/MsSqlDriver.php index 1dc2f83f5..c1176047e 100644 --- a/src/Database/Drivers/MsSqlDriver.php +++ b/src/Database/Drivers/MsSqlDriver.php @@ -33,7 +33,7 @@ public function convertException(\PDOException $e) public function delimite($name) { // @see http://msdn.microsoft.com/en-us/library/ms176027.aspx - return '[' . str_replace(array('[', ']'), array('[[', ']]'), $name) . ']'; + return '[' . str_replace(['[', ']'], ['[[', ']]'], $name) . ']'; } @@ -69,7 +69,7 @@ public function formatDateInterval(\DateInterval $value) */ public function formatLike($value, $pos) { - $value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]')); + $value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } diff --git a/src/Database/Drivers/MySqlDriver.php b/src/Database/Drivers/MySqlDriver.php index 97a285b8a..4ec81f33b 100644 --- a/src/Database/Drivers/MySqlDriver.php +++ b/src/Database/Drivers/MySqlDriver.php @@ -51,16 +51,16 @@ public function __construct(Nette\Database\Connection $connection, array $option public function convertException(\PDOException $e) { $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL; - if (in_array($code, array(1216, 1217, 1451, 1452, 1701), TRUE)) { + if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) { return Nette\Database\ForeignKeyConstraintViolationException::from($e); - } elseif (in_array($code, array(1062, 1557, 1569, 1586), TRUE)) { + } elseif (in_array($code, [1062, 1557, 1569, 1586], TRUE)) { return Nette\Database\UniqueConstraintViolationException::from($e); } elseif ($code >= 2001 && $code <= 2028) { return Nette\Database\ConnectionException::from($e); - } elseif (in_array($code, array(1048, 1121, 1138, 1171, 1252, 1263, 1566), TRUE)) { + } elseif (in_array($code, [1048, 1121, 1138, 1171, 1252, 1263, 1566], TRUE)) { return Nette\Database\NotNullConstraintViolationException::from($e); } else { @@ -149,12 +149,12 @@ public function normalizeRow($row) */ public function getTables() { - $tables = array(); + $tables = []; foreach ($this->connection->query('SHOW FULL TABLES') as $row) { - $tables[] = array( + $tables[] = [ 'name' => $row[0], 'view' => isset($row[1]) && $row[1] === 'VIEW', - ); + ]; } return $tables; } @@ -165,10 +165,10 @@ public function getTables() */ public function getColumns($table) { - $columns = array(); + $columns = []; foreach ($this->connection->query('SHOW FULL COLUMNS FROM ' . $this->delimite($table)) as $row) { $type = explode('(', $row['Type']); - $columns[] = array( + $columns[] = [ 'name' => $row['Field'], 'table' => $table, 'nativetype' => strtoupper($type[0]), @@ -179,7 +179,7 @@ public function getColumns($table) 'autoincrement' => $row['Extra'] === 'auto_increment', 'primary' => $row['Key'] === 'PRI', 'vendor' => (array) $row, - ); + ]; } return $columns; } @@ -190,7 +190,7 @@ public function getColumns($table) */ public function getIndexes($table) { - $indexes = array(); + $indexes = []; foreach ($this->connection->query('SHOW INDEX FROM ' . $this->delimite($table)) as $row) { $indexes[$row['Key_name']]['name'] = $row['Key_name']; $indexes[$row['Key_name']]['unique'] = !$row['Non_unique']; @@ -206,7 +206,7 @@ public function getIndexes($table) */ public function getForeignKeys($table) { - $keys = array(); + $keys = []; $query = 'SELECT CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE ' . 'WHERE TABLE_SCHEMA = DATABASE() AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = ' . $this->connection->quote($table); @@ -226,7 +226,7 @@ public function getForeignKeys($table) */ public function getColumnTypes(\PDOStatement $statement) { - $types = array(); + $types = []; $count = $statement->columnCount(); for ($col = 0; $col < $count; $col++) { $meta = $statement->getColumnMeta($col); diff --git a/src/Database/Drivers/OciDriver.php b/src/Database/Drivers/OciDriver.php index 616216522..72fa56d5b 100644 --- a/src/Database/Drivers/OciDriver.php +++ b/src/Database/Drivers/OciDriver.php @@ -34,13 +34,13 @@ public function __construct(Nette\Database\Connection $connection, array $option public function convertException(\PDOException $e) { $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL; - if (in_array($code, array(1, 2299, 38911), TRUE)) { + if (in_array($code, [1, 2299, 38911], TRUE)) { return Nette\Database\UniqueConstraintViolationException::from($e); - } elseif (in_array($code, array(1400), TRUE)) { + } elseif (in_array($code, [1400], TRUE)) { return Nette\Database\NotNullConstraintViolationException::from($e); - } elseif (in_array($code, array(2266, 2291, 2292), TRUE)) { + } elseif (in_array($code, [2266, 2291, 2292], TRUE)) { return Nette\Database\ForeignKeyConstraintViolationException::from($e); } else { @@ -132,13 +132,13 @@ public function normalizeRow($row) */ public function getTables() { - $tables = array(); + $tables = []; foreach ($this->connection->query('SELECT * FROM cat') as $row) { if ($row[1] === 'TABLE' || $row[1] === 'VIEW') { - $tables[] = array( + $tables[] = [ 'name' => $row[0], 'view' => $row[1] === 'VIEW', - ); + ]; } } return $tables; diff --git a/src/Database/Drivers/OdbcDriver.php b/src/Database/Drivers/OdbcDriver.php index 9d98d68c4..ab33d3ff6 100644 --- a/src/Database/Drivers/OdbcDriver.php +++ b/src/Database/Drivers/OdbcDriver.php @@ -32,7 +32,7 @@ public function convertException(\PDOException $e) */ public function delimite($name) { - return '[' . str_replace(array('[', ']'), array('[[', ']]'), $name) . ']'; + return '[' . str_replace(['[', ']'], ['[[', ']]'], $name) . ']'; } @@ -68,7 +68,7 @@ public function formatDateInterval(\DateInterval $value) */ public function formatLike($value, $pos) { - $value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]')); + $value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } diff --git a/src/Database/Drivers/PgSqlDriver.php b/src/Database/Drivers/PgSqlDriver.php index d573bf7b2..c61dfca06 100644 --- a/src/Database/Drivers/PgSqlDriver.php +++ b/src/Database/Drivers/PgSqlDriver.php @@ -98,7 +98,7 @@ public function formatLike($value, $pos) { $bs = substr($this->connection->quote('\\', \PDO::PARAM_STR), 1, -1); // standard_conforming_strings = on/off $value = substr($this->connection->quote($value, \PDO::PARAM_STR), 1, -1); - $value = strtr($value, array('%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\')); + $value = strtr($value, ['%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } @@ -134,7 +134,7 @@ public function normalizeRow($row) */ public function getTables() { - $tables = array(); + $tables = []; foreach ($this->connection->query(" SELECT DISTINCT ON (c.relname) c.relname::varchar AS name, @@ -161,7 +161,7 @@ public function getTables() */ public function getColumns($table) { - $columns = array(); + $columns = []; foreach ($this->connection->query(" SELECT a.attname::varchar AS name, @@ -204,7 +204,7 @@ public function getColumns($table) */ public function getIndexes($table) { - $indexes = array(); + $indexes = []; foreach ($this->connection->query(" SELECT c2.relname::varchar AS name, @@ -283,7 +283,7 @@ public function isSupported($item) */ private function delimiteFQN($name) { - return implode('.', array_map(array($this, 'delimite'), explode('.', $name))); + return implode('.', array_map([$this, 'delimite'], explode('.', $name))); } } diff --git a/src/Database/Drivers/SqliteDriver.php b/src/Database/Drivers/SqliteDriver.php index 007177aa8..e13178079 100644 --- a/src/Database/Drivers/SqliteDriver.php +++ b/src/Database/Drivers/SqliteDriver.php @@ -144,17 +144,17 @@ public function normalizeRow($row) */ public function getTables() { - $tables = array(); + $tables = []; foreach ($this->connection->query(" SELECT name, type = 'view' as view FROM sqlite_master WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%' UNION ALL SELECT name, type = 'view' as view FROM sqlite_temp_master WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%' ORDER BY name ") as $row) { - $tables[] = array( + $tables[] = [ 'name' => $row->name, 'view' => (bool) $row->view, - ); + ]; } return $tables; @@ -172,12 +172,12 @@ public function getColumns($table) SELECT sql FROM sqlite_temp_master WHERE type = 'table' AND name = {$this->connection->quote($table)} ")->fetch(); - $columns = array(); + $columns = []; foreach ($this->connection->query("PRAGMA table_info({$this->delimite($table)})") as $row) { $column = $row['name']; $pattern = "/(\"$column\"|\[$column\]|$column)\\s+[^,]+\\s+PRIMARY\\s+KEY\\s+AUTOINCREMENT/Ui"; $type = explode('(', $row['type']); - $columns[] = array( + $columns[] = [ 'name' => $column, 'table' => $table, 'nativetype' => strtoupper($type[0]), @@ -188,7 +188,7 @@ public function getColumns($table) 'autoincrement' => (bool) preg_match($pattern, $meta['sql']), 'primary' => $row['pk'] > 0, 'vendor' => (array) $row, - ); + ]; } return $columns; } @@ -199,7 +199,7 @@ public function getColumns($table) */ public function getIndexes($table) { - $indexes = array(); + $indexes = []; foreach ($this->connection->query("PRAGMA index_list({$this->delimite($table)})") as $row) { $indexes[$row['name']]['name'] = $row['name']; $indexes[$row['name']]['unique'] = (bool) $row['unique']; @@ -226,12 +226,12 @@ public function getIndexes($table) if (!$indexes) { // @see http://www.sqlite.org/lang_createtable.html#rowid foreach ($columns as $column) { if ($column['vendor']['pk']) { - $indexes[] = array( + $indexes[] = [ 'name' => 'ROWID', 'unique' => TRUE, 'primary' => TRUE, - 'columns' => array($column['name']), - ); + 'columns' => [$column['name']], + ]; break; } } @@ -246,7 +246,7 @@ public function getIndexes($table) */ public function getForeignKeys($table) { - $keys = array(); + $keys = []; foreach ($this->connection->query("PRAGMA foreign_key_list({$this->delimite($table)})") as $row) { $keys[$row['id']]['name'] = $row['id']; // foreign key name $keys[$row['id']]['local'] = $row['from']; // local columns @@ -268,7 +268,7 @@ public function getForeignKeys($table) */ public function getColumnTypes(\PDOStatement $statement) { - $types = array(); + $types = []; $count = $statement->columnCount(); for ($col = 0; $col < $count; $col++) { $meta = $statement->getColumnMeta($col); diff --git a/src/Database/Drivers/SqlsrvDriver.php b/src/Database/Drivers/SqlsrvDriver.php index 4dcd2b7fb..be7699434 100644 --- a/src/Database/Drivers/SqlsrvDriver.php +++ b/src/Database/Drivers/SqlsrvDriver.php @@ -81,7 +81,7 @@ public function formatDateInterval(\DateInterval $value) public function formatLike($value, $pos) { /** @see http://msdn.microsoft.com/en-us/library/ms179859.aspx */ - $value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]')); + $value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']); return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'"); } @@ -121,7 +121,7 @@ public function normalizeRow($row) */ public function getTables() { - $tables = array(); + $tables = []; foreach ($this->connection->query(" SELECT name, @@ -134,10 +134,10 @@ public function getTables() WHERE type IN ('U', 'V') ") as $row) { - $tables[] = array( + $tables[] = [ 'name' => $row->name, 'view' => (bool) $row->view, - ); + ]; } return $tables; @@ -149,7 +149,7 @@ public function getTables() */ public function getColumns($table) { - $columns = array(); + $columns = []; foreach ($this->connection->query(" SELECT c.name AS name, @@ -193,7 +193,7 @@ public function getColumns($table) */ public function getIndexes($table) { - $indexes = array(); + $indexes = []; foreach ($this->connection->query(" SELECT i.name AS name, @@ -230,7 +230,7 @@ public function getIndexes($table) public function getForeignKeys($table) { // Does't work with multicolumn foreign keys - $keys = array(); + $keys = []; foreach ($this->connection->query(" SELECT fk.name AS name, @@ -259,7 +259,7 @@ public function getForeignKeys($table) */ public function getColumnTypes(\PDOStatement $statement) { - $types = array(); + $types = []; $count = $statement->columnCount(); for ($col = 0; $col < $count; $col++) { $meta = $statement->getColumnMeta($col); diff --git a/src/Database/Helpers.php b/src/Database/Helpers.php index 9cea0a3a1..2a53f381a 100644 --- a/src/Database/Helpers.php +++ b/src/Database/Helpers.php @@ -22,7 +22,7 @@ class Helpers static public $maxLength = 100; /** @var array */ - public static $typePatterns = array( + public static $typePatterns = [ '^_' => IStructure::FIELD_TEXT, // PostgreSQL arrays 'BYTEA|BLOB|BIN' => IStructure::FIELD_BINARY, 'TEXT|CHAR|POINT|INTERVAL' => IStructure::FIELD_TEXT, @@ -32,7 +32,7 @@ class Helpers 'TIME' => IStructure::FIELD_DATETIME, // DATETIME, TIMESTAMP 'DATE' => IStructure::FIELD_DATE, 'BOOL' => IStructure::FIELD_BOOL, - ); + ]; /** @@ -147,7 +147,7 @@ public static function dumpSql($sql, array $params = NULL, Connection $connectio */ public static function detectTypes(\PDOStatement $statement) { - $types = array(); + $types = []; $count = $statement->columnCount(); // driver must be meta-aware, see PHP bugs #53782, #54695 for ($col = 0; $col < $count; $col++) { $meta = $statement->getColumnMeta($col); @@ -237,7 +237,7 @@ public static function createDebugPanel($connection, $explain = TRUE, $name = NU public static function toPairs(array $rows, $key = NULL, $value = NULL) { if (!$rows) { - return array(); + return []; } $keys = array_keys((array) reset($rows)); @@ -252,7 +252,7 @@ public static function toPairs(array $rows, $key = NULL, $value = NULL) } } - $return = array(); + $return = []; if ($key === NULL) { foreach ($rows as $row) { $return[] = ($value === NULL ? $row : $row[$value]); diff --git a/src/Database/ResultSet.php b/src/Database/ResultSet.php index 04b5e2330..aa3e77ec7 100644 --- a/src/Database/ResultSet.php +++ b/src/Database/ResultSet.php @@ -64,8 +64,8 @@ public function __construct(Connection $connection, $queryString, array $params) if (substr($queryString, 0, 2) === '::') { $connection->getPdo()->{substr($queryString, 2)}(); } elseif ($queryString !== NULL) { - static $types = array('boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, - 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL); + static $types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, + 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL]; $this->pdoStatement = $connection->getPdo()->prepare($queryString); foreach ($params as $key => $value) { $type = gettype($value); diff --git a/src/Database/SqlLiteral.php b/src/Database/SqlLiteral.php index 0c27638f3..8f1b40ff0 100644 --- a/src/Database/SqlLiteral.php +++ b/src/Database/SqlLiteral.php @@ -25,7 +25,7 @@ class SqlLiteral extends Nette\Object private $parameters; - public function __construct($value, array $parameters = array()) + public function __construct($value, array $parameters = []) { $this->value = (string) $value; $this->parameters = $parameters; diff --git a/src/Database/SqlPreprocessor.php b/src/Database/SqlPreprocessor.php index e951bc5f4..bdce6a853 100644 --- a/src/Database/SqlPreprocessor.php +++ b/src/Database/SqlPreprocessor.php @@ -51,9 +51,9 @@ public function process($params) { $this->params = $params; $this->counter = 0; $prev = -1; - $this->remaining = array(); + $this->remaining = []; $this->arrayMode = NULL; - $res = array(); + $res = []; while ($this->counter < count($params)) { $param = $params[$this->counter++]; @@ -68,14 +68,14 @@ public function process($params) $res[] = Nette\Utils\Strings::replace( $param, '~\'[^\']*+\'|"[^"]*+"|\?[a-z]*|^\s*+(?:INSERT|REPLACE)\b|\b(?:SET|WHERE|HAVING|ORDER BY|GROUP BY|KEY UPDATE)(?=[\s?]*+\z)|/\*.*?\*/|--[^\n]*~si', - array($this, 'callback') + [$this, 'callback'] ); } else { throw new Nette\InvalidArgumentException('There are more parameters than placeholders.'); } } - return array(implode(' ', $res), $this->remaining); + return [implode(' ', $res), $this->remaining]; } @@ -93,7 +93,7 @@ public function callback($m) return $m; } else { // command - static $modes = array( + static $modes = [ 'INSERT' => 'values', 'REPLACE' => 'values', 'KEY UPDATE' => 'set', @@ -102,7 +102,7 @@ public function callback($m) 'HAVING' => 'and', 'ORDER BY' => 'order', 'GROUP BY' => 'order', - ); + ]; $this->arrayMode = $modes[ltrim(strtoupper($m))]; return $m; } @@ -138,7 +138,7 @@ private function formatValue($value, $mode = NULL) } elseif ($value instanceof SqlLiteral) { $prep = clone $this; - list($res, $params) = $prep->process(array_merge(array($value->__toString()), $value->getParameters())); + list($res, $params) = $prep->process(array_merge([$value->__toString()], $value->getParameters())); $this->remaining = array_merge($this->remaining, $params); return $res; @@ -169,7 +169,7 @@ private function formatValue($value, $mode = NULL) } if (is_array($value)) { - $vx = $kx = array(); + $vx = $kx = []; if ($mode === 'auto') { $mode = $this->arrayMode; } @@ -180,7 +180,7 @@ private function formatValue($value, $mode = NULL) $kx[] = $this->delimite($k); } foreach ($value as $val) { - $vx2 = array(); + $vx2 = []; foreach ($val as $v) { $vx2[] = $this->formatValue($v); } @@ -242,7 +242,7 @@ private function formatValue($value, $mode = NULL) throw new Nette\InvalidArgumentException("Unknown placeholder ?$mode."); } - } elseif (in_array($mode, array('and', 'or', 'set', 'values', 'order'), TRUE)) { + } elseif (in_array($mode, ['and', 'or', 'set', 'values', 'order'], TRUE)) { $type = gettype($value); throw new Nette\InvalidArgumentException("Placeholder ?$mode expects array or Traversable object, $type given."); @@ -257,7 +257,7 @@ private function formatValue($value, $mode = NULL) private function delimite($name) { - return implode('.', array_map(array($this->driver, 'delimite'), explode('.', $name))); + return implode('.', array_map([$this->driver, 'delimite'], explode('.', $name))); } } diff --git a/src/Database/Structure.php b/src/Database/Structure.php index 401363aa4..b29fd85ee 100644 --- a/src/Database/Structure.php +++ b/src/Database/Structure.php @@ -111,7 +111,7 @@ public function getHasManyReference($table, $targetTable = NULL) } else { if (!isset($this->structure['hasMany'][$table])) { - return array(); + return []; } return $this->structure['hasMany'][$table]; } @@ -132,7 +132,7 @@ public function getBelongsToReference($table, $column = NULL) } else { if (!isset($this->structure['belongsTo'][$table])) { - return array(); + return []; } return $this->structure['belongsTo'][$table]; } @@ -159,7 +159,7 @@ protected function needStructure() return; } - $this->structure = $this->cache->load('structure', array($this, 'loadStructure')); + $this->structure = $this->cache->load('structure', [$this, 'loadStructure']); } @@ -171,7 +171,7 @@ public function loadStructure() { $driver = $this->connection->getSupplementalDriver(); - $structure = array(); + $structure = []; $structure['tables'] = $driver->getTables(); foreach ($structure['tables'] as $tablePair) { @@ -205,7 +205,7 @@ public function loadStructure() protected function analyzePrimaryKey(array $columns) { - $primary = array(); + $primary = []; foreach ($columns as $column) { if ($column['primary']) { $primary[] = $column['name']; diff --git a/src/Database/Table/ActiveRow.php b/src/Database/Table/ActiveRow.php index 4421f025b..f1d341d75 100644 --- a/src/Database/Table/ActiveRow.php +++ b/src/Database/Table/ActiveRow.php @@ -99,7 +99,7 @@ public function getPrimary($need = TRUE) } } else { - $primaryVal = array(); + $primaryVal = []; foreach ($primary as $key) { if (!isset($this->data[$key])) { if ($need) { @@ -173,7 +173,7 @@ public function update($data) $primary = $this->getPrimary(); if (!is_array($primary)) { - $primary = array($this->table->getPrimary() => $primary); + $primary = [$this->table->getPrimary() => $primary]; } $selection = $this->table->createSelectionInstance() diff --git a/src/Database/Table/GroupedSelection.php b/src/Database/Table/GroupedSelection.php index e6ae366ba..365d16875 100644 --- a/src/Database/Table/GroupedSelection.php +++ b/src/Database/Table/GroupedSelection.php @@ -93,7 +93,7 @@ public function aggregation($function) $aggregation = & $this->getRefTable($refPath)->aggregation[$refPath . $function . $this->getSql() . json_encode($this->sqlBuilder->getParameters())]; if ($aggregation === NULL) { - $aggregation = array(); + $aggregation = []; $selection = $this->createSelectionInstance(); $selection->getSqlBuilder()->importConditions($this->getSqlBuilder()); @@ -145,8 +145,8 @@ protected function execute() } parent::execute(); $this->sqlBuilder->setLimit($limit, NULL); - $data = array(); - $offset = array(); + $data = []; + $offset = []; $this->accessColumn($this->column); foreach ((array) $this->rows as $key => $row) { $ref = & $data[$row[$this->column]]; @@ -166,7 +166,7 @@ protected function execute() $this->observeCache = $this; if ($this->data === NULL) { - $this->data = array(); + $this->data = []; } else { foreach ($this->data as $row) { $row->setTable($this); // injects correct parent GroupedSelection diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 154372d70..668021d07 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -69,7 +69,7 @@ class Selection extends Nette\Object implements \Iterator, IRowContainer, \Array protected $specificCacheKey; /** @var array of [conditions => [key => IRow]]; used by GroupedSelection */ - protected $aggregation = array(); + protected $aggregation = []; /** @var array of touched columns */ protected $accessedColumns; @@ -81,7 +81,7 @@ class Selection extends Nette\Object implements \Iterator, IRowContainer, \Array protected $observeCache = FALSE; /** @var array of primary key values */ - protected $keys = array(); + protected $keys = []; /** @@ -197,7 +197,7 @@ public function getPreviousAccessedColumns() if ($this->cache && $this->previousAccessedColumns === NULL) { $this->accessedColumns = $this->previousAccessedColumns = $this->cache->load($this->getGeneralCacheKey()); if ($this->previousAccessedColumns === NULL) { - $this->previousAccessedColumns = array(); + $this->previousAccessedColumns = []; } } @@ -281,7 +281,7 @@ public function fetchAssoc($path) public function select($columns) { $this->emptyResultSet(); - call_user_func_array(array($this->sqlBuilder, 'addSelect'), func_get_args()); + call_user_func_array([$this->sqlBuilder, 'addSelect'], func_get_args()); return $this; } @@ -318,9 +318,9 @@ public function wherePrimary($key) * @param mixed ... * @return self */ - public function where($condition, $parameters = array()) + public function where($condition, $parameters = []) { - if (is_array($condition) && $parameters === array()) { // where(array('column1' => 1, 'column2 > ?' => 2)) + if (is_array($condition) && $parameters === []) { // where(array('column1' => 1, 'column2 > ?' => 2)) foreach ($condition as $key => $val) { if (is_int($key)) { $this->where($val); // where('full condition') @@ -332,7 +332,7 @@ public function where($condition, $parameters = array()) } $this->emptyResultSet(); - call_user_func_array(array($this->sqlBuilder, 'addWhere'), func_get_args()); + call_user_func_array([$this->sqlBuilder, 'addWhere'], func_get_args()); return $this; } @@ -345,7 +345,7 @@ public function where($condition, $parameters = array()) public function order($columns) { $this->emptyResultSet(); - call_user_func_array(array($this->sqlBuilder, 'addOrder'), func_get_args()); + call_user_func_array([$this->sqlBuilder, 'addOrder'], func_get_args()); return $this; } @@ -387,7 +387,7 @@ public function page($page, $itemsPerPage, & $numOfPages = NULL) public function group($columns) { $this->emptyResultSet(); - call_user_func_array(array($this->sqlBuilder, 'setGroup'), func_get_args()); + call_user_func_array([$this->sqlBuilder, 'setGroup'], func_get_args()); return $this; } @@ -400,7 +400,7 @@ public function group($columns) public function having($having) { $this->emptyResultSet(); - call_user_func_array(array($this->sqlBuilder, 'setHaving'), func_get_args()); + call_user_func_array([$this->sqlBuilder, 'setHaving'], func_get_args()); return $this; } @@ -493,14 +493,14 @@ protected function execute() } catch (DriverException $exception) { if (!$this->sqlBuilder->getSelect() && $this->previousAccessedColumns) { $this->previousAccessedColumns = FALSE; - $this->accessedColumns = array(); + $this->accessedColumns = []; $result = $this->query($this->getSql()); } else { throw $exception; } } - $this->rows = array(); + $this->rows = []; $usedPrimary = TRUE; foreach ($result->getPdoStatement() as $key => $row) { $row = $this->createRow($result->normalizeRow($row)); @@ -556,7 +556,7 @@ protected function emptyResultSet($saveCache = TRUE) $this->rows = NULL; $this->specificCacheKey = NULL; $this->generalCacheKey = NULL; - $this->refCache['referencingPrototype'] = array(); + $this->refCache['referencingPrototype'] = []; } @@ -607,9 +607,9 @@ protected function getGeneralCacheKey() return $this->generalCacheKey; } - $key = array(__CLASS__, $this->name, $this->sqlBuilder->getConditions()); + $key = [__CLASS__, $this->name, $this->sqlBuilder->getConditions()]; if (!$this->generalCacheTraceKey) { - $trace = array(); + $trace = []; foreach (debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : FALSE) as $item) { $trace[] = isset($item['file'], $item['line']) ? $item['file'] . $item['line'] : NULL; }; @@ -655,13 +655,13 @@ public function accessColumn($key, $selectColumn = TRUE) } if ($selectColumn && !$this->sqlBuilder->getSelect() && $this->previousAccessedColumns && ($key === NULL || !isset($this->previousAccessedColumns[$key]))) { - $this->previousAccessedColumns = array(); + $this->previousAccessedColumns = []; if ($this->sqlBuilder->getLimit()) { $generalCacheKey = $this->generalCacheKey; $sqlBuilder = $this->sqlBuilder; - $primaryValues = array(); + $primaryValues = []; foreach ((array) $this->rows as $row) { $primary = $row->getPrimary(); $primaryValues[] = is_array($primary) ? array_values($primary) : $primary; @@ -753,7 +753,7 @@ public function insert($data) } if (is_array($this->getPrimary())) { - $primaryKey = array(); + $primaryKey = []; foreach ((array) $this->getPrimary() as $key) { if (!isset($data[$key])) { @@ -807,7 +807,7 @@ public function update($data) return $this->context->queryArgs( $this->sqlBuilder->buildUpdateQuery(), - array_merge(array($data), $this->sqlBuilder->getParameters()) + array_merge([$data], $this->sqlBuilder->getParameters()) )->getRowCount(); } @@ -852,7 +852,7 @@ public function getReferencedTable(ActiveRow $row, $table, $column = NULL) $cacheKeys = & $referenced['cacheKeys']; if ($selection === NULL || ($checkPrimaryKey !== NULL && !isset($cacheKeys[$checkPrimaryKey]))) { $this->execute(); - $cacheKeys = array(); + $cacheKeys = []; foreach ($this->rows as $row) { if ($row[$column] === NULL) { continue; @@ -866,7 +866,7 @@ public function getReferencedTable(ActiveRow $row, $table, $column = NULL) $selection = $this->createSelectionInstance($table); $selection->where($selection->getPrimary(), array_keys($cacheKeys)); } else { - $selection = array(); + $selection = []; } } diff --git a/src/Database/Table/SqlBuilder.php b/src/Database/Table/SqlBuilder.php index f16ca626e..699c52fed 100644 --- a/src/Database/Table/SqlBuilder.php +++ b/src/Database/Table/SqlBuilder.php @@ -35,25 +35,25 @@ class SqlBuilder extends Nette\Object protected $delimitedTable; /** @var array of column to select */ - protected $select = array(); + protected $select = []; /** @var array of where conditions */ - protected $where = array(); + protected $where = []; /** @var array of where conditions for caching */ - protected $conditions = array(); + protected $conditions = []; /** @var array of parameters passed to where conditions */ - protected $parameters = array( - 'select' => array(), - 'where' => array(), - 'group' => array(), - 'having' => array(), - 'order' => array(), - ); + protected $parameters = [ + 'select' => [], + 'where' => [], + 'group' => [], + 'having' => [], + 'order' => [], + ]; /** @var array or columns to order by */ - protected $order = array(); + protected $order = []; /** @var int number of rows to fetch */ protected $limit = NULL; @@ -84,7 +84,7 @@ public function __construct($tableName, Context $context) $this->conventions = $context->getConventions(); $this->structure = $context->getStructure(); - $this->delimitedTable = implode('.', array_map(array($this->driver, 'delimite'), explode('.', $tableName))); + $this->delimitedTable = implode('.', array_map([$this->driver, 'delimite'], explode('.', $tableName))); } @@ -131,7 +131,7 @@ public function buildSelectQuery($columns = NULL) $queryCondition = $this->buildConditions(); $queryEnd = $this->buildQueryEnd(); - $joins = array(); + $joins = []; $this->parseJoins($joins, $queryCondition); $this->parseJoins($joins, $queryEnd); @@ -141,19 +141,19 @@ public function buildSelectQuery($columns = NULL) } elseif ($columns) { $prefix = $joins ? "{$this->delimitedTable}." : ''; - $cols = array(); + $cols = []; foreach ($columns as $col) { $cols[] = $prefix . $col; } $querySelect = $this->buildSelect($cols); } elseif ($this->group && !$this->driver->isSupported(ISupplementalDriver::SUPPORT_SELECT_UNGROUPED_COLUMNS)) { - $querySelect = $this->buildSelect(array($this->group)); + $querySelect = $this->buildSelect([$this->group]); $this->parseJoins($joins, $querySelect); } else { $prefix = $joins ? "{$this->delimitedTable}." : ''; - $querySelect = $this->buildSelect(array($prefix . '*')); + $querySelect = $this->buildSelect([$prefix . '*']); } @@ -207,7 +207,7 @@ public function getSelect() } - public function addWhere($condition, $parameters = array()) + public function addWhere($condition, $parameters = []) { if (is_array($condition) && is_array($parameters) && !empty($parameters)) { return $this->addWhereComposition($condition, $parameters); @@ -275,7 +275,7 @@ public function addWhere($condition, $parameters = array()) $replace = $match[2][0] . '(' . $clone->getSql() . ')'; $this->parameters['where'] = array_merge($this->parameters['where'], $clone->getSqlBuilder()->getParameters()); } else { - $arg = array(); + $arg = []; foreach ($clone as $row) { $arg[] = array_values(iterator_to_array($row)); } @@ -494,7 +494,7 @@ public function parseJoinsCb(& $joins, $match) $tableAlias = $parentAlias . '_ref'; } - $joins[$tableAlias . $column] = array($table, $tableAlias, $parentAlias, $column, $primary); + $joins[$tableAlias . $column] = [$table, $tableAlias, $parentAlias, $column, $primary]; $parent = $table; $parentAlias = $tableAlias; } diff --git a/src/Database/deprecated/DiscoveredReflection.php b/src/Database/deprecated/DiscoveredReflection.php index 52f1a5c79..b0f0e8311 100644 --- a/src/Database/deprecated/DiscoveredReflection.php +++ b/src/Database/deprecated/DiscoveredReflection.php @@ -20,7 +20,7 @@ class DiscoveredReflection extends Nette\Object implements Nette\Database\IRefle protected $cache; /** @var array */ - protected $structure = array(); + protected $structure = []; /** @var array */ protected $loadedStructure; @@ -36,7 +36,7 @@ public function __construct(Nette\Database\Connection $connection, Nette\Caching $this->connection = $connection; if ($cacheStorage) { $this->cache = new Nette\Caching\Cache($cacheStorage, 'Nette.Database.' . md5($connection->getDsn())); - $this->structure = $this->loadedStructure = $this->cache->load('structure') ?: array(); + $this->structure = $this->loadedStructure = $this->cache->load('structure') ?: []; } } @@ -57,7 +57,7 @@ public function getPrimary($table) } $columns = $this->connection->getSupplementalDriver()->getColumns($table); - $primary = array(); + $primary = []; foreach ($columns as $column) { if ($column['primary']) { $primary[] = $column['name']; @@ -77,16 +77,16 @@ public function getPrimary($table) public function getHasManyReference($table, $key, $refresh = TRUE) { if (isset($this->structure['hasMany'][strtolower($table)])) { - $candidates = $columnCandidates = array(); + $candidates = $columnCandidates = []; foreach ($this->structure['hasMany'][strtolower($table)] as $targetPair) { list($targetColumn, $targetTable) = $targetPair; if (stripos($targetTable, $key) === FALSE) { continue; } - $candidates[] = array($targetTable, $targetColumn); + $candidates[] = [$targetTable, $targetColumn]; if (stripos($targetColumn, $table) !== FALSE) { - $columnCandidates[] = $candidate = array($targetTable, $targetColumn); + $columnCandidates[] = $candidate = [$targetTable, $targetColumn]; if (strtolower($targetTable) === strtolower($key)) { return $candidate; } @@ -124,7 +124,7 @@ public function getBelongsToReference($table, $key, $refresh = TRUE) if (isset($this->structure['belongsTo'][strtolower($table)])) { foreach ($this->structure['belongsTo'][strtolower($table)] as $column => $targetTable) { if (stripos($column, $key) !== FALSE) { - return array($targetTable, $column); + return [$targetTable, $column]; } } } @@ -140,7 +140,7 @@ public function getBelongsToReference($table, $key, $refresh = TRUE) protected function reloadAllForeignKeys() { - $this->structure['hasMany'] = $this->structure['belongsTo'] = array(); + $this->structure['hasMany'] = $this->structure['belongsTo'] = []; foreach ($this->connection->getSupplementalDriver()->getTables() as $table) { if ($table['view'] == FALSE) { @@ -160,7 +160,7 @@ protected function reloadForeignKeys($table) { foreach ($this->connection->getSupplementalDriver()->getForeignKeys($table) as $row) { $this->structure['belongsTo'][strtolower($table)][$row['local']] = $row['table']; - $this->structure['hasMany'][strtolower($row['table'])][$row['local'] . $table] = array($row['local'], $table); + $this->structure['hasMany'][strtolower($row['table'])][$row['local'] . $table] = [$row['local'], $table]; } if (isset($this->structure['belongsTo'][$table])) { diff --git a/tests/Database/Connection.exceptions.mysql.phpt b/tests/Database/Connection.exceptions.mysql.phpt index 912efdd4a..cf544b998 100644 --- a/tests/Database/Connection.exceptions.mysql.phpt +++ b/tests/Database/Connection.exceptions.mysql.phpt @@ -15,7 +15,7 @@ $e = Assert::exception(function() use ($options) { }, 'Nette\Database\ConnectionException', '%a% Access denied for user %a%'); Assert::same(1045, $e->getDriverCode()); -Assert::contains($e->getSqlState(), array('HY000', '28000')); +Assert::contains($e->getSqlState(), ['HY000', '28000']); Assert::same($e->getCode(), $e->getSqlState()); diff --git a/tests/Database/Connection.fetch.phpt b/tests/Database/Connection.fetch.phpt index 4ce29233c..7b37a7d35 100644 --- a/tests/Database/Connection.fetch.phpt +++ b/tests/Database/Connection.fetch.phpt @@ -15,10 +15,10 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName test(function() use ($connection) { // fetch $row = $connection->fetch('SELECT name, id FROM author WHERE id = ?', 11); Assert::type( 'Nette\Database\Row', $row ); - Assert::equal(Nette\Database\Row::from(array( + Assert::equal(Nette\Database\Row::from([ 'name' => 'Jakub Vrana', 'id' => 11, - )), $row); + ]), $row); }); @@ -29,17 +29,17 @@ test(function() use ($connection) { // fetchField test(function() use ($connection) { // fetchPairs $pairs = $connection->fetchPairs('SELECT name, id FROM author WHERE id > ? ORDER BY id', 11); - Assert::same(array( + Assert::same([ 'David Grudl' => 12, 'Geek' => 13, - ), $pairs); + ], $pairs); }); test(function() use ($connection) { // fetchAll $arr = $connection->fetchAll('SELECT name, id FROM author WHERE id < ? ORDER BY id', 13); - Assert::equal(array( - Nette\Database\Row::from(array('name' => 'Jakub Vrana', 'id' => 11)), - Nette\Database\Row::from(array('name' => 'David Grudl', 'id' => 12)), - ), $arr); + Assert::equal([ + Nette\Database\Row::from(['name' => 'Jakub Vrana', 'id' => 11]), + Nette\Database\Row::from(['name' => 'David Grudl', 'id' => 12]), + ], $arr); }); diff --git a/tests/Database/Connection.lazy.phpt b/tests/Database/Connection.lazy.phpt index 7cfd26bfe..0cd820c67 100644 --- a/tests/Database/Connection.lazy.phpt +++ b/tests/Database/Connection.lazy.phpt @@ -20,7 +20,7 @@ test(function() { // non lazy test(function() { // lazy - $connection = new Nette\Database\Connection('dsn', 'user', 'password', array('lazy' => TRUE)); + $connection = new Nette\Database\Connection('dsn', 'user', 'password', ['lazy' => TRUE]); $context = new Nette\Database\Context($connection, new Structure($connection, new DevNullStorage())); Assert::exception(function() use ($context) { $context->query('SELECT ?', 10); @@ -29,7 +29,7 @@ test(function() { // lazy test(function() { - $connection = new Nette\Database\Connection('dsn', 'user', 'password', array('lazy' => TRUE)); + $connection = new Nette\Database\Connection('dsn', 'user', 'password', ['lazy' => TRUE]); Assert::exception(function() use ($connection) { $connection->quote('x'); }, 'Nette\Database\DriverException', 'invalid data source name'); @@ -37,7 +37,7 @@ test(function() { test(function() { // connect & disconnect - $options = Tester\Environment::loadData() + array('user' => NULL, 'password' => NULL); + $options = Tester\Environment::loadData() + ['user' => NULL, 'password' => NULL]; $connections = 1; $connection = new Nette\Database\Connection($options['dsn'], $options['user'], $options['password']); diff --git a/tests/Database/Connection.preprocess.phpt b/tests/Database/Connection.preprocess.phpt index bd06b32da..7d912a53f 100644 --- a/tests/Database/Connection.preprocess.phpt +++ b/tests/Database/Connection.preprocess.phpt @@ -10,6 +10,6 @@ use Tester\Assert; require __DIR__ . '/connect.inc.php'; // create $connection -Assert::same(array('SELECT name FROM author', array()), $connection->preprocess('SELECT name FROM author')); +Assert::same(['SELECT name FROM author', []], $connection->preprocess('SELECT name FROM author')); -Assert::same(array("SELECT 'string'", array()), $connection->preprocess('SELECT ?', 'string')); +Assert::same(["SELECT 'string'", []], $connection->preprocess('SELECT ?', 'string')); diff --git a/tests/Database/Connection.query.phpt b/tests/Database/Connection.query.phpt index 0911cb388..a016984fc 100644 --- a/tests/Database/Connection.query.phpt +++ b/tests/Database/Connection.query.phpt @@ -26,6 +26,6 @@ test(function() use ($connection) { test(function() use ($connection) { - $res = $connection->queryArgs('SELECT id FROM author WHERE id = ? OR id = ?', array(11, 12)); + $res = $connection->queryArgs('SELECT id FROM author WHERE id = ? OR id = ?', [11, 12]); Assert::same( 'SELECT id FROM author WHERE id = 11 OR id = 12', $res->getQueryString() ); }); diff --git a/tests/Database/Context.fetch.phpt b/tests/Database/Context.fetch.phpt index 08120d2fd..573b66152 100644 --- a/tests/Database/Context.fetch.phpt +++ b/tests/Database/Context.fetch.phpt @@ -15,10 +15,10 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName test(function() use ($context) { // fetch $row = $context->fetch('SELECT name, id FROM author WHERE id = ?', 11); Assert::type( 'Nette\Database\Row', $row ); - Assert::equal(Nette\Database\Row::from(array( + Assert::equal(Nette\Database\Row::from([ 'name' => 'Jakub Vrana', 'id' => 11, - )), $row); + ]), $row); }); @@ -29,17 +29,17 @@ test(function() use ($context) { // fetchField test(function() use ($context) { // fetchPairs $pairs = $context->fetchPairs('SELECT name, id FROM author WHERE id > ? ORDER BY id', 11); - Assert::same(array( + Assert::same([ 'David Grudl' => 12, 'Geek' => 13, - ), $pairs); + ], $pairs); }); test(function() use ($context) { // fetchAll $arr = $context->fetchAll('SELECT name, id FROM author WHERE id < ? ORDER BY id', 13); - Assert::equal(array( - Nette\Database\Row::from(array('name' => 'Jakub Vrana', 'id' => 11)), - Nette\Database\Row::from(array('name' => 'David Grudl', 'id' => 12)), - ), $arr); + Assert::equal([ + Nette\Database\Row::from(['name' => 'Jakub Vrana', 'id' => 11]), + Nette\Database\Row::from(['name' => 'David Grudl', 'id' => 12]), + ], $arr); }); diff --git a/tests/Database/Context.query.phpt b/tests/Database/Context.query.phpt index 4379d892a..e5d72aa54 100644 --- a/tests/Database/Context.query.phpt +++ b/tests/Database/Context.query.phpt @@ -26,6 +26,6 @@ test(function() use ($context) { test(function() use ($context) { - $res = $context->queryArgs('SELECT id FROM author WHERE id = ? OR id = ?', array(11, 12)); + $res = $context->queryArgs('SELECT id FROM author WHERE id = ? OR id = ?', [11, 12]); Assert::same( 'SELECT id FROM author WHERE id = 11 OR id = 12', $res->getQueryString() ); }); diff --git a/tests/Database/Conventions/DiscoveredConventions.getBelongsToReference().phpt b/tests/Database/Conventions/DiscoveredConventions.getBelongsToReference().phpt index eba286561..6da5accfd 100644 --- a/tests/Database/Conventions/DiscoveredConventions.getBelongsToReference().phpt +++ b/tests/Database/Conventions/DiscoveredConventions.getBelongsToReference().phpt @@ -13,71 +13,71 @@ require __DIR__ . '/../../bootstrap.php'; // basic test test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn(array( + $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([ 'author_id' => 'authors', 'translator_id' => 'authors', 'another_id' => 'another_table', - ))->twice(); + ])->twice(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('authors', 'author_id'), $conventions->getBelongsToReference('books', 'author')); - Assert::same(array('authors', 'translator_id'), $conventions->getBelongsToReference('books', 'translator')); + Assert::same(['authors', 'author_id'], $conventions->getBelongsToReference('books', 'author')); + Assert::same(['authors', 'translator_id'], $conventions->getBelongsToReference('books', 'translator')); }); // basic test test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getBelongsToReference')->with('public.books')->andReturn(array( + $structure->shouldReceive('getBelongsToReference')->with('public.books')->andReturn([ 'author_id' => 'public.authors', 'translator_id' => 'public.authors', 'another_id' => 'public.another_table', - ))->twice(); + ])->twice(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('public.authors', 'author_id'), $conventions->getBelongsToReference('public.books', 'author')); - Assert::same(array('public.authors', 'translator_id'), $conventions->getBelongsToReference('public.books', 'translator')); + Assert::same(['public.authors', 'author_id'], $conventions->getBelongsToReference('public.books', 'author')); + Assert::same(['public.authors', 'translator_id'], $conventions->getBelongsToReference('public.books', 'translator')); }); // tests order of table columns with foreign keys test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn(array( + $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([ 'translator_id' => 'authors', 'author_id' => 'authors', - ))->twice(); + ])->twice(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('authors', 'author_id'), $conventions->getBelongsToReference('books', 'author')); - Assert::same(array('authors', 'translator_id'), $conventions->getBelongsToReference('books', 'translator')); + Assert::same(['authors', 'author_id'], $conventions->getBelongsToReference('books', 'author')); + Assert::same(['authors', 'translator_id'], $conventions->getBelongsToReference('books', 'translator')); }); // tests case insensivity test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn(array( + $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([ 'author_id' => 'authors', 'translator_id' => 'authors', - ))->twice(); + ])->twice(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('authors', 'author_id'), $conventions->getBelongsToReference('books', 'Author')); - Assert::same(array('authors', 'translator_id'), $conventions->getBelongsToReference('books', 'Translator')); + Assert::same(['authors', 'author_id'], $conventions->getBelongsToReference('books', 'Author')); + Assert::same(['authors', 'translator_id'], $conventions->getBelongsToReference('books', 'Translator')); }); // tests case insensivity and prefixes test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getBelongsToReference')->with('nBooks')->andReturn(array( + $structure->shouldReceive('getBelongsToReference')->with('nBooks')->andReturn([ 'authorId' => 'nAuthors', 'translatorId' => 'nAuthors', - ))->twice(); + ])->twice(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('nAuthors', 'authorId'), $conventions->getBelongsToReference('nBooks', 'author')); - Assert::same(array('nAuthors', 'translatorId'), $conventions->getBelongsToReference('nBooks', 'translator')); + Assert::same(['nAuthors', 'authorId'], $conventions->getBelongsToReference('nBooks', 'author')); + Assert::same(['nAuthors', 'translatorId'], $conventions->getBelongsToReference('nBooks', 'translator')); }); @@ -86,16 +86,16 @@ test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); $structure->shouldReceive('isRebuilt')->andReturn(FALSE); $structure->shouldReceive('rebuild'); - $structure->shouldReceive('getBelongsToReference')->andReturn(array())->once(); - $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn(array( + $structure->shouldReceive('getBelongsToReference')->andReturn([])->once(); + $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([ 'author_id' => 'authors', 'translator_id' => 'authors', 'another_id' => 'another_table', - ))->twice(); + ])->twice(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('authors', 'author_id'), $conventions->getBelongsToReference('books', 'author')); - Assert::same(array('authors', 'translator_id'), $conventions->getBelongsToReference('books', 'translator')); + Assert::same(['authors', 'author_id'], $conventions->getBelongsToReference('books', 'author')); + Assert::same(['authors', 'translator_id'], $conventions->getBelongsToReference('books', 'translator')); }); @@ -103,7 +103,7 @@ test(function() { test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); $structure->shouldReceive('isRebuilt')->andReturn(TRUE); - $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn(array())->once(); + $structure->shouldReceive('getBelongsToReference')->with('books')->andReturn([])->once(); $conventions = new DiscoveredConventions($structure); Assert::null($conventions->getBelongsToReference('books', 'author')); diff --git a/tests/Database/Conventions/DiscoveredConventions.getHasManyReference().phpt b/tests/Database/Conventions/DiscoveredConventions.getHasManyReference().phpt index f00d41151..e6bd9e7ff 100644 --- a/tests/Database/Conventions/DiscoveredConventions.getHasManyReference().phpt +++ b/tests/Database/Conventions/DiscoveredConventions.getHasManyReference().phpt @@ -13,22 +13,22 @@ require __DIR__ . '/../../bootstrap.php'; // basic test singular test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getHasManyReference')->with('author')->andReturn(array( - 'book' => array('author_id', 'translator_id'), - 'book_topics' => array('author_id'), - 'another' => array('author_id'), - ))->times(3); - $structure->shouldReceive('getHasManyReference')->with('author')->andReturn(array( - 'book' => array('author_id'), - )); + $structure->shouldReceive('getHasManyReference')->with('author')->andReturn([ + 'book' => ['author_id', 'translator_id'], + 'book_topics' => ['author_id'], + 'another' => ['author_id'], + ])->times(3); + $structure->shouldReceive('getHasManyReference')->with('author')->andReturn([ + 'book' => ['author_id'], + ]); $conventions = new DiscoveredConventions($structure); // match by key = target_table - Assert::same(array('book', 'author_id'), $conventions->getHasManyReference('author', 'book')); + Assert::same(['book', 'author_id'], $conventions->getHasManyReference('author', 'book')); // match by key = target table - Assert::same(array('book_topics', 'author_id'), $conventions->getHasManyReference('author', 'book_topics')); + Assert::same(['book_topics', 'author_id'], $conventions->getHasManyReference('author', 'book_topics')); // test too many column candidates Assert::throws(function() use ($conventions) { @@ -36,35 +36,35 @@ test(function() { }, 'Nette\Database\Conventions\AmbiguousReferenceKeyException'); // test one column candidate - Assert::same(array('book', 'author_id'), $conventions->getHasManyReference('author', 'boo')); + Assert::same(['book', 'author_id'], $conventions->getHasManyReference('author', 'boo')); }); // basic test singular with schema test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getHasManyReference')->with('public.author')->andReturn(array( - 'public.book' => array('author_id', 'translator_id'), - 'public.book_topics' => array('author_id'), - 'public.another' => array('author_id'), - ))->times(6); - $structure->shouldReceive('getHasManyReference')->with('public.author')->andReturn(array( - 'public.book' => array('author_id'), - ))->times(2); + $structure->shouldReceive('getHasManyReference')->with('public.author')->andReturn([ + 'public.book' => ['author_id', 'translator_id'], + 'public.book_topics' => ['author_id'], + 'public.another' => ['author_id'], + ])->times(6); + $structure->shouldReceive('getHasManyReference')->with('public.author')->andReturn([ + 'public.book' => ['author_id'], + ])->times(2); $conventions = new DiscoveredConventions($structure); // match by key = target ns table - Assert::same(array('public.book', 'author_id'), $conventions->getHasManyReference('public.author', 'public.book')); + Assert::same(['public.book', 'author_id'], $conventions->getHasManyReference('public.author', 'public.book')); // match by key = target table - Assert::same(array('public.book', 'author_id'), $conventions->getHasManyReference('public.author', 'book')); + Assert::same(['public.book', 'author_id'], $conventions->getHasManyReference('public.author', 'book')); // match by key = target ns table - Assert::same(array('public.book_topics', 'author_id'), $conventions->getHasManyReference('public.author', 'public.book_topics')); + Assert::same(['public.book_topics', 'author_id'], $conventions->getHasManyReference('public.author', 'public.book_topics')); // match by key = target table - Assert::same(array('public.book_topics', 'author_id'), $conventions->getHasManyReference('public.author', 'book_topics')); + Assert::same(['public.book_topics', 'author_id'], $conventions->getHasManyReference('public.author', 'book_topics')); // test too many column candidates, ns table name Assert::throws(function() use ($conventions) { @@ -77,29 +77,29 @@ test(function() { }, 'Nette\Database\Conventions\AmbiguousReferenceKeyException'); // test one column candidate, ns table name - Assert::same(array('public.book', 'author_id'), $conventions->getHasManyReference('public.author', 'public.boo')); + Assert::same(['public.book', 'author_id'], $conventions->getHasManyReference('public.author', 'public.boo')); // test one column candidate - Assert::same(array('public.book', 'author_id'), $conventions->getHasManyReference('public.author', 'boo')); + Assert::same(['public.book', 'author_id'], $conventions->getHasManyReference('public.author', 'boo')); }); // basic test plural test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getHasManyReference')->with('authors')->andReturn(array( - 'books' => array('author_id', 'translator_id'), - ))->once(); - $structure->shouldReceive('getHasManyReference')->with('authors')->andReturn(array( - 'books' => array('author_id'), - 'book_topics' => array('author_id'), - 'another' => array('author_id'), - ))->twice(); + $structure->shouldReceive('getHasManyReference')->with('authors')->andReturn([ + 'books' => ['author_id', 'translator_id'], + ])->once(); + $structure->shouldReceive('getHasManyReference')->with('authors')->andReturn([ + 'books' => ['author_id'], + 'book_topics' => ['author_id'], + 'another' => ['author_id'], + ])->twice(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('books', 'author_id'), $conventions->getHasManyReference('authors', 'books')); - Assert::same(array('book_topics', 'author_id'), $conventions->getHasManyReference('authors', 'topics')); + Assert::same(['books', 'author_id'], $conventions->getHasManyReference('authors', 'books')); + Assert::same(['book_topics', 'author_id'], $conventions->getHasManyReference('authors', 'topics')); // test too many candidates Assert::throws(function() use ($conventions) { @@ -111,22 +111,22 @@ test(function() { // tests column match with source table test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getHasManyReference')->with('author')->andReturn(array( - 'book' => array('author_id', 'tran_id'), - ))->once(); - $structure->shouldReceive('getHasManyReference')->with('author')->andReturn(array( - 'book' => array('auth_id', 't_id'), - ))->once(); - $structure->shouldReceive('getHasManyReference')->with('authors')->andReturn(array( - 'books' => array('auth_id', 't_id'), - ))->once(); + $structure->shouldReceive('getHasManyReference')->with('author')->andReturn([ + 'book' => ['author_id', 'tran_id'], + ])->once(); + $structure->shouldReceive('getHasManyReference')->with('author')->andReturn([ + 'book' => ['auth_id', 't_id'], + ])->once(); + $structure->shouldReceive('getHasManyReference')->with('authors')->andReturn([ + 'books' => ['auth_id', 't_id'], + ])->once(); $conventions = new DiscoveredConventions($structure); // prefer the match of source table with joining column - Assert::same(array('book', 'author_id'), $conventions->getHasManyReference('author', 'book')); + Assert::same(['book', 'author_id'], $conventions->getHasManyReference('author', 'book')); // prefer the first possible column - Assert::same(array('book', 'auth_id'), $conventions->getHasManyReference('author', 'book')); + Assert::same(['book', 'auth_id'], $conventions->getHasManyReference('author', 'book')); // no propper match of key and target table name Assert::throws(function() use ($conventions) { @@ -138,13 +138,13 @@ test(function() { // tests case insensivity and prefixes test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getHasManyReference')->with('nAuthors')->andReturn(array( - 'nBooks' => array('authorId', 'translatorId'), - ))->once(); + $structure->shouldReceive('getHasManyReference')->with('nAuthors')->andReturn([ + 'nBooks' => ['authorId', 'translatorId'], + ])->once(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('nBooks', 'authorId'), $conventions->getHasManyReference('nAuthors', 'nbooks')); + Assert::same(['nBooks', 'authorId'], $conventions->getHasManyReference('nAuthors', 'nbooks')); }); @@ -153,13 +153,13 @@ test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); $structure->shouldReceive('isRebuilt')->andReturn(FALSE); $structure->shouldReceive('rebuild'); - $structure->shouldReceive('getHasManyReference')->with('author')->andReturn(array())->once(); - $structure->shouldReceive('getHasManyReference')->with('author')->andReturn(array( - 'book' => array('author_id', 'translator_id'), - ))->once(); + $structure->shouldReceive('getHasManyReference')->with('author')->andReturn([])->once(); + $structure->shouldReceive('getHasManyReference')->with('author')->andReturn([ + 'book' => ['author_id', 'translator_id'], + ])->once(); $conventions = new DiscoveredConventions($structure); - Assert::same(array('book', 'author_id'), $conventions->getHasManyReference('author', 'book')); + Assert::same(['book', 'author_id'], $conventions->getHasManyReference('author', 'book')); }); @@ -167,7 +167,7 @@ test(function() { test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); $structure->shouldReceive('isRebuilt')->andReturn(TRUE); - $structure->shouldReceive('getHasManyReference')->with('author')->andReturn(array())->once(); + $structure->shouldReceive('getHasManyReference')->with('author')->andReturn([])->once(); $conventions = new DiscoveredConventions($structure); Assert::null($conventions->getHasManyReference('author', 'book')); diff --git a/tests/Database/Conventions/DiscoveredConventions.getPrimary().phpt b/tests/Database/Conventions/DiscoveredConventions.getPrimary().phpt index 38895b225..6de7a3929 100644 --- a/tests/Database/Conventions/DiscoveredConventions.getPrimary().phpt +++ b/tests/Database/Conventions/DiscoveredConventions.getPrimary().phpt @@ -12,8 +12,8 @@ require __DIR__ . '/../../bootstrap.php'; test(function() { $structure = Mockery::mock('Nette\Database\IStructure'); - $structure->shouldReceive('getPrimaryKey')->with('books_x_tags')->andReturn(array('book_id', 'tag_id')); + $structure->shouldReceive('getPrimaryKey')->with('books_x_tags')->andReturn(['book_id', 'tag_id']); $conventions = new DiscoveredConventions($structure); - Assert::same(array('book_id', 'tag_id'), $conventions->getPrimary('books_x_tags')); + Assert::same(['book_id', 'tag_id'], $conventions->getPrimary('books_x_tags')); }); diff --git a/tests/Database/Conventions/StaticConventions.phpt b/tests/Database/Conventions/StaticConventions.phpt index 9bb85996d..6a3f7b0bf 100644 --- a/tests/Database/Conventions/StaticConventions.phpt +++ b/tests/Database/Conventions/StaticConventions.phpt @@ -13,9 +13,9 @@ require __DIR__ . '/../../bootstrap.php'; test(function() { $conventions = new StaticConventions; Assert::same('id', $conventions->getPrimary('book')); - Assert::same(array('author', 'book_id'), $conventions->getHasManyReference('book', 'author')); - Assert::same(array('translator', 'book_id'), $conventions->getHasManyReference('book', 'translator')); - Assert::same(array('book', 'book_id'), $conventions->getBelongsToReference('author', 'book')); + Assert::same(['author', 'book_id'], $conventions->getHasManyReference('book', 'author')); + Assert::same(['translator', 'book_id'], $conventions->getHasManyReference('book', 'translator')); + Assert::same(['book', 'book_id'], $conventions->getBelongsToReference('author', 'book')); }); @@ -28,36 +28,36 @@ test(function() { test(function() { $conventions = new StaticConventions('id_%s', 'id_%s'); Assert::same('id_book', $conventions->getPrimary('book')); - Assert::same(array('author', 'id_book'), $conventions->getHasManyReference('book', 'author')); - Assert::same(array('book', 'id_book'), $conventions->getBelongsToReference('author', 'book')); + Assert::same(['author', 'id_book'], $conventions->getHasManyReference('book', 'author')); + Assert::same(['book', 'id_book'], $conventions->getBelongsToReference('author', 'book')); }); test(function() { $conventions = new StaticConventions('%sId', '%sId'); Assert::same('bookId', $conventions->getPrimary('book')); - Assert::same(array('author', 'bookId'), $conventions->getHasManyReference('book', 'author')); - Assert::same(array('book', 'bookId'), $conventions->getBelongsToReference('author', 'book')); + Assert::same(['author', 'bookId'], $conventions->getHasManyReference('book', 'author')); + Assert::same(['book', 'bookId'], $conventions->getBelongsToReference('author', 'book')); }); test(function() { $conventions = new StaticConventions('id', '%2$s_%1$s_id'); Assert::same('id', $conventions->getPrimary('book')); - Assert::same(array('author', 'author_book_id'), $conventions->getHasManyReference('book', 'author')); - Assert::same(array('book', 'author_book_id'), $conventions->getBelongsToReference('author', 'book')); + Assert::same(['author', 'author_book_id'], $conventions->getHasManyReference('book', 'author')); + Assert::same(['book', 'author_book_id'], $conventions->getBelongsToReference('author', 'book')); }); test(function() { $conventions = new StaticConventions('id', '%s_id', 'prefix_%s'); - Assert::same(array('prefix_author', 'book_id'), $conventions->getHasManyReference('prefix_book', 'author')); - Assert::same(array('prefix_book', 'book_id'), $conventions->getBelongsToReference('prefix_author', 'book')); + Assert::same(['prefix_author', 'book_id'], $conventions->getHasManyReference('prefix_book', 'author')); + Assert::same(['prefix_book', 'book_id'], $conventions->getBelongsToReference('prefix_author', 'book')); }); test(function() { $conventions = new StaticConventions('id', '%s_id', '%s_suffix'); - Assert::same(array('author_suffix', 'book_id'), $conventions->getHasManyReference('book_suffix', 'author')); - Assert::same(array('book_suffix', 'book_id'), $conventions->getBelongsToReference('author_suffix', 'book')); + Assert::same(['author_suffix', 'book_id'], $conventions->getHasManyReference('book_suffix', 'author')); + Assert::same(['book_suffix', 'book_id'], $conventions->getBelongsToReference('author_suffix', 'book')); }); diff --git a/tests/Database/Helpers.dumpSql.phpt b/tests/Database/Helpers.dumpSql.phpt index ae3c1d300..0b503b812 100644 --- a/tests/Database/Helpers.dumpSql.phpt +++ b/tests/Database/Helpers.dumpSql.phpt @@ -14,31 +14,31 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName test(function() use ($connection) { // int check Assert::same( -"
SELECT id \nFROM author \nWHERE id = 10 OR id = 11
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE id = ? OR id = ?', array(10, 11), $connection)); +"
SELECT id \nFROM author \nWHERE id = 10 OR id = 11
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE id = ? OR id = ?', [10, 11], $connection)); }); test(function() use ($connection) { // string check Assert::same( -"
SELECT id \nFROM author \nWHERE name = 'Alexej Chruščev'
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', array('Alexej Chruščev'), $connection)); +"
SELECT id \nFROM author \nWHERE name = 'Alexej Chruščev'
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ['Alexej Chruščev'], $connection)); }); test(function() use ($connection) { // string check with \' Assert::same( -"
SELECT id \nFROM author \nWHERE name = 'Alexej Ch\'ruščev'
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', array("Alexej Ch'ruščev"), $connection)); +"
SELECT id \nFROM author \nWHERE name = 'Alexej Ch\'ruščev'
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"], $connection)); }); test(function() { // string check without connection Assert::same( -"
SELECT id \nFROM author \nWHERE name = 'Alexej Ch'ruščev'
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', array("Alexej Ch'ruščev"))); +"
SELECT id \nFROM author \nWHERE name = 'Alexej Ch'ruščev'
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"])); }); test(function() use ($connection) { // string compare with $connection vs without - Assert::notSame(Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', array("Alexej Ch'ruščev"), $connection), Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', array("Alexej Ch'ruščev"))); + Assert::notSame(Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"], $connection), Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"])); }); test(function() use ($connection) { // string check with \' Nette\Database\Helpers::$maxLength = 10; Assert::same( -"
SELECT id \nFROM author \nWHERE name = 'Alexej Ch…'
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', array("Alexej Ch'ruščev"), $connection)); +"
SELECT id \nFROM author \nWHERE name = 'Alexej Ch…'
\n", Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"], $connection)); }); diff --git a/tests/Database/Helpers.loadFromFile.phpt b/tests/Database/Helpers.loadFromFile.phpt index 6f9780134..07f83f1c2 100644 --- a/tests/Database/Helpers.loadFromFile.phpt +++ b/tests/Database/Helpers.loadFromFile.phpt @@ -13,7 +13,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/mysql-delimiter.sql"); $arr = $connection->query('SELECT name, id FROM author ORDER BY id')->fetchAll(); -Assert::equal(array( - Nette\Database\Row::from(array('name' => 'Jakub Vrana', 'id' => 11)), - Nette\Database\Row::from(array('name' => 'David Grudl', 'id' => 12)), -), $arr); +Assert::equal([ + Nette\Database\Row::from(['name' => 'Jakub Vrana', 'id' => 11]), + Nette\Database\Row::from(['name' => 'David Grudl', 'id' => 12]), +], $arr); diff --git a/tests/Database/Reflection.phpt b/tests/Database/Reflection.phpt index 48a04148b..f319e6d9a 100644 --- a/tests/Database/Reflection.phpt +++ b/tests/Database/Reflection.phpt @@ -15,24 +15,24 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName $driver = $connection->getSupplementalDriver(); $tables = $driver->getTables(); -$tables = array_filter($tables, function($t) { return in_array($t['name'], array('author', 'book', 'book_tag', 'tag')); }); +$tables = array_filter($tables, function($t) { return in_array($t['name'], ['author', 'book', 'book_tag', 'tag']); }); usort($tables, function($a, $b) { return strcmp($a['name'], $b['name']); }); if ($driver->isSupported(ISupplementalDriver::SUPPORT_SCHEMA)) { - Assert::same(array( - array('name' => 'author', 'view' => FALSE, 'fullName' => 'public.author'), - array('name' => 'book', 'view' => FALSE, 'fullName' => 'public.book'), - array('name' => 'book_tag', 'view' => FALSE, 'fullName' => 'public.book_tag'), - array('name' => 'tag', 'view' => FALSE, 'fullName' => 'public.tag'), - ), + Assert::same([ + ['name' => 'author', 'view' => FALSE, 'fullName' => 'public.author'], + ['name' => 'book', 'view' => FALSE, 'fullName' => 'public.book'], + ['name' => 'book_tag', 'view' => FALSE, 'fullName' => 'public.book_tag'], + ['name' => 'tag', 'view' => FALSE, 'fullName' => 'public.tag'], + ], $tables); } else { - Assert::same( array( - array('name' => 'author', 'view' => FALSE), - array('name' => 'book', 'view' => FALSE), - array('name' => 'book_tag', 'view' => FALSE), - array('name' => 'tag', 'view' => FALSE), - ), $tables ); + Assert::same( [ + ['name' => 'author', 'view' => FALSE], + ['name' => 'book', 'view' => FALSE], + ['name' => 'book_tag', 'view' => FALSE], + ['name' => 'tag', 'view' => FALSE], + ], $tables ); } @@ -42,8 +42,8 @@ array_walk($columns, function(& $item) { unset($item['vendor']); }); -$expectedColumns = array( - array( +$expectedColumns = [ + [ 'name' => 'id', 'table' => 'author', 'nativetype' => 'INT', @@ -53,8 +53,8 @@ $expectedColumns = array( 'default' => NULL, 'autoincrement' => TRUE, 'primary' => TRUE, - ), - array( + ], + [ 'name' => 'name', 'table' => 'author', 'nativetype' => 'VARCHAR', @@ -64,8 +64,8 @@ $expectedColumns = array( 'default' => NULL, 'autoincrement' => FALSE, 'primary' => FALSE, - ), - array( + ], + [ 'name' => 'web', 'table' => 'author', 'nativetype' => 'VARCHAR', @@ -75,8 +75,8 @@ $expectedColumns = array( 'default' => NULL, 'autoincrement' => FALSE, 'primary' => FALSE, - ), - array( + ], + [ 'name' => 'born', 'table' => 'author', 'nativetype' => 'DATE', @@ -86,8 +86,8 @@ $expectedColumns = array( 'default' => NULL, 'autoincrement' => FALSE, 'primary' => FALSE, - ), -); + ], +]; switch ($driverName) { case 'mysql': @@ -120,64 +120,64 @@ Assert::same($expectedColumns, $columns); $indexes = $driver->getIndexes('book_tag'); switch ($driverName) { case 'pgsql': - Assert::same( array( - array( + Assert::same( [ + [ 'name' => 'book_tag_pkey', 'unique' => TRUE, 'primary' => TRUE, - 'columns' => array( + 'columns' => [ 'book_id', 'tag_id', - ), - ), - ), $indexes); + ], + ], + ], $indexes); break; case 'sqlite': - Assert::same( array( - array( + Assert::same( [ + [ 'name' => 'sqlite_autoindex_book_tag_1', 'unique' => TRUE, 'primary' => TRUE, - 'columns' => array( + 'columns' => [ 'book_id', 'tag_id', - ), - ), - ), $indexes); + ], + ], + ], $indexes); break; case 'sqlsrv': - Assert::same( array( - array( + Assert::same( [ + [ 'name' => 'PK_book_tag', 'unique' => TRUE, 'primary' => TRUE, - 'columns' => array( + 'columns' => [ 'book_id', 'tag_id', - ), - ), - ), $indexes); + ], + ], + ], $indexes); break; case 'mysql': - Assert::same( array( - array( + Assert::same( [ + [ 'name' => 'PRIMARY', 'unique' => TRUE, 'primary' => TRUE, - 'columns' => array( + 'columns' => [ 'book_id', 'tag_id', - ), - ), - array( + ], + ], + [ 'name' => 'book_tag_tag', 'unique' => FALSE, 'primary' => FALSE, - 'columns' => array( + 'columns' => [ 'tag_id', - ), - ), - ), $indexes); + ], + ], + ], $indexes); break; default: Assert::fail("Unsupported driver $driverName"); @@ -186,4 +186,4 @@ switch ($driverName) { $structure->rebuild(); $primary = $structure->getPrimaryKey('book_tag'); -Assert::same(array('book_id', 'tag_id'), $primary); +Assert::same(['book_id', 'tag_id'], $primary); diff --git a/tests/Database/Reflection.postgre.phpt b/tests/Database/Reflection.postgre.phpt index ed4dd5bee..3d5dc1f66 100644 --- a/tests/Database/Reflection.postgre.phpt +++ b/tests/Database/Reflection.postgre.phpt @@ -38,33 +38,33 @@ function filter($columns) { // Reflection for tables with the same name but different schema $connection->query('SET search_path TO one, two'); -Assert::same(array('master', 'slave'), filter($driver->getTables())); -Assert::same(array('one_id'), filter($driver->getColumns('master'))); -Assert::same(array('one_master_pkey'), filter($driver->getIndexes('master'))); -Assert::same(array('one_slave_fk'), filter($driver->getForeignKeys('slave'))); +Assert::same(['master', 'slave'], filter($driver->getTables())); +Assert::same(['one_id'], filter($driver->getColumns('master'))); +Assert::same(['one_master_pkey'], filter($driver->getIndexes('master'))); +Assert::same(['one_slave_fk'], filter($driver->getForeignKeys('slave'))); $connection->query('SET search_path TO two, one'); -Assert::same(array('master', 'slave'), filter($driver->getTables())); -Assert::same(array('two_id'), filter($driver->getColumns('master'))); -Assert::same(array('two_master_pkey'), filter($driver->getIndexes('master'))); -Assert::same(array('two_slave_fk'), filter($driver->getForeignKeys('slave'))); +Assert::same(['master', 'slave'], filter($driver->getTables())); +Assert::same(['two_id'], filter($driver->getColumns('master'))); +Assert::same(['two_master_pkey'], filter($driver->getIndexes('master'))); +Assert::same(['two_slave_fk'], filter($driver->getForeignKeys('slave'))); // Reflection for FQN -Assert::same(array('one_id'), filter($driver->getColumns('one.master'))); -Assert::same(array('one_master_pkey'), filter($driver->getIndexes('one.master'))); +Assert::same(['one_id'], filter($driver->getColumns('one.master'))); +Assert::same(['one_master_pkey'], filter($driver->getIndexes('one.master'))); $foreign = $driver->getForeignKeys('one.slave'); -Assert::same(array( +Assert::same([ 'name' => 'one_slave_fk', 'local' => 'one_id', 'table' => 'one.master', 'foreign' => 'one_id', -), (array) $foreign[0]); +], (array) $foreign[0]); // Limit foreign keys for current schemas only $connection->query('ALTER TABLE "one"."slave" ADD CONSTRAINT "one_two_fk" FOREIGN KEY ("one_id") REFERENCES "two"."master"("two_id")'); $connection->query('SET search_path TO one'); -Assert::same(array('one_slave_fk'), filter($driver->getForeignKeys('slave'))); +Assert::same(['one_slave_fk'], filter($driver->getForeignKeys('slave'))); $connection->query('SET search_path TO one, two'); -Assert::same(array('one_slave_fk', 'one_two_fk'), filter($driver->getForeignKeys('slave'))); +Assert::same(['one_slave_fk', 'one_two_fk'], filter($driver->getForeignKeys('slave'))); diff --git a/tests/Database/ResultSet.fetchAll().phpt b/tests/Database/ResultSet.fetchAll().phpt index e82ec0c1a..beca4e830 100644 --- a/tests/Database/ResultSet.fetchAll().phpt +++ b/tests/Database/ResultSet.fetchAll().phpt @@ -28,16 +28,16 @@ switch ($driverName) { Assert::same(1, $res->getColumnCount()); Assert::same('SELECT id FROM book ORDER BY id', $res->getQueryString()); -Assert::equal(array( - Nette\Database\Row::from(array('id' => 1)), - Nette\Database\Row::from(array('id' => 2)), - Nette\Database\Row::from(array('id' => 3)), - Nette\Database\Row::from(array('id' => 4)), -), $res->fetchAll()); - -Assert::equal(array( - Nette\Database\Row::from(array('id' => 1)), - Nette\Database\Row::from(array('id' => 2)), - Nette\Database\Row::from(array('id' => 3)), - Nette\Database\Row::from(array('id' => 4)), -), $res->fetchAll()); +Assert::equal([ + Nette\Database\Row::from(['id' => 1]), + Nette\Database\Row::from(['id' => 2]), + Nette\Database\Row::from(['id' => 3]), + Nette\Database\Row::from(['id' => 4]), +], $res->fetchAll()); + +Assert::equal([ + Nette\Database\Row::from(['id' => 1]), + Nette\Database\Row::from(['id' => 2]), + Nette\Database\Row::from(['id' => 3]), + Nette\Database\Row::from(['id' => 4]), +], $res->fetchAll()); diff --git a/tests/Database/ResultSet.fetchAssoc().phpt b/tests/Database/ResultSet.fetchAssoc().phpt index 66768f58c..242b7b110 100644 --- a/tests/Database/ResultSet.fetchAssoc().phpt +++ b/tests/Database/ResultSet.fetchAssoc().phpt @@ -14,33 +14,33 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName test(function() use ($context) { $res = $context->query('SELECT * FROM book ORDER BY title'); - Assert::same(array( + Assert::same([ 1 => '1001 tipu a triku pro PHP', 4 => 'Dibi', 2 => 'JUSH', 3 => 'Nette', - ), $res->fetchAssoc('id=title')); + ], $res->fetchAssoc('id=title')); }); test(function() use ($context) { $pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchAssoc('id'); - Assert::equal(array( - 1 => array('id' => 1), - 2 => array('id' => 2), - 3 => array('id' => 3), - 4 => array('id' => 4), - ), $pairs); + Assert::equal([ + 1 => ['id' => 1], + 2 => ['id' => 2], + 3 => ['id' => 3], + 4 => ['id' => 4], + ], $pairs); }); test(function() use ($context) { $pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchAssoc('id[]=id'); - Assert::equal(array( - 1 => array(1), - 2 => array(2), - 3 => array(3), - 4 => array(4), - ), $pairs); + Assert::equal([ + 1 => [1], + 2 => [2], + 3 => [3], + 4 => [4], + ], $pairs); }); @@ -48,8 +48,8 @@ test(function() use ($context) { $pairs = $context->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20')); $pairs = $context->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02')); $pairs = $context->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchAssoc('born=name'); - Assert::same(array( + Assert::same([ '2002-02-02 00:00:00' => 'David Grudl', '2002-02-20 00:00:00' => 'Jakub Vrana', - ), $pairs); + ], $pairs); }); diff --git a/tests/Database/ResultSet.fetchPairs().phpt b/tests/Database/ResultSet.fetchPairs().phpt index d105a8dd5..156ec2f1d 100644 --- a/tests/Database/ResultSet.fetchPairs().phpt +++ b/tests/Database/ResultSet.fetchPairs().phpt @@ -14,52 +14,52 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName test(function() use ($context) { $res = $context->query('SELECT * FROM book ORDER BY title'); - Assert::same(array( + Assert::same([ 1 => '1001 tipu a triku pro PHP', 4 => 'Dibi', 2 => 'JUSH', 3 => 'Nette', - ), $res->fetchPairs('id', 'title')); + ], $res->fetchPairs('id', 'title')); - Assert::same(array( + Assert::same([ '1001 tipu a triku pro PHP' => 1, 'Dibi' => 4, 'JUSH' => 2, 'Nette' => 3, - ), $res->fetchPairs('title', 'id')); + ], $res->fetchPairs('title', 'id')); }); test(function() use ($context) { $pairs = $context->query('SELECT title, id FROM book ORDER BY title')->fetchPairs(1, 0); - Assert::same(array( + Assert::same([ 1 => '1001 tipu a triku pro PHP', 4 => 'Dibi', 2 => 'JUSH', 3 => 'Nette', - ), $pairs); + ], $pairs); }); test(function() use ($context) { $pairs = $context->query('SELECT * FROM book ORDER BY id')->fetchPairs('id', 'id'); - Assert::same(array( + Assert::same([ 1 => 1, 2 => 2, 3 => 3, 4 => 4, - ), $pairs); + ], $pairs); }); test(function() use ($context) { $pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchPairs('id'); - Assert::equal(array( - 1 => Nette\Database\Row::from(array('id' => 1)), - 2 => Nette\Database\Row::from(array('id' => 2)), - 3 => Nette\Database\Row::from(array('id' => 3)), - 4 => Nette\Database\Row::from(array('id' => 4)), - ), $pairs); + Assert::equal([ + 1 => Nette\Database\Row::from(['id' => 1]), + 2 => Nette\Database\Row::from(['id' => 2]), + 3 => Nette\Database\Row::from(['id' => 3]), + 4 => Nette\Database\Row::from(['id' => 4]), + ], $pairs); }); @@ -67,62 +67,62 @@ test(function() use ($context) { $pairs = $context->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20')); $pairs = $context->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02')); $pairs = $context->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name'); - Assert::same(array( + Assert::same([ '2002-02-02 00:00:00' => 'David Grudl', '2002-02-20 00:00:00' => 'Jakub Vrana', - ), $pairs); + ], $pairs); }); $pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchPairs('id'); -Assert::equal(array( - 1 => Nette\Database\Row::from(array('id' => 1)), - 2 => Nette\Database\Row::from(array('id' => 2)), - 3 => Nette\Database\Row::from(array('id' => 3)), - 4 => Nette\Database\Row::from(array('id' => 4)), -), $pairs); +Assert::equal([ + 1 => Nette\Database\Row::from(['id' => 1]), + 2 => Nette\Database\Row::from(['id' => 2]), + 3 => Nette\Database\Row::from(['id' => 3]), + 4 => Nette\Database\Row::from(['id' => 4]), +], $pairs); $pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchPairs(NULL, 'id'); -Assert::equal(array( +Assert::equal([ 0 => 1, 1 => 2, 2 => 3, 3 => 4, -), $pairs); +], $pairs); $pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchPairs(); -Assert::equal(array( +Assert::equal([ 0 => 1, 1 => 2, 2 => 3, 3 => 4, -), $pairs); +], $pairs); $pairs = $context->query('SELECT id, id + 1 AS id1 FROM book ORDER BY id')->fetchPairs(); -Assert::equal(array( +Assert::equal([ 1 => 2, 2 => 3, 3 => 4, 4 => 5, -), $pairs); +], $pairs); $pairs = $context->query('SELECT id, id + 1 AS id1, title FROM book ORDER BY id')->fetchPairs(); -Assert::equal(array( +Assert::equal([ 1 => 2, 2 => 3, 3 => 4, 4 => 5, -), $pairs); +], $pairs); $pairs = $context->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20')); $pairs = $context->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02')); $pairs = $context->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name'); -Assert::same(array( +Assert::same([ '2002-02-02 00:00:00' => 'David Grudl', '2002-02-20 00:00:00' => 'Jakub Vrana', -), $pairs); +], $pairs); diff --git a/tests/Database/ResultSet.normalizeRow.mysql.phpt b/tests/Database/ResultSet.normalizeRow.mysql.phpt index 47343761a..1965b9ad1 100644 --- a/tests/Database/ResultSet.normalizeRow.mysql.phpt +++ b/tests/Database/ResultSet.normalizeRow.mysql.phpt @@ -15,7 +15,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_ $res = $context->query('SELECT * FROM types'); -Assert::equal( array( +Assert::equal( [ 'unsigned_int' => 1, 'int' => 1, 'smallint' => 1, @@ -46,9 +46,9 @@ Assert::equal( array( 'longtext' => 'a', 'enum' => 'a', 'set' => 'a', -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::equal( array( +Assert::equal( [ 'unsigned_int' => 0, 'int' => 0, 'smallint' => 0, @@ -79,9 +79,9 @@ Assert::equal( array( 'longtext' => '', 'enum' => 'b', 'set' => '', -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::same( array( +Assert::same( [ 'unsigned_int' => NULL, 'int' => NULL, 'smallint' => NULL, @@ -112,11 +112,11 @@ Assert::same( array( 'longtext' => NULL, 'enum' => NULL, 'set' => NULL, -), (array) $res->fetch() ); +], (array) $res->fetch() ); $res = $context->query('SELECT `int` AS a, `char` AS a FROM types'); -Assert::same( array( +Assert::same( [ 'a' => 'a', -), (array) @$res->fetch() ); +], (array) @$res->fetch() ); diff --git a/tests/Database/ResultSet.normalizeRow.postgre.phpt b/tests/Database/ResultSet.normalizeRow.postgre.phpt index 7ad1f5b59..e95c7381c 100644 --- a/tests/Database/ResultSet.normalizeRow.postgre.phpt +++ b/tests/Database/ResultSet.normalizeRow.postgre.phpt @@ -19,7 +19,7 @@ $row = $res->fetch(); Assert::type( 'string', $row->money ); unset($row->money); -Assert::equal( array( +Assert::equal( [ 'smallint' => 1, 'integer' => 1, 'bigint' => 1, @@ -50,9 +50,9 @@ Assert::equal( array( 'path' => '((10,20),(30,40))', 'point' => '(10,20)', 'polygon' => '((10,20),(30,40))', -), (array) $row ); +], (array) $row ); -Assert::same( array( +Assert::same( [ 'smallint' => 0, 'integer' => 0, 'bigint' => 0, @@ -84,9 +84,9 @@ Assert::same( array( 'path' => '((10,20),(30,40))', 'point' => '(10,20)', 'polygon' => '((10,20),(30,40))', -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::same( array( +Assert::same( [ 'smallint' => NULL, 'integer' => NULL, 'bigint' => NULL, @@ -118,11 +118,11 @@ Assert::same( array( 'path' => NULL, 'point' => NULL, 'polygon' => NULL, -), (array) $res->fetch() ); +], (array) $res->fetch() ); $res = $context->query('SELECT "integer" AS a, "text" AS a FROM types'); -Assert::same( array( +Assert::same( [ 'a' => 'a', -), (array) @$res->fetch() ); +], (array) @$res->fetch() ); diff --git a/tests/Database/ResultSet.normalizeRow.sqlite.phpt b/tests/Database/ResultSet.normalizeRow.sqlite.phpt index 721d701e0..477a0c0fc 100644 --- a/tests/Database/ResultSet.normalizeRow.sqlite.phpt +++ b/tests/Database/ResultSet.normalizeRow.sqlite.phpt @@ -15,7 +15,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlite-nette $res = $context->query('SELECT * FROM types'); -Assert::equal( array( +Assert::equal( [ 'int' => 1, 'integer' => 1, 'tinyint' => 1, @@ -43,9 +43,9 @@ Assert::equal( array( 'boolean' => TRUE, 'date' => new DateTime('2012-10-13'), 'datetime' => new DateTime('2012-10-13 10:10:10'), -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::equal( array( +Assert::equal( [ 'int' => 0, 'integer' => 0, 'tinyint' => 0, @@ -73,9 +73,9 @@ Assert::equal( array( 'boolean' => FALSE, 'date' => new DateTime('1970-01-01'), 'datetime' => new DateTime('1970-01-01 00:00:00'), -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::same( array( +Assert::same( [ 'int' => NULL, 'integer' => NULL, 'tinyint' => NULL, @@ -103,11 +103,11 @@ Assert::same( array( 'boolean' => NULL, 'date' => NULL, 'datetime' => NULL, -), (array) $res->fetch() ); +], (array) $res->fetch() ); $res = $context->query('SELECT [int] AS a, [text] AS a FROM types'); -Assert::same( array( +Assert::same( [ 'a' => 'a', -), (array) @$res->fetch() ); +], (array) @$res->fetch() ); diff --git a/tests/Database/ResultSet.normalizeRow.sqlite2.phpt b/tests/Database/ResultSet.normalizeRow.sqlite2.phpt index 2beb00d36..20aa2fc00 100644 --- a/tests/Database/ResultSet.normalizeRow.sqlite2.phpt +++ b/tests/Database/ResultSet.normalizeRow.sqlite2.phpt @@ -21,7 +21,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlite-nette $res = $connection->query('SELECT * FROM types'); -Assert::equal( array( +Assert::equal( [ 'int' => '1', 'integer' => '1', 'tinyint' => '1', @@ -49,9 +49,9 @@ Assert::equal( array( 'boolean' => '1', 'date' => '2012-10-13', 'datetime' => '2012-10-13 10:10:10', -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::equal( array( +Assert::equal( [ 'int' => '0', 'integer' => '0', 'tinyint' => '0', @@ -79,9 +79,9 @@ Assert::equal( array( 'boolean' => '0', 'date' => '1970-01-01', 'datetime' => '1970-01-01 00:00:00', -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::same( array( +Assert::same( [ 'int' => NULL, 'integer' => NULL, 'tinyint' => NULL, @@ -109,4 +109,4 @@ Assert::same( array( 'boolean' => NULL, 'date' => NULL, 'datetime' => NULL, -), (array) $res->fetch() ); +], (array) $res->fetch() ); diff --git a/tests/Database/ResultSet.normalizeRow.sqlsrv.phpt b/tests/Database/ResultSet.normalizeRow.sqlsrv.phpt index d7af882fe..a9f29b69b 100644 --- a/tests/Database/ResultSet.normalizeRow.sqlsrv.phpt +++ b/tests/Database/ResultSet.normalizeRow.sqlsrv.phpt @@ -15,7 +15,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/sqlsrv-nette $res = $context->query('SELECT * FROM types'); -Assert::equal( array( +Assert::equal( [ 'bigint' => 1, 'binary_3' => '0000FF', 'bit' => '1', @@ -46,9 +46,9 @@ Assert::equal( array( 'varbinary' => '01', 'varchar' => 'a', 'xml' => '', -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::equal( array( +Assert::equal( [ 'bigint' => 0, 'binary_3' => '000000', 'bit' => '0', @@ -79,9 +79,9 @@ Assert::equal( array( 'varbinary' => '00', 'varchar' => '', 'xml' => '', -), (array) $res->fetch() ); +], (array) $res->fetch() ); -Assert::same( array( +Assert::same( [ 'bigint' => NULL, 'binary_3' => NULL, 'bit' => NULL, @@ -112,14 +112,14 @@ Assert::same( array( 'varbinary' => NULL, 'varchar' => NULL, 'xml' => NULL, -), (array) $res->fetch() ); +], (array) $res->fetch() ); $res = $context->query('SELECT [int] AS a, [text] AS a FROM types'); -Assert::same( array( +Assert::same( [ 'a' => 'a', -), (array) @$res->fetch() ); +], (array) @$res->fetch() ); function isTimestamp($str) { diff --git a/tests/Database/ResultSet.parameters.mysql.phpt b/tests/Database/ResultSet.parameters.mysql.phpt index 46c296a51..10e645c52 100644 --- a/tests/Database/ResultSet.parameters.mysql.phpt +++ b/tests/Database/ResultSet.parameters.mysql.phpt @@ -13,6 +13,6 @@ require __DIR__ . '/connect.inc.php'; // create $connection $res = $connection->fetch('SELECT ? AS c1, ? AS c2, ? AS c3, ? as c4', fopen(__FILE__, 'r'), TRUE, NULL, 123); Assert::same( - array('c1' => file_get_contents(__FILE__), 'c2' => 1, 'c3' => NULL, 'c4' => 123), + ['c1' => file_get_contents(__FILE__), 'c2' => 1, 'c3' => NULL, 'c4' => 123], (array) $res ); diff --git a/tests/Database/ResultSet.parameters.postgre.phpt b/tests/Database/ResultSet.parameters.postgre.phpt index afaef19f5..70185ad81 100644 --- a/tests/Database/ResultSet.parameters.postgre.phpt +++ b/tests/Database/ResultSet.parameters.postgre.phpt @@ -13,6 +13,6 @@ require __DIR__ . '/connect.inc.php'; // create $connection $res = $connection->fetch('SELECT ? AS c1, ? AS c2, ? AS c3', TRUE, NULL, 123); Assert::same( - array('c1' => TRUE, 'c2' => NULL, 'c3' => 123), + ['c1' => TRUE, 'c2' => NULL, 'c3' => 123], (array) $res ); diff --git a/tests/Database/SqlPreprocessor.phpt b/tests/Database/SqlPreprocessor.phpt index abff2b2c8..252e84637 100644 --- a/tests/Database/SqlPreprocessor.phpt +++ b/tests/Database/SqlPreprocessor.phpt @@ -14,414 +14,414 @@ require __DIR__ . '/connect.inc.php'; // create $connection $preprocessor = new Nette\Database\SqlPreprocessor($connection); test(function() use ($preprocessor) { // basic - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id = ?', 11)); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id = ?', 11]); Assert::same( 'SELECT id FROM author WHERE id = 11', $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // arg without placeholder - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id =', 11)); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id =', 11]); Assert::same( 'SELECT id FROM author WHERE id = 11', $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id =', '11')); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id =', '11']); Assert::same( "SELECT id FROM author WHERE id = '11'", $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id = ? OR id = ?', 11, 12)); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id = ? OR id = ?', 11, 12]); Assert::same( 'SELECT id FROM author WHERE id = 11 OR id = 12', $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id = ?', 11, 'OR id = ?', 12)); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id = ?', 11, 'OR id = ?', 12]); Assert::same( 'SELECT id FROM author WHERE id = 11 OR id = 12', $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // IN - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id IN (?)', array(10, 11))); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id IN (?)', [10, 11]]); Assert::same( 'SELECT id FROM author WHERE id IN (10, 11)', $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE (id, name) IN (?)', array(array(10, 'a'), array(11, 'b')))); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE (id, name) IN (?)', [[10, 'a'], [11, 'b']]]); Assert::same( "SELECT id FROM author WHERE (id, name) IN ((10, 'a'), (11, 'b'))", $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE', array( - 'a' => array(NULL, 1, 2, 3), - 'b' => array(), - 'c NOT IN' => array(NULL, 1, 2, 3), - 'd NOT IN' => array(), - ))); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE', [ + 'a' => [NULL, 1, 2, 3], + 'b' => [], + 'c NOT IN' => [NULL, 1, 2, 3], + 'd NOT IN' => [], + ]]); Assert::same( reformat('SELECT id FROM author WHERE ([a] IN (NULL, 1, 2, 3)) AND (1=0) AND ([c] NOT IN (NULL, 1, 2, 3))'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // ?name - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE ?name = ? OR ?name = ?', 'id', 12, 'table.number', 23)); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE ?name = ? OR ?name = ?', 'id', 12, 'table.number', 23]); Assert::same( reformat('SELECT id FROM author WHERE [id] = 12 OR [table].[number] = 23'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // comments - list($sql, $params) = $preprocessor->process(array("SELECT id --?\nFROM author WHERE id = ?", 11)); + list($sql, $params) = $preprocessor->process(["SELECT id --?\nFROM author WHERE id = ?", 11]); Assert::same( "SELECT id --?\nFROM author WHERE id = 11", $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); - list($sql, $params) = $preprocessor->process(array("SELECT id /* ? \n */FROM author WHERE id = ? --*/", 11)); + list($sql, $params) = $preprocessor->process(["SELECT id /* ? \n */FROM author WHERE id = ? --*/", 11]); Assert::same( "SELECT id /* ? \n */FROM author WHERE id = 11 --*/", $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // strings - list($sql, $params) = $preprocessor->process(array("SELECT id, '?' FROM author WHERE id = ?", 11)); + list($sql, $params) = $preprocessor->process(["SELECT id, '?' FROM author WHERE id = ?", 11]); Assert::same( "SELECT id, '?' FROM author WHERE id = 11", $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); - list($sql, $params) = $preprocessor->process(array('SELECT id, "?" FROM author WHERE id = ?', 11)); + list($sql, $params) = $preprocessor->process(['SELECT id, "?" FROM author WHERE id = ?', 11]); Assert::same( 'SELECT id, "?" FROM author WHERE id = 11', $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // where - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE', array( + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE', [ 'id' => NULL, 'x.name <>' => 'a', - 'born' => array(NULL, 1, 2, 3), - 'web' => array(), - ))); + 'born' => [NULL, 1, 2, 3], + 'web' => [], + ]]); Assert::same( reformat("SELECT id FROM author WHERE ([id] IS NULL) AND ([x].[name] <> 'a') AND ([born] IN (NULL, 1, 2, 3)) AND (1=0)"), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // tuples - list($sql, $params) = $preprocessor->process(array('SELECT * FROM book_tag WHERE (book_id, tag_id) IN (?)', array( - array(1, 2), - array(3, 4), - array(5, 6), - ))); + list($sql, $params) = $preprocessor->process(['SELECT * FROM book_tag WHERE (book_id, tag_id) IN (?)', [ + [1, 2], + [3, 4], + [5, 6], + ]]); Assert::same( reformat("SELECT * FROM book_tag WHERE (book_id, tag_id) IN ((1, 2), (3, 4), (5, 6))"), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // order - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author ORDER BY', array( + list($sql, $params) = $preprocessor->process(['SELECT id FROM author ORDER BY', [ 'id' => TRUE, 'name' => FALSE, - ))); + ]]); Assert::same( reformat('SELECT id FROM author ORDER BY [id], [name] DESC'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // ?order - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author ORDER BY ?order', array( + list($sql, $params) = $preprocessor->process(['SELECT id FROM author ORDER BY ?order', [ 'id' => TRUE, 'name' => FALSE, - ))); + ]]); Assert::same( reformat('SELECT id FROM author ORDER BY [id], [name] DESC'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // missing parameters Assert::exception(function() use ($preprocessor) { - $preprocessor->process(array('SELECT id FROM author WHERE id =? OR id = ?', 11)); + $preprocessor->process(['SELECT id FROM author WHERE id =? OR id = ?', 11]); }, 'Nette\InvalidArgumentException', 'There are more placeholders than passed parameters.'); Assert::exception(function() use ($preprocessor) { - $preprocessor->process(array('SELECT id FROM author WHERE id =', new SqlLiteral('? OR ?name = ?', array(11)), 'id', 12)); + $preprocessor->process(['SELECT id FROM author WHERE id =', new SqlLiteral('? OR ?name = ?', [11]), 'id', 12]); }, 'Nette\InvalidArgumentException', 'There are more placeholders than passed parameters.'); }); test(function() use ($preprocessor) { // extra parameters Assert::exception(function() use ($preprocessor) { - $preprocessor->process(array('SELECT id FROM author WHERE id =', 11, 12)); + $preprocessor->process(['SELECT id FROM author WHERE id =', 11, 12]); }, 'Nette\InvalidArgumentException', 'There are more parameters than placeholders.'); Assert::exception(function() use ($preprocessor) { - $preprocessor->process(array('SELECT id FROM author WHERE id =?', 11, 12)); + $preprocessor->process(['SELECT id FROM author WHERE id =?', 11, 12]); }, 'Nette\InvalidArgumentException', 'There are more parameters than placeholders.'); Assert::exception(function() use ($preprocessor) { - $preprocessor->process(array('SELECT id FROM author WHERE id =', 'a', 'b')); + $preprocessor->process(['SELECT id FROM author WHERE id =', 'a', 'b']); }, 'Nette\InvalidArgumentException', 'There are more parameters than placeholders.'); Assert::exception(function() use ($preprocessor) { - $preprocessor->process(array('SELECT id FROM author WHERE id =', '?', 11, 'OR id = ?', 12)); + $preprocessor->process(['SELECT id FROM author WHERE id =', '?', 11, 'OR id = ?', 12]); }, 'Nette\InvalidArgumentException', 'There are more parameters than placeholders.'); }); test(function() use ($preprocessor) { // unknown placeholder Assert::exception(function() use ($preprocessor) { - $preprocessor->process(array('SELECT ?test', 11)); + $preprocessor->process(['SELECT ?test', 11]); }, 'Nette\InvalidArgumentException', 'Unknown placeholder ?test.'); }); test(function() use ($preprocessor) { // SqlLiteral - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id =', new SqlLiteral('? OR ?name = ?', array(11, 'id', 12)) )); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id =', new SqlLiteral('? OR ?name = ?', [11, 'id', 12]) ]); Assert::same( reformat('SELECT id FROM author WHERE id = 11 OR [id] = 12'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE', new SqlLiteral('id=11'), 'OR', new SqlLiteral('id=?', array(12)))); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE', new SqlLiteral('id=11'), 'OR', new SqlLiteral('id=?', [12])]); Assert::same( 'SELECT id FROM author WHERE id=11 OR id=12', $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // and - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE', array( + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE', [ 'id' => new SqlLiteral('NULL'), - 'born' => array(1, 2, new SqlLiteral('3+1')), + 'born' => [1, 2, new SqlLiteral('3+1')], 'web' => new SqlLiteral('NOW()'), - ))); + ]]); Assert::same( reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([born] IN (1, 2, 3+1)) AND ([web] = NOW())'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // empty and - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE', array())); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE', []]); Assert::same( reformat('SELECT id FROM author WHERE 1=1'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // ?and - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE ?and', array( + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE ?and', [ 'id' => NULL, - 'born' => array(1, 2), - ))); + 'born' => [1, 2], + ]]); Assert::same( reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([born] IN (1, 2))'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // ?or - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE ?or', array( + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE ?or', [ 'id' => NULL, - 'born' => array(1, 2), - ))); + 'born' => [1, 2], + ]]); Assert::same( reformat('SELECT id FROM author WHERE ([id] IS NULL) OR ([born] IN (1, 2))'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor, $driverName) { // date time - list($sql, $params) = $preprocessor->process(array('SELECT ?', array(new DateTime('2011-11-11')))); - Assert::same( reformat(array( + list($sql, $params) = $preprocessor->process(['SELECT ?', [new DateTime('2011-11-11')]]); + Assert::same( reformat([ 'sqlite' => "SELECT 1320966000", "SELECT '2011-11-11 00:00:00'", - )), $sql ); - Assert::same( array(), $params ); + ]), $sql ); + Assert::same( [], $params ); if ($driverName === 'mysql') { $interval = new DateInterval('PT26H8M10S'); $interval->invert = TRUE; - list($sql, $params) = $preprocessor->process(array('SELECT ?', array($interval))); + list($sql, $params) = $preprocessor->process(['SELECT ?', [$interval]]); Assert::same( reformat("SELECT '-26:08:10'"), $sql ); } - Assert::same( array(), $params ); + Assert::same( [], $params ); if (PHP_VERSION_ID >= 50500) { - list($sql, $params) = $preprocessor->process(array('SELECT ?', array(new DateTimeImmutable('2011-11-11')))); - Assert::same( reformat(array( + list($sql, $params) = $preprocessor->process(['SELECT ?', [new DateTimeImmutable('2011-11-11')]]); + Assert::same( reformat([ 'sqlite' => "SELECT 1320966000", "SELECT '2011-11-11 00:00:00'", - )), $sql ); + ]), $sql ); } }); test(function() use ($preprocessor) { // insert - list($sql, $params) = $preprocessor->process(array('INSERT INTO author', - array('name' => 'Catelyn Stark', 'born' => new DateTime('2011-11-11')), - )); + list($sql, $params) = $preprocessor->process(['INSERT INTO author', + ['name' => 'Catelyn Stark', 'born' => new DateTime('2011-11-11')], + ]); - Assert::same( reformat(array( + Assert::same( reformat([ 'sqlite' => "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', 1320966000)", "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11 00:00:00')", - )), $sql ); - Assert::same( array(), $params ); + ]), $sql ); + Assert::same( [], $params ); - list($sql, $params) = $preprocessor->process(array("\r\n INSERT INTO author", - array('name' => 'Catelyn Stark'), - )); + list($sql, $params) = $preprocessor->process(["\r\n INSERT INTO author", + ['name' => 'Catelyn Stark'], + ]); Assert::same( reformat("\r\n INSERT INTO author ([name]) VALUES ('Catelyn Stark')"), $sql ); - list($sql, $params) = $preprocessor->process(array('REPLACE author ?', - array('name' => 'Catelyn Stark'), - )); + list($sql, $params) = $preprocessor->process(['REPLACE author ?', + ['name' => 'Catelyn Stark'], + ]); Assert::same( reformat("REPLACE author ([name]) VALUES ('Catelyn Stark')"), $sql ); - list($sql, $params) = $preprocessor->process(array("/* comment */ INSERT INTO author", - array('name' => 'Catelyn Stark'), - )); + list($sql, $params) = $preprocessor->process(["/* comment */ INSERT INTO author", + ['name' => 'Catelyn Stark'], + ]); Assert::same( reformat("/* comment */ INSERT INTO author [name]='Catelyn Stark'"), $sql ); // autodetection not used }); test(function() use ($preprocessor) { // ?values - list($sql, $params) = $preprocessor->process(array('INSERT INTO update ?values', - array('name' => 'Catelyn Stark'), - )); + list($sql, $params) = $preprocessor->process(['INSERT INTO update ?values', + ['name' => 'Catelyn Stark'], + ]); Assert::same( reformat("INSERT INTO update ([name]) VALUES ('Catelyn Stark')"), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // multi insert - list($sql, $params) = $preprocessor->process(array('INSERT INTO author', array( - array('name' => 'Catelyn Stark', 'born' => new DateTime('2011-11-11')), - array('name' => 'Sansa Stark', 'born' => new DateTime('2021-11-11')) - ))); + list($sql, $params) = $preprocessor->process(['INSERT INTO author', [ + ['name' => 'Catelyn Stark', 'born' => new DateTime('2011-11-11')], + ['name' => 'Sansa Stark', 'born' => new DateTime('2021-11-11')] + ]]); - Assert::same( reformat(array( + Assert::same( reformat([ 'sqlite' => "INSERT INTO author ([name], [born]) SELECT 'Catelyn Stark', 1320966000 UNION ALL SELECT 'Sansa Stark', 1636585200", "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11 00:00:00'), ('Sansa Stark', '2021-11-11 00:00:00')", - )), $sql ); - Assert::same( array(), $params ); + ]), $sql ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // multi insert ?values - list($sql, $params) = $preprocessor->process(array('INSERT INTO author ?values', array( - array('name' => 'Catelyn Stark', 'born' => new DateTime('2011-11-11')), - array('name' => 'Sansa Stark', 'born' => new DateTime('2021-11-11')) - ))); + list($sql, $params) = $preprocessor->process(['INSERT INTO author ?values', [ + ['name' => 'Catelyn Stark', 'born' => new DateTime('2011-11-11')], + ['name' => 'Sansa Stark', 'born' => new DateTime('2021-11-11')] + ]]); - Assert::same( reformat(array( + Assert::same( reformat([ 'sqlite' => "INSERT INTO author ([name], [born]) SELECT 'Catelyn Stark', 1320966000 UNION ALL SELECT 'Sansa Stark', 1636585200", "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11 00:00:00'), ('Sansa Stark', '2021-11-11 00:00:00')", - )), $sql ); - Assert::same( array(), $params ); + ]), $sql ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // update - list($sql, $params) = $preprocessor->process(array('UPDATE author SET ?', array( + list($sql, $params) = $preprocessor->process(['UPDATE author SET ?', [ 'id' => 12, - 'name' => new SqlLiteral('UPPER(?)', array('John Doe')), - new SqlLiteral('UPPER(?) = ?', array('John', 'DOE')), - ))); + 'name' => new SqlLiteral('UPPER(?)', ['John Doe']), + new SqlLiteral('UPPER(?) = ?', ['John', 'DOE']), + ]]); Assert::same( reformat("UPDATE author SET [id]=12, [name]=UPPER('John Doe'), UPPER('John') = 'DOE'"), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); - list($sql, $params) = $preprocessor->process(array("UPDATE author SET \n", - array('id' => 12, 'name' => 'John Doe'), - )); + list($sql, $params) = $preprocessor->process(["UPDATE author SET \n", + ['id' => 12, 'name' => 'John Doe'], + ]); Assert::same( reformat("UPDATE author SET \n [id]=12, [name]='John Doe'"), $sql ); - list($sql, $params) = $preprocessor->process(array('UPDATE author SET', - array('id' => 12, 'name' => 'John Doe'), - )); + list($sql, $params) = $preprocessor->process(['UPDATE author SET', + ['id' => 12, 'name' => 'John Doe'], + ]); Assert::same( reformat("UPDATE author SET [id]=12, [name]='John Doe'"), $sql ); - list($sql, $params) = $preprocessor->process(array('UPDATE author SET a=1,', - array('id' => 12, 'name' => 'John Doe'), - )); + list($sql, $params) = $preprocessor->process(['UPDATE author SET a=1,', + ['id' => 12, 'name' => 'John Doe'], + ]); Assert::same( reformat("UPDATE author SET a=1, [id]=12, [name]='John Doe'"), $sql ); }); test(function() use ($preprocessor) { // ?set - list($sql, $params) = $preprocessor->process(array('UPDATE insert SET ?set', - array('id' => 12, 'name' => 'John Doe'), - )); + list($sql, $params) = $preprocessor->process(['UPDATE insert SET ?set', + ['id' => 12, 'name' => 'John Doe'], + ]); Assert::same( reformat("UPDATE insert SET [id]=12, [name]='John Doe'"), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // update += - list($sql, $params) = $preprocessor->process(array('UPDATE author SET ?', - array('id+=' => 1, 'id-=' => -1), - )); + list($sql, $params) = $preprocessor->process(['UPDATE author SET ?', + ['id+=' => 1, 'id-=' => -1], + ]); Assert::same( reformat("UPDATE author SET [id]=[id] + 1, [id]=[id] - -1"), $sql ); }); test(function() use ($preprocessor) { // insert & update - list($sql, $params) = $preprocessor->process(array('INSERT INTO author ? ON DUPLICATE KEY UPDATE ?', - array('id' => 12, 'name' => 'John Doe'), - array('web' => 'http://nette.org', 'name' => 'Dave Lister'), - )); + list($sql, $params) = $preprocessor->process(['INSERT INTO author ? ON DUPLICATE KEY UPDATE ?', + ['id' => 12, 'name' => 'John Doe'], + ['web' => 'http://nette.org', 'name' => 'Dave Lister'], + ]); Assert::same( reformat("INSERT INTO author ([id], [name]) VALUES (12, 'John Doe') ON DUPLICATE KEY UPDATE [web]='http://nette.org', [name]='Dave Lister'"), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); test(function() use ($preprocessor) { // invalid usage of ?and, ... - foreach (array('?and', '?or', '?set', '?values', '?order') as $mode) { + foreach (['?and', '?or', '?set', '?values', '?order'] as $mode) { Assert::exception(function() use ($preprocessor, $mode) { - $preprocessor->process(array($mode, 'string')); + $preprocessor->process([$mode, 'string']); }, 'Nette\InvalidArgumentException', "Placeholder $mode expects array or Traversable object, string given."); } Assert::exception(function() use ($preprocessor) { - $preprocessor->process(array('SELECT ?name', array('id', 'table.id'))); + $preprocessor->process(['SELECT ?name', ['id', 'table.id']]); }, 'Nette\InvalidArgumentException', 'Placeholder ?name expects string, array given.'); }); test(function() use ($preprocessor) { - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE ?or', array( - new SqlLiteral('max > ?', array(10)), - new SqlLiteral('min < ?', array(20)), - ))); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE ?or', [ + new SqlLiteral('max > ?', [10]), + new SqlLiteral('min < ?', [20]), + ]]); Assert::same( reformat('SELECT id FROM author WHERE (max > 10) OR (min < 20)'), $sql ); }); test(function() use ($preprocessor) { - list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE', new SqlLiteral('?or', array(array( - new SqlLiteral('?and', array(array('a' => 1, 'b' => 2))), - new SqlLiteral('?and', array(array('c' => 3, 'd' => 4))), - ))))); + list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE', new SqlLiteral('?or', [[ + new SqlLiteral('?and', [['a' => 1, 'b' => 2]]), + new SqlLiteral('?and', [['c' => 3, 'd' => 4]]), + ]])]); Assert::same( reformat('SELECT id FROM author WHERE (([a] = 1) AND ([b] = 2)) OR (([c] = 3) AND ([d] = 4))'), $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); @@ -434,19 +434,19 @@ class ToString } test(function() use ($preprocessor) { // object - list($sql, $params) = $preprocessor->process(array('SELECT ?', new ToString)); + list($sql, $params) = $preprocessor->process(['SELECT ?', new ToString]); Assert::same( "SELECT 'hello'", $sql ); - Assert::same( array(), $params ); + Assert::same( [], $params ); }); Assert::exception(function() use ($preprocessor) { // object - $preprocessor->process(array('SELECT ?', new stdClass)); + $preprocessor->process(['SELECT ?', new stdClass]); }, 'Nette\InvalidArgumentException', 'Unexpected type of parameter: stdClass'); test(function() use ($preprocessor) { // resource - list($sql, $params) = $preprocessor->process(array('SELECT ?', $res = fopen(__FILE__, 'r'))); + list($sql, $params) = $preprocessor->process(['SELECT ?', $res = fopen(__FILE__, 'r')]); Assert::same( 'SELECT ?', $sql ); - Assert::same( array($res), $params ); + Assert::same( [$res], $params ); }); diff --git a/tests/Database/Structure.phpt b/tests/Database/Structure.phpt index 82d6c4d44..4fef53bbe 100644 --- a/tests/Database/Structure.phpt +++ b/tests/Database/Structure.phpt @@ -50,40 +50,40 @@ class StructureTestCase extends TestCase $this->connection->shouldReceive('getDsn')->once()->andReturn(''); $this->connection->shouldReceive('getSupplementalDriver')->once()->andReturn($this->driver); - $this->driver->shouldReceive('getTables')->once()->andReturn(array( - array('name' => 'authors', 'view' => FALSE), - array('name' => 'Books', 'view' => FALSE), - array('name' => 'tags', 'view' => FALSE), - array('name' => 'books_x_tags', 'view' => FALSE), - array('name' => 'books_view', 'view' => TRUE), - )); - $this->driver->shouldReceive('getColumns')->with('authors')->once()->andReturn(array( - array('name' => 'id', 'primary' => TRUE, 'vendor' => array('sequence' => '"public"."authors_id_seq"')), - array('name' => 'name', 'primary' => FALSE, 'vendor' => array()), - )); - $this->driver->shouldReceive('getColumns')->with('Books')->once()->andReturn(array( - array('name' => 'id', 'primary' => TRUE, 'vendor' => array('sequence' => '"public"."Books_id_seq"')), - array('name' => 'title', 'primary' => FALSE, 'vendor' => array()), - )); - $this->driver->shouldReceive('getColumns')->with('tags')->once()->andReturn(array( - array('name' => 'id', 'primary' => TRUE, 'vendor' => array()), - array('name' => 'name', 'primary' => FALSE, 'vendor' => array()), - )); - $this->driver->shouldReceive('getColumns')->with('books_x_tags')->once()->andReturn(array( - array('name' => 'book_id', 'primary' => TRUE, 'vendor' => array()), - array('name' => 'tag_id', 'primary' => TRUE, 'vendor' => array()), - )); + $this->driver->shouldReceive('getTables')->once()->andReturn([ + ['name' => 'authors', 'view' => FALSE], + ['name' => 'Books', 'view' => FALSE], + ['name' => 'tags', 'view' => FALSE], + ['name' => 'books_x_tags', 'view' => FALSE], + ['name' => 'books_view', 'view' => TRUE], + ]); + $this->driver->shouldReceive('getColumns')->with('authors')->once()->andReturn([ + ['name' => 'id', 'primary' => TRUE, 'vendor' => ['sequence' => '"public"."authors_id_seq"']], + ['name' => 'name', 'primary' => FALSE, 'vendor' => []], + ]); + $this->driver->shouldReceive('getColumns')->with('Books')->once()->andReturn([ + ['name' => 'id', 'primary' => TRUE, 'vendor' => ['sequence' => '"public"."Books_id_seq"']], + ['name' => 'title', 'primary' => FALSE, 'vendor' => []], + ]); + $this->driver->shouldReceive('getColumns')->with('tags')->once()->andReturn([ + ['name' => 'id', 'primary' => TRUE, 'vendor' => []], + ['name' => 'name', 'primary' => FALSE, 'vendor' => []], + ]); + $this->driver->shouldReceive('getColumns')->with('books_x_tags')->once()->andReturn([ + ['name' => 'book_id', 'primary' => TRUE, 'vendor' => []], + ['name' => 'tag_id', 'primary' => TRUE, 'vendor' => []], + ]); $this->connection->shouldReceive('getSupplementalDriver')->times(4)->andReturn($this->driver); - $this->driver->shouldReceive('getForeignKeys')->with('authors')->once()->andReturn(array()); - $this->driver->shouldReceive('getForeignKeys')->with('Books')->once()->andReturn(array( - array('local' => 'author_id', 'table' => 'authors', 'foreign' => 'id'), - array('local' => 'translator_id', 'table' => 'authors', 'foreign' => 'id'), - )); - $this->driver->shouldReceive('getForeignKeys')->with('tags')->once()->andReturn(array()); - $this->driver->shouldReceive('getForeignKeys')->with('books_x_tags')->once()->andReturn(array( - array('local' => 'book_id', 'table' => 'Books', 'foreign' => 'id'), - array('local' => 'tag_id', 'table' => 'tags', 'foreign' => 'id'), - )); + $this->driver->shouldReceive('getForeignKeys')->with('authors')->once()->andReturn([]); + $this->driver->shouldReceive('getForeignKeys')->with('Books')->once()->andReturn([ + ['local' => 'author_id', 'table' => 'authors', 'foreign' => 'id'], + ['local' => 'translator_id', 'table' => 'authors', 'foreign' => 'id'], + ]); + $this->driver->shouldReceive('getForeignKeys')->with('tags')->once()->andReturn([]); + $this->driver->shouldReceive('getForeignKeys')->with('books_x_tags')->once()->andReturn([ + ['local' => 'book_id', 'table' => 'Books', 'foreign' => 'id'], + ['local' => 'tag_id', 'table' => 'tags', 'foreign' => 'id'], + ]); $this->structure = new StructureMock($this->connection, $this->storage); } @@ -91,22 +91,22 @@ class StructureTestCase extends TestCase public function testGetTables() { - Assert::same(array( - array('name' => 'authors', 'view' => FALSE), - array('name' => 'Books', 'view' => FALSE), - array('name' => 'tags', 'view' => FALSE), - array('name' => 'books_x_tags', 'view' => FALSE), - array('name' => 'books_view', 'view' => TRUE), - ), $this->structure->getTables()); + Assert::same([ + ['name' => 'authors', 'view' => FALSE], + ['name' => 'Books', 'view' => FALSE], + ['name' => 'tags', 'view' => FALSE], + ['name' => 'books_x_tags', 'view' => FALSE], + ['name' => 'books_view', 'view' => TRUE], + ], $this->structure->getTables()); } public function testGetColumns() { - $columns = array( - array('name' => 'id', 'primary' => TRUE, 'vendor' => array()), - array('name' => 'name', 'primary' => FALSE, 'vendor' => array()), - ); + $columns = [ + ['name' => 'id', 'primary' => TRUE, 'vendor' => []], + ['name' => 'name', 'primary' => FALSE, 'vendor' => []], + ]; Assert::same($columns, $this->structure->getColumns('tags')); Assert::same($columns, $this->structure->getColumns('Tags')); @@ -121,7 +121,7 @@ class StructureTestCase extends TestCase public function testGetPrimaryKey() { Assert::same('id', $this->structure->getPrimaryKey('books')); - Assert::same(array('book_id', 'tag_id'), $this->structure->getPrimaryKey('Books_x_tags')); + Assert::same(['book_id', 'tag_id'], $this->structure->getPrimaryKey('Books_x_tags')); Assert::null($this->structure->getPrimaryKey('invalid')); } @@ -141,12 +141,12 @@ class StructureTestCase extends TestCase public function testGetHasManyReference() { - Assert::same(array( - 'Books' => array('author_id', 'translator_id'), - ), $this->structure->getHasManyReference('authors')); + Assert::same([ + 'Books' => ['author_id', 'translator_id'], + ], $this->structure->getHasManyReference('authors')); Assert::same( - array('author_id', 'translator_id'), + ['author_id', 'translator_id'], $this->structure->getHasManyReference('authors', 'books') ); } @@ -154,17 +154,17 @@ class StructureTestCase extends TestCase public function testGetBelongsToReference() { - Assert::same(array(), $this->structure->getBelongsToReference('authors')); + Assert::same([], $this->structure->getBelongsToReference('authors')); - Assert::same(array( + Assert::same([ 'author_id' => 'authors', 'translator_id' => 'authors', - ), $this->structure->getBelongsToReference('books')); + ], $this->structure->getBelongsToReference('books')); - Assert::same(array( + Assert::same([ 'tag_id' => 'tags', 'book_id' => 'Books', - ), $this->structure->getBelongsToReference('books_x_tags')); + ], $this->structure->getBelongsToReference('books_x_tags')); } diff --git a/tests/Database/Structure.schemas.phpt b/tests/Database/Structure.schemas.phpt index e459c9995..9029cfb41 100644 --- a/tests/Database/Structure.schemas.phpt +++ b/tests/Database/Structure.schemas.phpt @@ -50,25 +50,25 @@ class StructureSchemasTestCase extends TestCase $this->connection->shouldReceive('getDsn')->once()->andReturn(''); $this->connection->shouldReceive('getSupplementalDriver')->once()->andReturn($this->driver); - $this->driver->shouldReceive('getTables')->once()->andReturn(array( - array('name' => 'authors', 'view' => FALSE, 'fullName' => 'authors.authors'), - array('name' => 'books', 'view' => FALSE, 'fullName' => 'books.books'), - )); - $this->driver->shouldReceive('getColumns')->with('authors.authors')->once()->andReturn(array( - array('name' => 'id', 'primary' => TRUE, 'vendor' => array('sequence' => '"authors"."authors_id_seq"')), - array('name' => 'name', 'primary' => FALSE, 'vendor' => array()), - )); - $this->driver->shouldReceive('getColumns')->with('books.books')->once()->andReturn(array( - array('name' => 'id', 'primary' => TRUE, 'vendor' => array('sequence' => '"books"."books_id_seq"')), - array('name' => 'title', 'primary' => FALSE, 'vendor' => array()), - )); + $this->driver->shouldReceive('getTables')->once()->andReturn([ + ['name' => 'authors', 'view' => FALSE, 'fullName' => 'authors.authors'], + ['name' => 'books', 'view' => FALSE, 'fullName' => 'books.books'], + ]); + $this->driver->shouldReceive('getColumns')->with('authors.authors')->once()->andReturn([ + ['name' => 'id', 'primary' => TRUE, 'vendor' => ['sequence' => '"authors"."authors_id_seq"']], + ['name' => 'name', 'primary' => FALSE, 'vendor' => []], + ]); + $this->driver->shouldReceive('getColumns')->with('books.books')->once()->andReturn([ + ['name' => 'id', 'primary' => TRUE, 'vendor' => ['sequence' => '"books"."books_id_seq"']], + ['name' => 'title', 'primary' => FALSE, 'vendor' => []], + ]); $this->connection->shouldReceive('getSupplementalDriver')->times(2)->andReturn($this->driver); - $this->driver->shouldReceive('getForeignKeys')->with('authors.authors')->once()->andReturn(array()); - $this->driver->shouldReceive('getForeignKeys')->with('books.books')->once()->andReturn(array( - array('local' => 'author_id', 'table' => 'authors.authors', 'foreign' => 'id'), - array('local' => 'translator_id', 'table' => 'authors.authors', 'foreign' => 'id'), - )); + $this->driver->shouldReceive('getForeignKeys')->with('authors.authors')->once()->andReturn([]); + $this->driver->shouldReceive('getForeignKeys')->with('books.books')->once()->andReturn([ + ['local' => 'author_id', 'table' => 'authors.authors', 'foreign' => 'id'], + ['local' => 'translator_id', 'table' => 'authors.authors', 'foreign' => 'id'], + ]); $this->structure = new StructureMock($this->connection, $this->storage); } @@ -76,30 +76,30 @@ class StructureSchemasTestCase extends TestCase public function testGetHasManyReference() { - Assert::same(array( - 'books.books' => array('author_id', 'translator_id'), - ), $this->structure->getHasManyReference('authors')); + Assert::same([ + 'books.books' => ['author_id', 'translator_id'], + ], $this->structure->getHasManyReference('authors')); - Assert::same(array( - 'books.books' => array('author_id', 'translator_id'), - ), $this->structure->getHasManyReference('authors.authors')); + Assert::same([ + 'books.books' => ['author_id', 'translator_id'], + ], $this->structure->getHasManyReference('authors.authors')); } public function testGetBelongsToReference() { - Assert::same(array(), $this->structure->getBelongsToReference('authors')); - Assert::same(array(), $this->structure->getBelongsToReference('authors.authors')); + Assert::same([], $this->structure->getBelongsToReference('authors')); + Assert::same([], $this->structure->getBelongsToReference('authors.authors')); - Assert::same(array( + Assert::same([ 'author_id' => 'authors.authors', 'translator_id' => 'authors.authors', - ), $this->structure->getBelongsToReference('books')); + ], $this->structure->getBelongsToReference('books')); - Assert::same(array( + Assert::same([ 'author_id' => 'authors.authors', 'translator_id' => 'authors.authors', - ), $this->structure->getBelongsToReference('books.books'));; + ], $this->structure->getBelongsToReference('books.books'));; } diff --git a/tests/Database/Table/GroupedSelection.insert().phpt b/tests/Database/Table/GroupedSelection.insert().phpt index 87ff78bdf..80bde994c 100644 --- a/tests/Database/Table/GroupedSelection.insert().phpt +++ b/tests/Database/Table/GroupedSelection.insert().phpt @@ -14,7 +14,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { $book = $context->table('book')->get(1); - $book->related('book_tag')->insert(array('tag_id' => 23)); + $book->related('book_tag')->insert(['tag_id' => 23]); Assert::equal(3, $book->related('book_tag')->count()); Assert::equal(3, $book->related('book_tag')->count('*')); @@ -26,6 +26,6 @@ test(function() use ($context) { test(function() use ($context) { // test counting already fetched rows $book = $context->table('book')->get(1); iterator_to_array($book->related('book_tag')); - $book->related('book_tag')->insert(array('tag_id' => 23)); + $book->related('book_tag')->insert(['tag_id' => 23]); Assert::equal(3, $book->related('book_tag')->count()); }); diff --git a/tests/Database/Table/Selection.fetch().phpt b/tests/Database/Table/Selection.fetch().phpt index eb1890853..c6c25f22a 100644 --- a/tests/Database/Table/Selection.fetch().phpt +++ b/tests/Database/Table/Selection.fetch().phpt @@ -13,11 +13,11 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { - $tags = array(); + $tags = []; $book = $context->table('book')->where('title', '1001 tipu a triku pro PHP')->fetch(); // SELECT * FROM `book` WHERE (`title` = ?) foreach ($book->related('book_tag')->where('tag_id', 21) as $book_tag) { // SELECT * FROM `book_tag` WHERE (`book_tag`.`book_id` IN (1)) AND (`tag_id` = 21) $tags[] = $book_tag->tag->name; // SELECT * FROM `tag` WHERE (`tag`.`id` IN (21)) } - Assert::same(array('PHP'), $tags); + Assert::same(['PHP'], $tags); }); diff --git a/tests/Database/Table/Selection.fetchAssoc().phpt b/tests/Database/Table/Selection.fetchAssoc().phpt index fde021ca7..fead3083f 100644 --- a/tests/Database/Table/Selection.fetchAssoc().phpt +++ b/tests/Database/Table/Selection.fetchAssoc().phpt @@ -15,10 +15,10 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { $apps = $context->table('book')->order('title')->fetchAssoc('id=title'); // SELECT * FROM `book` ORDER BY `title` - Assert::same(array( + Assert::same([ 1 => '1001 tipu a triku pro PHP', 4 => 'Dibi', 2 => 'JUSH', 3 => 'Nette', - ), $apps); + ], $apps); }); diff --git a/tests/Database/Table/Selection.fetchPairs().phpt b/tests/Database/Table/Selection.fetchPairs().phpt index a81af19db..d30bb32e4 100644 --- a/tests/Database/Table/Selection.fetchPairs().phpt +++ b/tests/Database/Table/Selection.fetchPairs().phpt @@ -14,32 +14,32 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { $apps = $context->table('book')->order('title')->fetchPairs('id', 'title'); // SELECT * FROM `book` ORDER BY `title` - Assert::same(array( + Assert::same([ 1 => '1001 tipu a triku pro PHP', 4 => 'Dibi', 2 => 'JUSH', 3 => 'Nette', - ), $apps); + ], $apps); }); test(function() use ($context) { $ids = $context->table('book')->order('id')->fetchPairs('id', 'id'); // SELECT * FROM `book` ORDER BY `id` - Assert::same(array( + Assert::same([ 1 => 1, 2 => 2, 3 => 3, 4 => 4, - ), $ids); + ], $ids); }); test(function() use ($context) { - $context->table('author')->get(11)->update(array('born' => new DateTime('2002-02-20'))); - $context->table('author')->get(12)->update(array('born' => new DateTime('2002-02-02'))); + $context->table('author')->get(11)->update(['born' => new DateTime('2002-02-20')]); + $context->table('author')->get(12)->update(['born' => new DateTime('2002-02-02')]); $list = $context->table('author')->where('born IS NOT NULL')->order('born')->fetchPairs('born', 'name'); - Assert::same(array( + Assert::same([ '2002-02-02 00:00:00' => 'David Grudl', '2002-02-20 00:00:00' => 'Jakub Vrana', - ), $list); + ], $list); }); diff --git a/tests/Database/Table/Selection.get().phpt b/tests/Database/Table/Selection.get().phpt index 9ccb3b78b..9f4a5801d 100644 --- a/tests/Database/Table/Selection.get().phpt +++ b/tests/Database/Table/Selection.get().phpt @@ -15,11 +15,11 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { $book = $context->table('book')->get(1); // SELECT * FROM `book` WHERE (`id` = ?) - Assert::same(array( + Assert::same([ 'id' => 1, 'author_id' => 11, 'translator_id' => 11, 'title' => '1001 tipu a triku pro PHP', 'next_volume' => NULL, - ), $book->toArray()); + ], $book->toArray()); }); diff --git a/tests/Database/Table/Selection.group().phpt b/tests/Database/Table/Selection.group().phpt index 78c321f50..cfae1ae52 100644 --- a/tests/Database/Table/Selection.group().phpt +++ b/tests/Database/Table/Selection.group().phpt @@ -14,5 +14,5 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { $authors = $context->table('book')->group('author_id')->order('author_id')->fetchPairs('author_id', 'author_id'); - Assert::same(array(11, 12), array_values($authors)); + Assert::same([11, 12], array_values($authors)); }); diff --git a/tests/Database/Table/Selection.insert().multi.phpt b/tests/Database/Table/Selection.insert().multi.phpt index 9cb8a1405..bb1e8a0eb 100644 --- a/tests/Database/Table/Selection.insert().multi.phpt +++ b/tests/Database/Table/Selection.insert().multi.phpt @@ -14,27 +14,27 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { Assert::same(3, $context->table('author')->count()); - $context->table('author')->insert(array( - array( + $context->table('author')->insert([ + [ 'name' => 'Catelyn Stark', 'web' => 'http://example.com', 'born' => new DateTime('2011-11-11'), - ), - array( + ], + [ 'name' => 'Sansa Stark', 'web' => 'http://example.com', 'born' => new DateTime('2021-11-11'), - ), - )); // INSERT INTO `author` (`name`, `web`, `born`) VALUES ('Catelyn Stark', 'http://example.com', '2011-11-11 00:00:00'), ('Sansa Stark', 'http://example.com', '2021-11-11 00:00:00') + ], + ]); // INSERT INTO `author` (`name`, `web`, `born`) VALUES ('Catelyn Stark', 'http://example.com', '2011-11-11 00:00:00'), ('Sansa Stark', 'http://example.com', '2021-11-11 00:00:00') Assert::same(5, $context->table('author')->count()); $context->table('book_tag')->where('book_id', 1)->delete(); // DELETE FROM `book_tag` WHERE (`book_id` = ?) Assert::same(4, $context->table('book_tag')->count()); - $context->table('book')->get(1)->related('book_tag')->insert(array( // SELECT * FROM `book` WHERE (`id` = ?) - array('tag_id' => 21), - array('tag_id' => 22), - array('tag_id' => 23), - )); // INSERT INTO `book_tag` (`tag_id`, `book_id`) VALUES (21, 1), (22, 1), (23, 1) + $context->table('book')->get(1)->related('book_tag')->insert([ // SELECT * FROM `book` WHERE (`id` = ?) + ['tag_id' => 21], + ['tag_id' => 22], + ['tag_id' => 23], + ]); // INSERT INTO `book_tag` (`tag_id`, `book_id`) VALUES (21, 1), (22, 1), (23, 1) Assert::same(7, $context->table('book_tag')->count()); }); diff --git a/tests/Database/Table/Selection.insert().phpt b/tests/Database/Table/Selection.insert().phpt index d67795a17..4717d1f61 100644 --- a/tests/Database/Table/Selection.insert().phpt +++ b/tests/Database/Table/Selection.insert().phpt @@ -12,11 +12,11 @@ require __DIR__ . '/../connect.inc.php'; // create $connection Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$book = $context->table('author')->insert(array( +$book = $context->table('author')->insert([ 'name' => $context->literal('LOWER(?)', 'Eddard Stark'), 'web' => 'http://example.com', 'born' => new \DateTime('2011-11-11'), -)); // INSERT INTO `author` (`name`, `web`) VALUES (LOWER('Eddard Stark'), 'http://example.com', '2011-11-11 00:00:00') +]); // INSERT INTO `author` (`name`, `web`) VALUES (LOWER('Eddard Stark'), 'http://example.com', '2011-11-11 00:00:00') // id = 14 Assert::equal('eddard stark', $book->name); @@ -28,10 +28,10 @@ $books = $context->table('book'); $book1 = $books->get(1); // SELECT * FROM `book` WHERE (`id` = ?) Assert::same('Jakub Vrana', $book1->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (11)) -$book2 = $books->insert(array( +$book2 = $books->insert([ 'title' => 'Dragonstone', 'author_id' => $context->table('author')->get(14), // SELECT * FROM `author` WHERE (`id` = ?) -)); // INSERT INTO `book` (`title`, `author_id`) VALUES ('Dragonstone', 14) +]); // INSERT INTO `book` (`title`, `author_id`) VALUES ('Dragonstone', 14) Assert::same('eddard stark', $book2->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (11, 15)) @@ -40,11 +40,11 @@ Assert::same('eddard stark', $book2->author->name); // SELECT * FROM `author` W // This exception is about primary key violation. if ($driverName !== 'sqlsrv') { Assert::exception(function() use ($context) { - $context->table('author')->insert(array( + $context->table('author')->insert([ 'id' => 14, 'name' => 'Jon Snow', 'web' => 'http://example.com', - )); + ]); }, '\PDOException'); } @@ -76,8 +76,8 @@ $context = new Nette\Database\Context( new Nette\Database\Conventions\DiscoveredConventions($structure) ); -$inserted = $context->table('note')->insert(array( +$inserted = $context->table('note')->insert([ 'book_id' => 1, 'note' => 'Good one!', -)); +]); Assert::equal(1, $inserted); diff --git a/tests/Database/Table/Selection.order().phpt b/tests/Database/Table/Selection.order().phpt index 58cffd1bd..bfae943e4 100644 --- a/tests/Database/Table/Selection.order().phpt +++ b/tests/Database/Table/Selection.order().phpt @@ -13,13 +13,13 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { - $apps = array(); + $apps = []; foreach ($context->table('book')->where('title LIKE ?', '%t%')->order('title')->limit(3) as $book) { // SELECT * FROM `book` WHERE (`title` LIKE ?) ORDER BY `title` LIMIT 3 $apps[] = $book->title; } - Assert::same(array( + Assert::same([ '1001 tipu a triku pro PHP', 'Nette', - ), $apps); + ], $apps); }); diff --git a/tests/Database/Table/SqlBuilder.addWhere().phpt b/tests/Database/Table/SqlBuilder.addWhere().phpt index e30325cea..bcb8a4204 100644 --- a/tests/Database/Table/SqlBuilder.addWhere().phpt +++ b/tests/Database/Table/SqlBuilder.addWhere().phpt @@ -18,8 +18,8 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { // test paramateres with NULL $sqlBuilder = new SqlBuilder('book', $context); - $sqlBuilder->addWhere('id ? OR id ?', array(1, NULL)); - $sqlBuilder->addWhere('id ? OR id ?', array(1, NULL)); // duplicit condition + $sqlBuilder->addWhere('id ? OR id ?', [1, NULL]); + $sqlBuilder->addWhere('id ? OR id ?', [1, NULL]); // duplicit condition Assert::same(reformat('SELECT * FROM [book] WHERE ([id] = ? OR [id] IS NULL)'), $sqlBuilder->buildSelectQuery()); }); @@ -36,40 +36,40 @@ test(function() use ($context) { // ?name test(function() use ($context) { // test Selection as a parameter $sqlBuilder = new SqlBuilder('book', $context); $sqlBuilder->addWhere('id', $context->table('book')); - Assert::equal(reformat(array( + Assert::equal(reformat([ 'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?))', 'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book]))', - )), $sqlBuilder->buildSelectQuery()); + ]), $sqlBuilder->buildSelectQuery()); }); test(function() use ($context) { // test Selection with parameters as a parameter $sqlBuilder = new SqlBuilder('book', $context); $sqlBuilder->addWhere('id', $context->table('book')->having('COUNT(:book_tag.tag_id) >', 1)); $schemaSupported = $context->getConnection()->getSupplementalDriver()->isSupported(ISupplementalDriver::SUPPORT_SCHEMA); - Assert::equal(reformat(array( + Assert::equal(reformat([ 'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?))', 'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book] LEFT JOIN ' . ($schemaSupported ? '[public].[book_tag] AS ' : '') . '[book_tag] ON [book].[id] = [book_tag].[book_id] HAVING COUNT([book_tag].[tag_id]) >))', - )), $sqlBuilder->buildSelectQuery()); + ]), $sqlBuilder->buildSelectQuery()); Assert::count(1, $sqlBuilder->getParameters()); }); test(function() use ($context) { // test Selection with column as a parameter $sqlBuilder = new SqlBuilder('book', $context); $sqlBuilder->addWhere('id', $context->table('book')->select('id')); - Assert::equal(reformat(array( + Assert::equal(reformat([ 'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?))', 'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book]))', - )), $sqlBuilder->buildSelectQuery()); + ]), $sqlBuilder->buildSelectQuery()); }); test(function() use ($context) { // test multiple placeholder parameter $sqlBuilder = new SqlBuilder('book', $context); $sqlBuilder->addWhere('id ? OR id ?', NULL, $context->table('book')); - Assert::equal(reformat(array( + Assert::equal(reformat([ 'mysql' => 'SELECT * FROM `book` WHERE (`id` IS NULL OR `id` IN (?))', 'SELECT * FROM [book] WHERE ([id] IS NULL OR [id] IN (SELECT [id] FROM [book]))', - )), $sqlBuilder->buildSelectQuery()); + ]), $sqlBuilder->buildSelectQuery()); }); @@ -82,23 +82,23 @@ test(function() use ($context) { // test SqlLiteral test(function() use ($context) { // test auto type detection $sqlBuilder = new SqlBuilder('book', $context); - $sqlBuilder->addWhere('id ? OR id ? OR id ?', 1, "test", array(1, 2)); + $sqlBuilder->addWhere('id ? OR id ? OR id ?', 1, "test", [1, 2]); Assert::same(reformat('SELECT * FROM [book] WHERE ([id] = ? OR [id] = ? OR [id] IN (?))'), $sqlBuilder->buildSelectQuery()); }); test(function() use ($context) { // test empty array $sqlBuilder = new SqlBuilder('book', $context); - $sqlBuilder->addWhere('id', array()); - $sqlBuilder->addWhere('id NOT', array()); - $sqlBuilder->addWhere('NOT (id ?)', array()); + $sqlBuilder->addWhere('id', []); + $sqlBuilder->addWhere('id NOT', []); + $sqlBuilder->addWhere('NOT (id ?)', []); Assert::exception(function() use ($sqlBuilder) { - $sqlBuilder->addWhere('TRUE AND id', array()); + $sqlBuilder->addWhere('TRUE AND id', []); }, 'Nette\InvalidArgumentException', 'Possible SQL query corruption. Add parentheses around operators.'); Assert::exception(function() use ($sqlBuilder) { - $sqlBuilder->addWhere('NOT id', array()); + $sqlBuilder->addWhere('NOT id', []); }, 'Nette\InvalidArgumentException', 'Possible SQL query corruption. Add parentheses around operators.'); Assert::same(reformat('SELECT * FROM [book] WHERE ([id] IS NULL AND FALSE) AND ([id] IS NULL OR TRUE) AND (NOT ([id] IS NULL AND FALSE))'), $sqlBuilder->buildSelectQuery()); @@ -107,10 +107,10 @@ test(function() use ($context) { // test empty array test(function() use ($context) { // backward compatibility $sqlBuilder = new SqlBuilder('book', $context); - $sqlBuilder->addWhere('id = ? OR id ? OR id IN ? OR id LIKE ? OR id > ?', 1, 2, array(1, 2), "%test", 3); + $sqlBuilder->addWhere('id = ? OR id ? OR id IN ? OR id LIKE ? OR id > ?', 1, 2, [1, 2], "%test", 3); $sqlBuilder->addWhere('name', "var"); $sqlBuilder->addWhere('MAIN', 0); // "IN" is not considered as the operator - $sqlBuilder->addWhere('id IN (?)', array(1, 2)); + $sqlBuilder->addWhere('id IN (?)', [1, 2]); Assert::same(reformat('SELECT * FROM [book] WHERE ([id] = ? OR [id] = ? OR [id] IN (?) OR [id] LIKE ? OR [id] > ?) AND ([name] = ?) AND (MAIN = ?) AND ([id] IN (?))'), $sqlBuilder->buildSelectQuery()); }); @@ -136,24 +136,24 @@ test(function() use ($context) { // tests multiline condition test(function() use ($context) { // tests NOT $sqlBuilder = new SqlBuilder('book', $context); - $sqlBuilder->addWhere('id NOT', array(1, 2)); + $sqlBuilder->addWhere('id NOT', [1, 2]); $sqlBuilder->addWhere('id NOT', NULL); $sqlBuilder->addWhere('id NOT', $context->table('book')->select('id')); - Assert::equal(reformat(array( + Assert::equal(reformat([ 'mysql' => 'SELECT * FROM `book` WHERE (`id` NOT IN (?)) AND (`id` IS NOT NULL) AND (`id` NOT IN (?))', 'SELECT * FROM [book] WHERE ([id] NOT IN (?)) AND ([id] IS NOT NULL) AND ([id] NOT IN (SELECT [id] FROM [book]))', - )), $sqlBuilder->buildSelectQuery()); + ]), $sqlBuilder->buildSelectQuery()); }); test(function() use ($context) { // tests multi column IN clause $sqlBuilder = new SqlBuilder('book_tag', $context); - $sqlBuilder->addWhere(array('book_id', 'tag_id'), array(array(1, 11), array(2, 12))); - Assert::equal(reformat(array( + $sqlBuilder->addWhere(['book_id', 'tag_id'], [[1, 11], [2, 12]]); + Assert::equal(reformat([ 'sqlite' => 'SELECT * FROM [book_tag] WHERE (([book_id] = ? AND [tag_id] = ?) OR ([book_id] = ? AND [tag_id] = ?))', 'mysql' => 'SELECT * FROM `book_tag` WHERE ((`book_id` = ? AND `tag_id` = ?) OR (`book_id` = ? AND `tag_id` = ?))', 'SELECT * FROM [book_tag] WHERE (([book_id], [tag_id]) IN (?))', - )), $sqlBuilder->buildSelectQuery()); + ]), $sqlBuilder->buildSelectQuery()); }); @@ -193,7 +193,7 @@ Assert::exception(function() use ($context) { Assert::exception(function() use ($context) { $sqlBuilder = new SqlBuilder('book', $context); - $sqlBuilder->addWhere('id = ?', array(1, 2)); + $sqlBuilder->addWhere('id = ?', [1, 2]); }, 'Nette\InvalidArgumentException', 'Column operator does not accept array argument.'); diff --git a/tests/Database/Table/SqlBuilder.order.phpt b/tests/Database/Table/SqlBuilder.order.phpt index 41447c2c2..17211b354 100644 --- a/tests/Database/Table/SqlBuilder.order.phpt +++ b/tests/Database/Table/SqlBuilder.order.phpt @@ -18,7 +18,7 @@ test(function() use ($context) { $sqlBuilder->addOrder('FIELD(title, ?, ?)', 'a', 'b'); Assert::same(reformat('SELECT * FROM [book] ORDER BY [id], [title] DESC, FIELD([title], ?, ?)'), $sqlBuilder->buildSelectQuery()); - Assert::same(array('a', 'b'), $sqlBuilder->getParameters()); + Assert::same(['a', 'b'], $sqlBuilder->getParameters()); }); @@ -26,8 +26,8 @@ test(function() use ($context) { $sqlBuilder = new SqlBuilder('book', $context); $sqlBuilder->addOrder('id'); $sqlBuilder->addOrder('title DESC'); - $sqlBuilder->setOrder(array('FIELD(title, ?, ?)'), array('a', 'b')); + $sqlBuilder->setOrder(['FIELD(title, ?, ?)'], ['a', 'b']); Assert::same(reformat('SELECT * FROM [book] ORDER BY FIELD([title], ?, ?)'), $sqlBuilder->buildSelectQuery()); - Assert::same(array('a', 'b'), $sqlBuilder->getParameters()); + Assert::same(['a', 'b'], $sqlBuilder->getParameters()); }); diff --git a/tests/Database/Table/SqlBuilder.parseJoins().phpt b/tests/Database/Table/SqlBuilder.parseJoins().phpt index c6a8f3bf5..ab39c9f8c 100644 --- a/tests/Database/Table/SqlBuilder.parseJoins().phpt +++ b/tests/Database/Table/SqlBuilder.parseJoins().phpt @@ -32,14 +32,14 @@ $sqlBuilder = new SqlBuilderMock('nUsers', $context); $driver = $connection->getSupplementalDriver(); -$joins = array(); +$joins = []; $query = 'WHERE :nusers_ntopics.topic.priorit.id IS NULL'; $sqlBuilder->parseJoins($joins, $query); $join = $sqlBuilder->buildQueryJoins($joins); Assert::same('WHERE priorit.id IS NULL', $query); $tables = $connection->getSupplementalDriver()->getTables(); -if (!in_array($tables[0]['name'], array('npriorities', 'ntopics', 'nusers', 'nusers_ntopics', 'nusers_ntopics_alt'), TRUE)) { +if (!in_array($tables[0]['name'], ['npriorities', 'ntopics', 'nusers', 'nusers_ntopics', 'nusers_ntopics_alt'], TRUE)) { if ($driver->isSupported(ISupplementalDriver::SUPPORT_SCHEMA)) { Assert::same( 'LEFT JOIN public.nUsers_nTopics AS nusers_ntopics ON nUsers.nUserId = nusers_ntopics.nUserId ' . @@ -72,7 +72,7 @@ $structure->rebuild(); $sqlBuilder = new SqlBuilderMock('author', $context); -$joins = array(); +$joins = []; $query = 'WHERE :book(translator).next_volume IS NULL'; $sqlBuilder->parseJoins($joins, $query); $join = $sqlBuilder->buildQueryJoins($joins); @@ -89,7 +89,7 @@ if ($driver->isSupported(ISupplementalDriver::SUPPORT_SCHEMA)) { $sqlBuilder = new SqlBuilderMock('book', $context); } -$joins = array(); +$joins = []; $query = 'WHERE :book.translator_id IS NULL AND :book:book.translator_id IS NULL'; $sqlBuilder->parseJoins($joins, $query); $join = $sqlBuilder->buildQueryJoins($joins); diff --git a/tests/Database/Table/Table.aggregation.phpt b/tests/Database/Table/Table.aggregation.phpt index a82d84ed3..64ba0f8b3 100644 --- a/tests/Database/Table/Table.aggregation.phpt +++ b/tests/Database/Table/Table.aggregation.phpt @@ -19,18 +19,18 @@ test(function() use ($context) { test(function() use ($context) { - $tags = array(); + $tags = []; foreach ($context->table('book') as $book) { // SELECT * FROM `book` $count = $book->related('book_tag')->count('*'); // SELECT COUNT(*), `book_id` FROM `book_tag` WHERE (`book_tag`.`book_id` IN (1, 2, 3, 4)) GROUP BY `book_id` $tags[$book->title] = $count; } - Assert::same(array( + Assert::same([ '1001 tipu a triku pro PHP' => 2, 'JUSH' => 1, 'Nette' => 1, 'Dibi' => 2, - ), $tags); + ], $tags); }); diff --git a/tests/Database/Table/Table.backjoin.phpt b/tests/Database/Table/Table.backjoin.phpt index 3e9a14560..ffebb4944 100644 --- a/tests/Database/Table/Table.backjoin.phpt +++ b/tests/Database/Table/Table.backjoin.phpt @@ -15,7 +15,7 @@ $driver = $connection->getSupplementalDriver(); test(function() use ($context) { - $authorTagsCount = array(); + $authorTagsCount = []; $authors = $context ->table('author') ->select('author.name, COUNT(DISTINCT :book:book_tag.tag_id) AS tagsCount') @@ -27,10 +27,10 @@ test(function() use ($context) { $authorTagsCount[$author->name] = $author->tagsCount; } - Assert::same(array( + Assert::same([ 'David Grudl' => 2, 'Geek' => 0, - ), $authorTagsCount); + ], $authorTagsCount); }); @@ -49,12 +49,12 @@ test(function() use ($context, $driver) { ); } - $authors = array(); + $authors = []; foreach ($authorsSelection as $author) { $authors[$author->id] = $author->name; } - Assert::same(array(12 => 'David Grudl'), $authors); + Assert::same([12 => 'David Grudl'], $authors); }); diff --git a/tests/Database/Table/Table.basic.camelCase.phpt b/tests/Database/Table/Table.basic.camelCase.phpt index 7475f262e..71497a999 100644 --- a/tests/Database/Table/Table.basic.camelCase.phpt +++ b/tests/Database/Table/Table.basic.camelCase.phpt @@ -13,16 +13,16 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { - $titles = array(); + $titles = []; foreach ($context->table('nUsers')->order('nUserId') as $user) { foreach ($user->related('nUsers_nTopics')->order('nTopicId') as $userTopic) { $titles[$userTopic->nTopic->title] = $user->name; } } - Assert::same(array( + Assert::same([ 'Topic #1' => 'John', 'Topic #3' => 'John', 'Topic #2' => 'Doe', - ), $titles); + ], $titles); }); diff --git a/tests/Database/Table/Table.basic.phpt b/tests/Database/Table/Table.basic.phpt index b0264720d..78d5c292c 100644 --- a/tests/Database/Table/Table.basic.phpt +++ b/tests/Database/Table/Table.basic.phpt @@ -14,19 +14,19 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { $book = $context->table('book')->where('id = ?', 1)->select('id, title')->fetch()->toArray(); // SELECT `id`, `title` FROM `book` WHERE (`id` = ?) - Assert::same(array( + Assert::same([ 'id' => 1, 'title' => '1001 tipu a triku pro PHP', - ), $book); + ], $book); }); test(function() use ($context) { $book = $context->table('book')->select('id, title')->where('id = ?', 1)->fetch()->toArray(); // SELECT `id`, `title` FROM `book` WHERE (`id` = ?) - Assert::same(array( + Assert::same([ 'id' => 1, 'title' => '1001 tipu a triku pro PHP', - ), $book); + ], $book); }); @@ -39,36 +39,36 @@ test(function() use ($context) { test(function() use ($context) { - $bookTags = array(); + $bookTags = []; foreach ($context->table('book') as $book) { // SELECT * FROM `book` - $bookTags[$book->title] = array( + $bookTags[$book->title] = [ 'author' => $book->author->name, // SELECT * FROM `author` WHERE (`author`.`id` IN (11, 12)) - 'tags' => array(), - ); + 'tags' => [], + ]; foreach ($book->related('book_tag') as $book_tag) { // SELECT * FROM `book_tag` WHERE (`book_tag`.`book_id` IN (1, 2, 3, 4)) $bookTags[$book->title]['tags'][] = $book_tag->tag->name; // SELECT * FROM `tag` WHERE (`tag`.`id` IN (21, 22, 23)) } } - Assert::same(array( - '1001 tipu a triku pro PHP' => array( + Assert::same([ + '1001 tipu a triku pro PHP' => [ 'author' => 'Jakub Vrana', - 'tags' => array('PHP', 'MySQL'), - ), - 'JUSH' => array( + 'tags' => ['PHP', 'MySQL'], + ], + 'JUSH' => [ 'author' => 'Jakub Vrana', - 'tags' => array('JavaScript'), - ), - 'Nette' => array( + 'tags' => ['JavaScript'], + ], + 'Nette' => [ 'author' => 'David Grudl', - 'tags' => array('PHP'), - ), - 'Dibi' => array( + 'tags' => ['PHP'], + ], + 'Dibi' => [ 'author' => 'David Grudl', - 'tags' => array('PHP', 'MySQL'), - ), - ), $bookTags); + 'tags' => ['PHP', 'MySQL'], + ], + ], $bookTags); }); diff --git a/tests/Database/Table/Table.cache.observer.phpt b/tests/Database/Table/Table.cache.observer.phpt index c6036b546..664ce59b8 100644 --- a/tests/Database/Table/Table.cache.observer.phpt +++ b/tests/Database/Table/Table.cache.observer.phpt @@ -14,9 +14,9 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN $cacheStorage = Mockery::mock('Nette\Caching\Istorage'); -$cacheStorage->shouldReceive('read')->withAnyArgs()->once()->andReturn(array('id' => TRUE)); -$cacheStorage->shouldReceive('read')->withAnyArgs()->times(4)->andReturn(array('id' => TRUE, 'author_id' => TRUE)); -$cacheStorage->shouldReceive('write')->with(Mockery::any(), array('id' => TRUE, 'author_id' => TRUE, 'title' => TRUE), array()); +$cacheStorage->shouldReceive('read')->withAnyArgs()->once()->andReturn(['id' => TRUE]); +$cacheStorage->shouldReceive('read')->withAnyArgs()->times(4)->andReturn(['id' => TRUE, 'author_id' => TRUE]); +$cacheStorage->shouldReceive('write')->with(Mockery::any(), ['id' => TRUE, 'author_id' => TRUE, 'title' => TRUE], []); $context = new Nette\Database\Context($connection, $structure, $conventions, $cacheStorage); @@ -28,7 +28,7 @@ $connection->onQuery[] = function($dao, ResultSet $result) use (& $queries) { }; $authors = $context->table('author'); -$stack = array(); +$stack = []; foreach ($authors as $author) { foreach ($stack[] = $author->related('book') as $book) { $book->title; diff --git a/tests/Database/Table/Table.cache.phpt b/tests/Database/Table/Table.cache.phpt index 670970662..23e294c6b 100644 --- a/tests/Database/Table/Table.cache.phpt +++ b/tests/Database/Table/Table.cache.phpt @@ -13,7 +13,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { // Testing Selection caching - $sql = array(); + $sql = []; for ($i = 0; $i < 4; $i += 1) { if ($i !== 2) { $bookSelection = $context->table('book')->wherePrimary(2); @@ -42,12 +42,12 @@ test(function() use ($context) { // Testing Selection caching * - fetch used column with new used column / cycle 4 */ - Assert::same(array( + Assert::same([ reformat('SELECT * FROM [book] WHERE ([book].[id] = ?)'), reformat('SELECT [id], [title], [translator_id] FROM [book] WHERE ([book].[id] = ?)'), reformat('SELECT * FROM [book] WHERE ([book].[id] = ?)'), reformat('SELECT [id], [title], [translator_id], [author_id] FROM [book] WHERE ([book].[id] = ?)') - ), $sql); + ], $sql); }); @@ -62,7 +62,7 @@ test(function() use ($context) { // Testing GroupedSelection reinvalidation cach reset($stack)->__destruct(); - $books = array(); + $books = []; foreach ($context->table('author') as $author) { foreach ($author->related('book.author_id')->order('title') as $book) { if ($book->author_id == 12) { @@ -71,15 +71,15 @@ test(function() use ($context) { // Testing GroupedSelection reinvalidation cach } } - Assert::same(array( + Assert::same([ 'Dibi' => 12, 'Nette' => 12, - ), $books); + ], $books); }); before(function() use ($cacheMemoryStorage) { - $cacheMemoryStorage->clean(array(Nette\Caching\Cache::ALL => TRUE)); + $cacheMemoryStorage->clean([Nette\Caching\Cache::ALL => TRUE]); }); @@ -90,7 +90,7 @@ test(function() use ($context) { } $selection->__destruct(); - $authors = array(); + $authors = []; foreach ($context->table('book') as $book) { $authors[$book->author->name] = 1; } @@ -98,15 +98,15 @@ test(function() use ($context) { $authors = array_keys($authors); sort($authors); - Assert::same(array( + Assert::same([ 'David Grudl', 'Jakub Vrana', - ), $authors); + ], $authors); }); test(function() use ($context) { - $relatedStack = array(); + $relatedStack = []; foreach ($context->table('author') as $author) { $relatedStack[] = $related = $author->related('book.author_id'); foreach ($related as $book) { @@ -118,13 +118,13 @@ test(function() use ($context) { $property = $related->getReflection()->getProperty('accessedColumns'); $property->setAccessible(TRUE); // checks if instances have shared data of accessed columns - Assert::same(array('id', 'author_id'), array_keys((array) $property->getValue($related))); + Assert::same(['id', 'author_id'], array_keys((array) $property->getValue($related))); } }); test(function() use ($context) { // Test saving joining keys even with 0 rows - $cols = array(); + $cols = []; for ($i = 0; $i < 2; $i += 1) { $author = $context->table('author')->get(11); $books = $author->related('book')->where('translator_id', 99); // 0 rows @@ -133,15 +133,15 @@ test(function() use ($context) { // Test saving joining keys even with 0 rows $books->__destruct(); } - Assert::same(array( - array(), - array('id', 'author_id'), - ), $cols); + Assert::same([ + [], + ['id', 'author_id'], + ], $cols); }); test(function() use ($context) { // Test saving the union of needed cols, the second call is subset - $cols = array(); + $cols = []; for ($i = 0; $i < 3; $i += 1) { $author = $context->table('author')->get(11); $books = $author->related('book'); @@ -155,16 +155,16 @@ test(function() use ($context) { // Test saving the union of needed cols, the se $books->__destruct(); } - Assert::same(array( - array(), - array('id', 'author_id', 'translator_id', 'title'), - array('id', 'author_id', 'translator_id', 'title'), - ), $cols); + Assert::same([ + [], + ['id', 'author_id', 'translator_id', 'title'], + ['id', 'author_id', 'translator_id', 'title'], + ], $cols); }); test(function() use ($context) { // Test saving the union of needed cols, the second call is not subset - $cols = array(); + $cols = []; for ($i = 0; $i < 3; $i += 1) { $author = $context->table('author')->get(11); $books = $author->related('book'); @@ -179,9 +179,9 @@ test(function() use ($context) { // Test saving the union of needed cols, the se $books->__destruct(); } - Assert::same(array( - array(), - array('id', 'author_id', 'translator_id'), - array('id', 'author_id', 'translator_id', 'title'), - ), $cols); + Assert::same([ + [], + ['id', 'author_id', 'translator_id'], + ['id', 'author_id', 'translator_id', 'title'], + ], $cols); }); diff --git a/tests/Database/Table/Table.cache.rows.phpt b/tests/Database/Table/Table.cache.rows.phpt index a20f621c9..c5c1a618b 100644 --- a/tests/Database/Table/Table.cache.rows.phpt +++ b/tests/Database/Table/Table.cache.rows.phpt @@ -12,7 +12,7 @@ require __DIR__ . '/../connect.inc.php'; // create $connection Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$selections = array(); +$selections = []; foreach ($selections[] = $context->table('book') as $book) { $book->author->name; $selections[] = $book->author->getTable(); @@ -21,20 +21,20 @@ foreach ($selections as $selection) { $selection->__destruct(); } -$authors = array(); +$authors = []; foreach ($context->table('book') as $book) { $authors[] = $book->author; } -$webs = array(); +$webs = []; foreach ($authors as $author) { $webs[$author->web] = NULL; } ksort($webs); -Assert::same(array( +Assert::same([ 'http://davidgrudl.com/', 'http://www.vrana.cz/', -), array_keys($webs)); +], array_keys($webs)); $bookSelection = $context->table('book')->order('id'); @@ -43,7 +43,7 @@ $book->author_id; $bookSelection->__destruct(); $bookSelection = $context->table('book')->order('id'); -$books = array(); +$books = []; $books[] = $bookSelection->fetch(); $books[] = $bookSelection->fetch()->toArray(); $books[] = $bookSelection->fetch()->toArray(); @@ -52,10 +52,10 @@ Assert::same(2, $books[1]['id']); Assert::same(3, $books[2]['id']); -$row = $context->table('author')->insert(array( +$row = $context->table('author')->insert([ 'name' => 'Eddard Stark', 'web' => 'http://example.com', -)); // INSERT INTO `author` (`name`, `web`) VALUES ('Eddard Stark', 'http://example.com') +]); // INSERT INTO `author` (`name`, `web`) VALUES ('Eddard Stark', 'http://example.com') Assert::true(is_array($row->toArray())); // id = 14 diff --git a/tests/Database/Table/Table.cache2.phpt b/tests/Database/Table/Table.cache2.phpt index 8c53c573c..54b874ee1 100644 --- a/tests/Database/Table/Table.cache2.phpt +++ b/tests/Database/Table/Table.cache2.phpt @@ -11,7 +11,7 @@ require __DIR__ . '/../connect.inc.php'; // create $connection Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$res = array(); +$res = []; for ($i = 1; $i <= 2; ++$i) { @@ -31,7 +31,7 @@ for ($i = 1; $i <= 2; ++$i) { } -Assert::same(array( +Assert::same([ 'Jakub Vrana', '1001 tipu a triku pro PHP', 'JUSH', @@ -48,4 +48,4 @@ Assert::same(array( 'Dibi', 'Geek', 'Geek', -), $res); +], $res); diff --git a/tests/Database/Table/Table.columnRefetch.phpt b/tests/Database/Table/Table.columnRefetch.phpt index eda550ca6..b341b2105 100644 --- a/tests/Database/Table/Table.columnRefetch.phpt +++ b/tests/Database/Table/Table.columnRefetch.phpt @@ -18,25 +18,25 @@ foreach ($books as $book) { } $books->__destruct(); -$res = array(); +$res = []; $books = $context->table('book')->order('id DESC')->limit(2); foreach ($books as $book) { $res[] = (string) $book->title; } -Assert::same(array('Dibi', 'Nette'), $res); +Assert::same(['Dibi', 'Nette'], $res); -$context->table('book')->insert(array( +$context->table('book')->insert([ 'title' => 'New book #1', 'author_id' => 11, -)); -$context->table('book')->insert(array( +]); +$context->table('book')->insert([ 'title' => 'New book #2', 'author_id' => 11, -)); +]); -$res = array(); +$res = []; foreach ($books as $book) { $res[] = (string) $book->title; $res[] = (string) $book->author->name; } -Assert::same(array('Dibi', 'David Grudl', 'Nette', 'David Grudl'), $res); +Assert::same(['Dibi', 'David Grudl', 'Nette', 'David Grudl'], $res); diff --git a/tests/Database/Table/Table.discoveredReflection.phpt b/tests/Database/Table/Table.discoveredReflection.phpt index eb7aaf8ff..1f83109c2 100644 --- a/tests/Database/Table/Table.discoveredReflection.phpt +++ b/tests/Database/Table/Table.discoveredReflection.phpt @@ -13,53 +13,53 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { - $appTags = array(); + $appTags = []; foreach ($context->table('book') as $book) { - $appTags[$book->title] = array( + $appTags[$book->title] = [ 'author' => $book->author->name, - 'tags' => array(), - ); + 'tags' => [], + ]; foreach ($book->related('book_tag') as $book_tag) { $appTags[$book->title]['tags'][] = $book_tag->tag->name; } } - Assert::same(array( - '1001 tipu a triku pro PHP' => array( + Assert::same([ + '1001 tipu a triku pro PHP' => [ 'author' => 'Jakub Vrana', - 'tags' => array('PHP', 'MySQL'), - ), - 'JUSH' => array( + 'tags' => ['PHP', 'MySQL'], + ], + 'JUSH' => [ 'author' => 'Jakub Vrana', - 'tags' => array('JavaScript'), - ), - 'Nette' => array( + 'tags' => ['JavaScript'], + ], + 'Nette' => [ 'author' => 'David Grudl', - 'tags' => array('PHP'), - ), - 'Dibi' => array( + 'tags' => ['PHP'], + ], + 'Dibi' => [ 'author' => 'David Grudl', - 'tags' => array('PHP', 'MySQL'), - ), - ), $appTags); + 'tags' => ['PHP', 'MySQL'], + ], + ], $appTags); }); test(function() use ($context) { - $books = array(); + $books = []; foreach ($context->table('author') as $author) { foreach ($author->related('book') as $book) { $books[$book->title] = $author->name; } } - Assert::same(array( + Assert::same([ '1001 tipu a triku pro PHP' => 'Jakub Vrana', 'JUSH' => 'Jakub Vrana', 'Nette' => 'David Grudl', 'Dibi' => 'David Grudl', - ), $books); + ], $books); }); @@ -92,19 +92,19 @@ test(function() use ($connection, $context) { $lowerCase->Value != 0 ) { // tests case-insensitive reflection - $books = array(); + $books = []; foreach ($context->table('Author') as $author) { foreach ($author->related('book') as $book) { $books[$book->title] = $author->name; } } - Assert::same(array( + Assert::same([ '1001 tipu a triku pro PHP' => 'Jakub Vrana', 'JUSH' => 'Jakub Vrana', 'Nette' => 'David Grudl', 'Dibi' => 'David Grudl', - ), $books); + ], $books); } }); diff --git a/tests/Database/Table/Table.join.phpt b/tests/Database/Table/Table.join.phpt index 786663c21..5cc360064 100644 --- a/tests/Database/Table/Table.join.phpt +++ b/tests/Database/Table/Table.join.phpt @@ -15,17 +15,17 @@ $driver = $connection->getSupplementalDriver(); test(function() use ($context) { - $apps = array(); + $apps = []; foreach ($context->table('book')->order('author.name, title') as $book) { // SELECT `book`.* FROM `book` LEFT JOIN `author` ON `book`.`author_id` = `author`.`id` ORDER BY `author`.`name`, `title` $apps[$book->title] = $book->author->name; // SELECT * FROM `author` WHERE (`author`.`id` IN (12, 11)) } - Assert::same(array( + Assert::same([ 'Dibi' => 'David Grudl', 'Nette' => 'David Grudl', '1001 tipu a triku pro PHP' => 'Jakub Vrana', 'JUSH' => 'Jakub Vrana', - ), $apps); + ], $apps); }); @@ -64,16 +64,16 @@ test(function() use ($context, $driver) { test(function() use ($context) { - $tags = array(); + $tags = []; foreach ($context->table('book_tag')->where('book.author.name', 'Jakub Vrana')->group('book_tag.tag_id')->order('book_tag.tag_id') as $book_tag) { // SELECT `book_tag`.* FROM `book_tag` INNER JOIN `book` ON `book_tag`.`book_id` = `book`.`id` INNER JOIN `author` ON `book`.`author_id` = `author`.`id` WHERE (`author`.`name` = ?) GROUP BY `book_tag`.`tag_id` $tags[] = $book_tag->tag->name; // SELECT * FROM `tag` WHERE (`tag`.`id` IN (21, 22, 23)) } - Assert::same(array( + Assert::same([ 'PHP', 'MySQL', 'JavaScript', - ), $tags); + ], $tags); }); diff --git a/tests/Database/Table/Table.multi-primary-key.phpt b/tests/Database/Table/Table.multi-primary-key.phpt index 341c7d3c3..d028c49d9 100644 --- a/tests/Database/Table/Table.multi-primary-key.phpt +++ b/tests/Database/Table/Table.multi-primary-key.phpt @@ -37,26 +37,26 @@ test(function() use ($context) { } $related->__destruct(); - $states = array(); + $states = []; $book = $context->table('book')->get(3); foreach ($book->related('book_tag_alt') as $bookTag) { $states[] = $bookTag->state; } - Assert::same(array( + Assert::same([ 'public', 'private', 'private', 'public', - ), $states); + ], $states); }); test(function() use ($context) { - $context->table('book_tag')->insert(array( + $context->table('book_tag')->insert([ 'book_id' => 1, 'tag_id' => 21, // PHP tag - )); + ]); $count = $context->table('book_tag')->where('book_id', 1)->count('*'); Assert::same(2, $count); }); diff --git a/tests/Database/Table/Table.placeholders.phpt b/tests/Database/Table/Table.placeholders.phpt index 201bceb42..c365526b3 100644 --- a/tests/Database/Table/Table.placeholders.phpt +++ b/tests/Database/Table/Table.placeholders.phpt @@ -44,7 +44,7 @@ test(function() use ($context, $driverName) { test(function() use ($context) { - $bookTagsCount = array(); + $bookTagsCount = []; $books = $context ->table('book') ->select('book.title, COUNT(DISTINCT :book_tag.tag_id) AS tagsCount') @@ -56,22 +56,22 @@ test(function() use ($context) { $bookTagsCount[$book->title] = $book->tagsCount; } - Assert::same(array( + Assert::same([ 'JUSH' => 1, 'Nette' => 1, - ), $bookTagsCount); + ], $bookTagsCount); }); test(function() use ($context, $driverName) { if ($driverName === 'mysql') { - $authors = array(); - $selection = $context->table('author')->order('FIELD(name, ?)', array('Jakub Vrana', 'David Grudl', 'Geek')); + $authors = []; + $selection = $context->table('author')->order('FIELD(name, ?)', ['Jakub Vrana', 'David Grudl', 'Geek']); foreach ($selection as $author) { $authors[] = $author->name; } - Assert::same(array('Jakub Vrana', 'David Grudl', 'Geek'), $authors); + Assert::same(['Jakub Vrana', 'David Grudl', 'Geek'], $authors); } }); diff --git a/tests/Database/Table/Table.ref().phpt b/tests/Database/Table/Table.ref().phpt index 63135207f..40fe9a3f7 100644 --- a/tests/Database/Table/Table.ref().phpt +++ b/tests/Database/Table/Table.ref().phpt @@ -17,9 +17,9 @@ Assert::same('Jakub Vrana', $context->table('book')->get(1)->ref('author')->name test(function() use ($context) { $book = $context->table('book')->get(1); - $book->update(array( + $book->update([ 'translator_id' => 12, - )); + ]); $book = $context->table('book')->get(1); @@ -41,7 +41,7 @@ test(function() use ($context, $connection) { $table = $context->table('book'); - $names = array(); + $names = []; foreach ($table as $book) { $translator = $book->ref('author', 'translator_id'); } diff --git a/tests/Database/Table/Table.related().caching.phpt b/tests/Database/Table/Table.related().caching.phpt index 4325a8eb3..61e222f43 100644 --- a/tests/Database/Table/Table.related().caching.phpt +++ b/tests/Database/Table/Table.related().caching.phpt @@ -20,25 +20,25 @@ test(function() use ($context) { } } - $tags = array(); + $tags = []; foreach ($books as $book) { foreach ($book->related('book_tag_alt') as $bookTag) { $tags[] = $bookTag->tag->name; } } - Assert::same(array( + Assert::same([ 'PHP', 'MySQL', 'JavaScript', 'Neon', - ), $tags); + ], $tags); }); test(function() use ($context) { $authors = $context->table('author')->where('id', 11); - $books = array(); + $books = []; foreach ($authors as $author) { foreach ($author->related('book')->where('translator_id', NULL) as $book) { foreach ($book->related('book_tag') as $bookTag) { @@ -46,7 +46,7 @@ test(function() use ($context) { } } } - Assert::same(array('JavaScript'), $books); + Assert::same(['JavaScript'], $books); foreach ($authors as $author) { foreach ($author->related('book')->where('NOT translator_id', NULL) as $book) { @@ -55,7 +55,7 @@ test(function() use ($context) { } } } - Assert::same(array('JavaScript', 'PHP', 'MySQL'), $books); + Assert::same(['JavaScript', 'PHP', 'MySQL'], $books); }); @@ -67,16 +67,16 @@ test(function() use ($context) { $book->ref('author', 'translator_id')->name; } - $translators = array(); + $translators = []; foreach ($author->related('book')->limit(2) as $book) { $translators[] = $book->ref('author', 'translator_id')->name; } sort($translators); - Assert::same(array( + Assert::same([ 'David Grudl', 'Jakub Vrana', - ), $translators); + ], $translators); }); @@ -88,12 +88,12 @@ test(function() use ($context) { // cache can't be affected by inner query! if (!isset($secondBookTagRels)) { $bookFromAnotherSelection = $author->related('book')->where('id', $book->id)->fetch(); $bookFromAnotherSelection->related('book_tag')->fetchPairs('id'); - $secondBookTagRels = array(); + $secondBookTagRels = []; } else { foreach ($book->related('book_tag') as $bookTagRel) { $secondBookTagRels[] = $bookTagRel->tag->name; } } } - Assert::same(array('JavaScript'), $secondBookTagRels); + Assert::same(['JavaScript'], $secondBookTagRels); }); diff --git a/tests/Database/Table/Table.related().phpt b/tests/Database/Table/Table.related().phpt index a1823add5..2f5fff30e 100644 --- a/tests/Database/Table/Table.related().phpt +++ b/tests/Database/Table/Table.related().phpt @@ -13,7 +13,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { - $books1 = $books2 = $books3 = array(); + $books1 = $books2 = $books3 = []; foreach ($context->table('author') as $author) { // SELECT * FROM `author` foreach ($author->related('book', 'translator_id') as $book) { // SELECT * FROM `book` WHERE (`book`.`translator_id` IN (11, 12, 13)) @@ -29,18 +29,18 @@ test(function() use ($context) { } } - Assert::same(array( + Assert::same([ '1001 tipu a triku pro PHP' => 'Jakub Vrana', 'Nette' => 'David Grudl', 'Dibi' => 'David Grudl', - ), $books1); + ], $books1); - $expectBooks = array( + $expectBooks = [ '1001 tipu a triku pro PHP' => 'Jakub Vrana', 'JUSH' => 'Jakub Vrana', 'Nette' => 'David Grudl', 'Dibi' => 'David Grudl', - ); + ]; Assert::same($expectBooks, $books2); Assert::same($expectBooks, $books3); @@ -48,7 +48,7 @@ test(function() use ($context) { test(function() use ($context) { - $tagsAuthors = array(); + $tagsAuthors = []; foreach ($context->table('tag') as $tag) { $book_tags = $tag->related('book_tag')->group('book_tag.tag_id, book.author_id, book.author.name')->select('book.author_id')->order('book.author.name'); @@ -58,31 +58,31 @@ test(function() use ($context) { } - Assert::same(array( - 'PHP' => array( + Assert::same([ + 'PHP' => [ 'David Grudl', 'Jakub Vrana', - ), - 'MySQL' => array( + ], + 'MySQL' => [ 'David Grudl', 'Jakub Vrana', - ), - 'JavaScript' => array( + ], + 'JavaScript' => [ 'Jakub Vrana', - ), - ), $tagsAuthors); + ], + ], $tagsAuthors); }); test(function() use ($context) { - $counts1 = $counts2 = array(); + $counts1 = $counts2 = []; foreach($context->table('author')->order('id') as $author) { $counts1[] = $author->related('book.author_id')->count('id'); $counts2[] = $author->related('book.author_id')->where('translator_id', NULL)->count('id'); } - Assert::same(array(2, 2, 0), $counts1); - Assert::same(array(1, 0, 0), $counts2); + Assert::same([2, 2, 0], $counts1); + Assert::same([1, 0, 0], $counts2); }); diff --git a/tests/Database/Table/Table.subquery.phpt b/tests/Database/Table/Table.subquery.phpt index e927f40ba..c41e55892 100644 --- a/tests/Database/Table/Table.subquery.phpt +++ b/tests/Database/Table/Table.subquery.phpt @@ -13,16 +13,16 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN test(function() use ($context) { - $apps = array(); + $apps = []; $unknownBorn = $context->table('author')->where('born', null); // authors with unknown date of born foreach ($context->table('book')->where('author_id', $unknownBorn) as $book) { // their books: SELECT `id` FROM `author` WHERE (`born` IS NULL), SELECT * FROM `book` WHERE (`author_id` IN (11, 12)) $apps[] = $book->title; } - Assert::same(array( + Assert::same([ '1001 tipu a triku pro PHP', 'JUSH', 'Nette', 'Dibi', - ), $apps); + ], $apps); }); diff --git a/tests/Database/Table/Table.update().phpt b/tests/Database/Table/Table.update().phpt index f505bd26a..eb7e8c40d 100644 --- a/tests/Database/Table/Table.update().phpt +++ b/tests/Database/Table/Table.update().phpt @@ -13,9 +13,9 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN $author = $context->table('author')->get(12); // SELECT * FROM `author` WHERE (`id` = ?) -$author->update(array( +$author->update([ 'name' => 'Tyrion Lannister', -)); // UPDATE `author` SET `name`='Tyrion Lannister' WHERE (`id` = 12) +]); // UPDATE `author` SET `name`='Tyrion Lannister' WHERE (`id` = 12) $book = $context->table('book'); @@ -23,46 +23,46 @@ $book1 = $book->get(1); // SELECT * FROM `book` WHERE (`id` = ?) Assert::same('Jakub Vrana', $book1->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (11)) -$book2 = $book->insert(array( +$book2 = $book->insert([ 'author_id' => $author->getPrimary(), 'title' => 'Game of Thrones', -)); // INSERT INTO `book` (`author_id`, `title`) VALUES (12, 'Game of Thrones') +]); // INSERT INTO `book` (`author_id`, `title`) VALUES (12, 'Game of Thrones') Assert::same('Tyrion Lannister', $book2->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (12)) -$book2->update(array( +$book2->update([ 'author_id' => $context->table('author')->get(12), // SELECT * FROM `author` WHERE (`id` = ?) -)); // UPDATE `book` SET `author_id`=11 WHERE (`id` = '5') +]); // UPDATE `book` SET `author_id`=11 WHERE (`id` = '5') Assert::same('Tyrion Lannister', $book2->author->name); // NO SQL, SHOULD BE CACHED -$book2->update(array( +$book2->update([ 'author_id' => $context->table('author')->get(11), // SELECT * FROM `author` WHERE (`id` = ?) -)); // UPDATE `book` SET `author_id`=11 WHERE (`id` = '5') +]); // UPDATE `book` SET `author_id`=11 WHERE (`id` = '5') Assert::same('Jakub Vrana', $book2->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (11)) -$book2->update(array( +$book2->update([ 'author_id' => new Nette\Database\SqlLiteral('10 + 3'), -)); // UPDATE `book` SET `author_id`=13 WHERE (`id` = '5') +]); // UPDATE `book` SET `author_id`=13 WHERE (`id` = '5') Assert::same('Geek', $book2->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (13)) Assert::same(13, $book2->author_id); -$tag = $context->table('tag')->insert(array( +$tag = $context->table('tag')->insert([ 'name' => 'PC Game', -)); // INSERT INTO `tag` (`name`) VALUES ('PC Game') +]); // INSERT INTO `tag` (`name`) VALUES ('PC Game') -$tag->update(array( +$tag->update([ 'name' => 'Xbox Game', -)); // UPDATE `tag` SET `name`='Xbox Game' WHERE (`id` = '24') +]); // UPDATE `tag` SET `name`='Xbox Game' WHERE (`id` = '24') -$bookTag = $book2->related('book_tag')->insert(array( +$bookTag = $book2->related('book_tag')->insert([ 'tag_id' => $tag, -)); // INSERT INTO `book_tag` (`tag_id`, `book_id`) VALUES (24, '5') +]); // INSERT INTO `book_tag` (`tag_id`, `book_id`) VALUES (24, '5') $app = $context->table('book')->get(5); // SELECT * FROM `book` WHERE (`id` = ?) @@ -70,21 +70,21 @@ $tags = iterator_to_array($app->related('book_tag')); // SELECT * FROM `book_ta Assert::same('Xbox Game', reset($tags)->tag->name); // SELECT * FROM `tag` WHERE (`tag`.`id` IN (24)) -$tag2 = $context->table('tag')->insert(array( +$tag2 = $context->table('tag')->insert([ 'name' => 'PS4 Game', -)); // INSERT INTO `tag` (`name`) VALUES ('PS4 Game') +]); // INSERT INTO `tag` (`name`) VALUES ('PS4 Game') -$tag2->update(array( +$tag2->update([ 'id' => 1, -)); // UPDATE `tag` SET `id`=1 WHERE (`id` = (?)) +]); // UPDATE `tag` SET `id`=1 WHERE (`id` = (?)) Assert::same(1, $tag2->id); -$book_tag = $context->table('book_tag')->get(array( +$book_tag = $context->table('book_tag')->get([ 'book_id' => 5, 'tag_id' => 25, -)); // SELECT * FROM `book_tag` WHERE (`book_id` = (?) AND `tag_id` = (?)) -$book_tag->update(new ArrayIterator(array( +]); // SELECT * FROM `book_tag` WHERE (`book_id` = (?) AND `tag_id` = (?)) +$book_tag->update(new ArrayIterator([ 'tag_id' => 21, -))); // UPDATE `book_tag` SET `tag_id`=21 WHERE (`book_id` = (?) AND `tag_id` = (?)) +])); // UPDATE `book_tag` SET `tag_id`=21 WHERE (`book_id` = (?) AND `tag_id` = (?)) Assert::same(21, $book_tag->tag_id); diff --git a/tests/Database/Table/bugs/bug10.postgre.phpt b/tests/Database/Table/bugs/bug10.postgre.phpt index 144485c0d..199feecfb 100644 --- a/tests/Database/Table/bugs/bug10.postgre.phpt +++ b/tests/Database/Table/bugs/bug10.postgre.phpt @@ -18,8 +18,8 @@ $context->query(' ) '); -$result = $context->table("Bug10")->insert(array( +$result = $context->table("Bug10")->insert([ 'D1' => 123 -)); +]); Tester\Assert::notEqual(null, $result); diff --git a/tests/Database/Table/bugs/bug1342.postgre.phpt b/tests/Database/Table/bugs/bug1342.postgre.phpt index 198bef45f..dcf7a5a21 100644 --- a/tests/Database/Table/bugs/bug1342.postgre.phpt +++ b/tests/Database/Table/bugs/bug1342.postgre.phpt @@ -20,9 +20,9 @@ $context->query(' '); -$insertedRows = $context->table('bug1342')->insert(array( +$insertedRows = $context->table('bug1342')->insert([ 'a1' => 1, 'a2' => 2, -)); +]); Assert::same(1, $insertedRows); diff --git a/tests/Database/connect.inc.php b/tests/Database/connect.inc.php index 15021b6d9..2215384cb 100644 --- a/tests/Database/connect.inc.php +++ b/tests/Database/connect.inc.php @@ -11,7 +11,7 @@ try { - $options = Tester\Environment::loadData() + array('user' => NULL, 'password' => NULL); + $options = Tester\Environment::loadData() + ['user' => NULL, 'password' => NULL]; } catch (Exception $e) { Tester\Environment::skip($e->getMessage()); }