From b6646f1671e84e370b523a837de1ce666a38a51d Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Thu, 14 Sep 2023 23:07:31 -0500 Subject: [PATCH] Upgrade to cakephp-cs 5 and add type declarations --- .github/workflows/ci.yml | 3 + composer.json | 2 +- phpcs.xml | 8 +- phpstan-baseline.neon | 10 - src/Phinx/Config/Config.php | 16 +- src/Phinx/Config/ConfigInterface.php | 9 +- src/Phinx/Config/FeatureFlags.php | 4 +- src/Phinx/Config/NamespaceAwareInterface.php | 3 - src/Phinx/Config/NamespaceAwareTrait.php | 3 - src/Phinx/Console/Command/AbstractCommand.php | 15 +- src/Phinx/Console/Command/Breakpoint.php | 2 + src/Phinx/Console/Command/Create.php | 2 + src/Phinx/Console/Command/Init.php | 4 +- src/Phinx/Console/Command/ListAliases.php | 2 + src/Phinx/Console/Command/Migrate.php | 2 + src/Phinx/Console/Command/Rollback.php | 2 + src/Phinx/Console/Command/SeedCreate.php | 2 + src/Phinx/Console/Command/SeedRun.php | 2 + src/Phinx/Console/Command/Status.php | 2 + src/Phinx/Console/Command/Test.php | 2 + src/Phinx/Console/PhinxApplication.php | 3 +- src/Phinx/Db/Action/Action.php | 3 +- src/Phinx/Db/Action/AddColumn.php | 6 +- src/Phinx/Db/Action/AddForeignKey.php | 5 +- src/Phinx/Db/Action/AddIndex.php | 5 +- src/Phinx/Db/Action/ChangeColumn.php | 8 +- src/Phinx/Db/Action/ChangeComment.php | 3 +- src/Phinx/Db/Action/ChangePrimaryKey.php | 7 +- src/Phinx/Db/Action/CreateTable.php | 1 + src/Phinx/Db/Action/DropForeignKey.php | 5 +- src/Phinx/Db/Action/DropIndex.php | 7 +- src/Phinx/Db/Action/DropTable.php | 1 + src/Phinx/Db/Action/RemoveColumn.php | 5 +- src/Phinx/Db/Action/RenameColumn.php | 7 +- src/Phinx/Db/Action/RenameTable.php | 3 +- src/Phinx/Db/Adapter/AbstractAdapter.php | 23 +- src/Phinx/Db/Adapter/AdapterFactory.php | 23 +- src/Phinx/Db/Adapter/AdapterInterface.php | 19 +- src/Phinx/Db/Adapter/AdapterWrapper.php | 21 +- .../Db/Adapter/DirectActionInterface.php | 5 +- src/Phinx/Db/Adapter/MysqlAdapter.php | 21 +- src/Phinx/Db/Adapter/PdoAdapter.php | 32 +- src/Phinx/Db/Adapter/PostgresAdapter.php | 18 +- src/Phinx/Db/Adapter/ProxyAdapter.php | 5 +- src/Phinx/Db/Adapter/SQLiteAdapter.php | 44 +-- src/Phinx/Db/Adapter/SqlServerAdapter.php | 31 +- src/Phinx/Db/Adapter/TablePrefixAdapter.php | 5 +- src/Phinx/Db/Adapter/TimedOutputAdapter.php | 3 +- .../UnsupportedColumnTypeException.php | 3 +- src/Phinx/Db/Adapter/WrapperInterface.php | 3 +- src/Phinx/Db/Plan/AlterTable.php | 5 +- src/Phinx/Db/Plan/Intent.php | 3 +- src/Phinx/Db/Plan/NewTable.php | 7 +- src/Phinx/Db/Plan/Plan.php | 13 +- src/Phinx/Db/Plan/Solver/ActionSplitter.php | 5 +- src/Phinx/Db/Table.php | 42 +-- src/Phinx/Db/Table/Column.php | 52 +-- src/Phinx/Db/Table/ForeignKey.php | 17 +- src/Phinx/Db/Table/Index.php | 19 +- src/Phinx/Db/Table/Table.php | 7 +- src/Phinx/Db/Util/AlterInstructions.php | 7 +- src/Phinx/Migration/AbstractMigration.php | 21 +- .../Migration/AbstractTemplateCreation.php | 5 +- src/Phinx/Migration/CreationInterface.php | 3 +- .../IrreversibleMigrationException.php | 3 +- src/Phinx/Migration/Manager.php | 21 +- src/Phinx/Migration/Manager/Environment.php | 17 +- src/Phinx/Migration/MigrationInterface.php | 7 +- src/Phinx/Seed/AbstractSeed.php | 17 +- src/Phinx/Seed/SeedInterface.php | 12 +- src/Phinx/Util/Expression.php | 3 +- src/Phinx/Util/Literal.php | 3 +- src/Phinx/Util/Util.php | 5 +- src/Phinx/Wrapper/TextWrapper.php | 15 +- src/composer_autoloader.php | 1 + tests/Phinx/Config/ConfigPhpTest.php | 6 +- tests/Phinx/Config/ConfigTest.php | 38 +- .../Phinx/Console/Command/BreakpointTest.php | 1 + tests/Phinx/Console/Command/CreateTest.php | 1 + tests/Phinx/Console/Command/InitTest.php | 1 + .../Phinx/Console/Command/ListAliasesTest.php | 1 + tests/Phinx/Console/Command/ListTest.php | 1 + tests/Phinx/Console/Command/MigrateTest.php | 3 +- tests/Phinx/Console/Command/RollbackTest.php | 11 +- .../Phinx/Console/Command/SeedCreateTest.php | 16 +- tests/Phinx/Console/Command/SeedRunTest.php | 1 + tests/Phinx/Console/Command/StatusTest.php | 9 +- .../DoesNotImplementRequiredInterface.php | 1 + .../TemplateGenerators/NullGenerator.php | 1 + .../TemplateGenerators/SimpleGenerator.php | 1 + .../Console/Output/RawBufferedOutput.php | 5 +- tests/Phinx/Console/PhinxApplicationTest.php | 1 + tests/Phinx/Db/Adapter/AdapterFactoryTest.php | 6 +- tests/Phinx/Db/Adapter/DataDomainTest.php | 1 + tests/Phinx/Db/Adapter/MysqlAdapterTest.php | 324 +++++++++--------- tests/Phinx/Db/Adapter/PdoAdapterTest.php | 8 +- .../Phinx/Db/Adapter/PostgresAdapterTest.php | 281 +++++++-------- tests/Phinx/Db/Adapter/ProxyAdapterTest.php | 16 +- tests/Phinx/Db/Adapter/SQLiteAdapterTest.php | 284 +++++++-------- .../Phinx/Db/Adapter/SqlServerAdapterTest.php | 163 ++++----- .../Db/Adapter/TablePrefixAdapterTest.php | 28 +- tests/Phinx/Db/Table/ColumnTest.php | 1 + tests/Phinx/Db/Table/ForeignKeyTest.php | 1 + tests/Phinx/Db/Table/IndexTest.php | 1 + tests/Phinx/Db/TableTest.php | 68 ++-- .../Phinx/Migration/AbstractMigrationTest.php | 4 +- .../Migration/Manager/EnvironmentTest.php | 13 +- tests/Phinx/Migration/ManagerTest.php | 106 +++--- tests/Phinx/TestCase.php | 1 - tests/Phinx/TestUtils.php | 8 +- tests/Phinx/Util/ExpressionTest.php | 2 +- tests/Phinx/Util/LiteralTest.php | 2 +- tests/Phinx/Util/UtilTest.php | 5 +- tests/Phinx/Wrapper/TextWrapperTest.php | 1 - tests/phpunit-bootstrap.php | 1 - 115 files changed, 1129 insertions(+), 1024 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4cdc040f..104529d42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,9 @@ jobs: db-type: [sqlite, mysql, pgsql] prefer-lowest: [''] include: + - php-version: '8.3' + db-type: sqlite + prefer-lowest: '' - php-version: '8.1' db-type: sqlite prefer-lowest: prefer-lowest diff --git a/composer.json b/composer.json index ae6a0f63b..7d3c1386f 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "phpunit/phpunit": "^9.5.19", "sebastian/comparator": ">=1.2.3", "cakephp/cakephp": "^5.0", - "cakephp/cakephp-codesniffer": "^4.0", + "cakephp/cakephp-codesniffer": "^5.0", "symfony/yaml": "^3.4|^4.0|^5.0|^6.0" }, "autoload": { diff --git a/phpcs.xml b/phpcs.xml index 7bdb4f504..9ef5ab011 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -2,16 +2,12 @@ + + src/ tests/ *_files* - - - - - 0 - diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 03587fb2e..97e75659b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15,13 +15,3 @@ parameters: count: 2 path: src/Phinx/Db/Adapter/SqlServerAdapter.php - - - message: "#^Property Phinx\\\\Migration\\\\Manager\\\\Environment\\:\\:\\$adapter \\(Phinx\\\\Db\\\\Adapter\\\\AdapterInterface\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: src/Phinx/Migration/Manager/Environment.php - - - - message: "#^Unreachable statement \\- code above always terminates\\.$#" - count: 1 - path: src/Phinx/Migration/Manager/Environment.php - diff --git a/src/Phinx/Config/Config.php b/src/Phinx/Config/Config.php index 91cfbd499..85186ff9a 100644 --- a/src/Phinx/Config/Config.php +++ b/src/Phinx/Config/Config.php @@ -12,15 +12,13 @@ use Phinx\Db\Adapter\SQLiteAdapter; use Phinx\Util\Util; use Psr\Container\ContainerInterface; +use ReturnTypeWillChange; use RuntimeException; use Symfony\Component\Yaml\Yaml; use UnexpectedValueException; /** * Phinx configuration class. - * - * @package Phinx - * @author Rob Morgan */ class Config implements ConfigInterface, NamespaceAwareInterface { @@ -42,12 +40,12 @@ class Config implements ConfigInterface, NamespaceAwareInterface /** * @var array */ - protected $values = []; + protected array $values = []; /** * @var string|null */ - protected $configFilePath; + protected ?string $configFilePath = null; /** * @param array $configArray Config array @@ -328,7 +326,7 @@ public function getSeedBaseClassName(bool $dropNamespace = true): string /** * @inheritdoc */ - public function getTemplateFile() + public function getTemplateFile(): string|false { if (!isset($this->values['templates']['file'])) { return false; @@ -340,7 +338,7 @@ public function getTemplateFile() /** * @inheritdoc */ - public function getTemplateClass() + public function getTemplateClass(): string|false { if (!isset($this->values['templates']['class'])) { return false; @@ -410,7 +408,7 @@ public function isVersionOrderCreationTime(): bool /** * @inheritdoc */ - public function getBootstrapFile() + public function getBootstrapFile(): string|false { if (!isset($this->values['paths']['bootstrap'])) { return false; @@ -511,7 +509,7 @@ public function offsetSet($id, $value): void * @throws \InvalidArgumentException * @return mixed */ - #[\ReturnTypeWillChange] + #[ReturnTypeWillChange] public function offsetGet($id) { if (!array_key_exists($id, $this->values)) { diff --git a/src/Phinx/Config/ConfigInterface.php b/src/Phinx/Config/ConfigInterface.php index 3bd57f213..81382a2b9 100644 --- a/src/Phinx/Config/ConfigInterface.php +++ b/src/Phinx/Config/ConfigInterface.php @@ -12,9 +12,6 @@ /** * Phinx configuration interface. - * - * @package Phinx - * @author Woody Gilk */ interface ConfigInterface extends ArrayAccess { @@ -95,14 +92,14 @@ public function getSeedPaths(): array; * * @return string|false */ - public function getTemplateFile(); + public function getTemplateFile(): string|false; /** * Get the template class name. * * @return string|false */ - public function getTemplateClass(); + public function getTemplateClass(): string|false; /** * Get the template style to use, either change or up_down. @@ -144,7 +141,7 @@ public function isVersionOrderCreationTime(): bool; * * @return string|false */ - public function getBootstrapFile(); + public function getBootstrapFile(): string|false; /** * Gets the base class name for migrations. diff --git a/src/Phinx/Config/FeatureFlags.php b/src/Phinx/Config/FeatureFlags.php index dded535b8..a9c272b17 100644 --- a/src/Phinx/Config/FeatureFlags.php +++ b/src/Phinx/Config/FeatureFlags.php @@ -17,11 +17,11 @@ class FeatureFlags /** * @var bool Should Phinx create unsigned primary keys by default? */ - public static $unsignedPrimaryKeys = true; + public static bool $unsignedPrimaryKeys = true; /** * @var bool Should Phinx create columns NULL by default? */ - public static $columnNullDefault = true; + public static bool $columnNullDefault = true; /** * Set the feature flags from the `feature_flags` section of the overall diff --git a/src/Phinx/Config/NamespaceAwareInterface.php b/src/Phinx/Config/NamespaceAwareInterface.php index 2acab3dc2..d441d7785 100644 --- a/src/Phinx/Config/NamespaceAwareInterface.php +++ b/src/Phinx/Config/NamespaceAwareInterface.php @@ -9,9 +9,6 @@ /** * Config aware getNamespaceByPath method. - * - * @package Phinx\Config - * @author Andrey N. Mokhov */ interface NamespaceAwareInterface { diff --git a/src/Phinx/Config/NamespaceAwareTrait.php b/src/Phinx/Config/NamespaceAwareTrait.php index 8426070ea..28de366b3 100644 --- a/src/Phinx/Config/NamespaceAwareTrait.php +++ b/src/Phinx/Config/NamespaceAwareTrait.php @@ -9,9 +9,6 @@ /** * Trait implemented NamespaceAwareInterface. - * - * @package Phinx\Config - * @author Andrey N. Mokhov */ trait NamespaceAwareTrait { diff --git a/src/Phinx/Console/Command/AbstractCommand.php b/src/Phinx/Console/Command/AbstractCommand.php index c9490d62b..41a15f77a 100644 --- a/src/Phinx/Console/Command/AbstractCommand.php +++ b/src/Phinx/Console/Command/AbstractCommand.php @@ -1,4 +1,5 @@ */ abstract class AbstractCommand extends Command { @@ -52,22 +51,22 @@ abstract class AbstractCommand extends Command /** * @var \Phinx\Config\ConfigInterface|null */ - protected $config; + protected ?ConfigInterface $config = null; /** * @var \Phinx\Db\Adapter\AdapterInterface */ - protected $adapter; + protected AdapterInterface $adapter; /** * @var \Phinx\Migration\Manager */ - protected $manager; + protected Manager $manager; /** * @var int */ - protected $verbosityLevel = OutputInterface::OUTPUT_NORMAL | OutputInterface::VERBOSITY_NORMAL; + protected int $verbosityLevel = OutputInterface::OUTPUT_NORMAL | OutputInterface::VERBOSITY_NORMAL; /** * Exit code for when command executes successfully @@ -235,7 +234,7 @@ public function setManager(Manager $manager) */ public function getManager(): ?Manager { - return $this->manager; + return $this->manager ?? null; } /** @@ -342,7 +341,7 @@ protected function loadConfig(InputInterface $input, OutputInterface $output): v */ protected function loadManager(InputInterface $input, OutputInterface $output): void { - if ($this->getManager() === null) { + if (!isset($this->manager)) { $manager = new Manager($this->getConfig(), $input, $output); $manager->setVerbosityLevel($this->verbosityLevel); $container = $this->getConfig()->getContainer(); diff --git a/src/Phinx/Console/Command/Breakpoint.php b/src/Phinx/Console/Command/Breakpoint.php index f94d597a0..aec3862d4 100644 --- a/src/Phinx/Console/Command/Breakpoint.php +++ b/src/Phinx/Console/Command/Breakpoint.php @@ -1,4 +1,5 @@ */ class PhinxApplication extends Application { diff --git a/src/Phinx/Db/Action/Action.php b/src/Phinx/Db/Action/Action.php index 90c3ae42b..f8263c48d 100644 --- a/src/Phinx/Db/Action/Action.php +++ b/src/Phinx/Db/Action/Action.php @@ -1,4 +1,5 @@ $options The column options * @return static */ - public static function build(Table $table, string $columnName, $type = null, array $options = []) + public static function build(Table $table, string $columnName, string|Literal $type, array $options = []): static { $column = new Column(); $column->setName($columnName); diff --git a/src/Phinx/Db/Action/AddForeignKey.php b/src/Phinx/Db/Action/AddForeignKey.php index 9121cfe44..1468539cd 100644 --- a/src/Phinx/Db/Action/AddForeignKey.php +++ b/src/Phinx/Db/Action/AddForeignKey.php @@ -1,4 +1,5 @@ $options Additional options for the index creation * @return static */ - public static function build(Table $table, $columns, array $options = []) + public static function build(Table $table, string|array|Index $columns, array $options = []): static { // create a new index object if strings or an array of strings were supplied $index = $columns; diff --git a/src/Phinx/Db/Action/ChangeColumn.php b/src/Phinx/Db/Action/ChangeColumn.php index 143baf931..9bcff7cf6 100644 --- a/src/Phinx/Db/Action/ChangeColumn.php +++ b/src/Phinx/Db/Action/ChangeColumn.php @@ -1,4 +1,5 @@ $options Additional options for the column * @return static */ - public static function build(Table $table, string $columnName, $type = null, array $options = []) + public static function build(Table $table, string $columnName, string|Column|Literal $type, array $options = []): static { $column = new Column(); $column->setName($columnName); diff --git a/src/Phinx/Db/Action/ChangeComment.php b/src/Phinx/Db/Action/ChangeComment.php index 56045306b..7718519b7 100644 --- a/src/Phinx/Db/Action/ChangeComment.php +++ b/src/Phinx/Db/Action/ChangeComment.php @@ -1,4 +1,5 @@ newColumns = $newColumns; @@ -35,7 +36,7 @@ public function __construct(Table $table, $newColumns) * * @return string|string[]|null */ - public function getNewColumns() + public function getNewColumns(): string|array|null { return $this->newColumns; } diff --git a/src/Phinx/Db/Action/CreateTable.php b/src/Phinx/Db/Action/CreateTable.php index 8f50afa5b..a9a593bbd 100644 --- a/src/Phinx/Db/Action/CreateTable.php +++ b/src/Phinx/Db/Action/CreateTable.php @@ -1,4 +1,5 @@ setColumns($columns); @@ -55,7 +56,7 @@ public static function build(Table $table, array $columns = []) * @param string $name The name of the index * @return static */ - public static function buildFromName(Table $table, string $name) + public static function buildFromName(Table $table, string $name): static { $index = new Index(); $index->setName($name); diff --git a/src/Phinx/Db/Action/DropTable.php b/src/Phinx/Db/Action/DropTable.php index 6343d0bfb..318664971 100644 --- a/src/Phinx/Db/Action/DropTable.php +++ b/src/Phinx/Db/Action/DropTable.php @@ -1,4 +1,5 @@ setName($columnName); diff --git a/src/Phinx/Db/Action/RenameColumn.php b/src/Phinx/Db/Action/RenameColumn.php index 0f1839527..3bf4ed52f 100644 --- a/src/Phinx/Db/Action/RenameColumn.php +++ b/src/Phinx/Db/Action/RenameColumn.php @@ -1,4 +1,5 @@ setName($columnName); diff --git a/src/Phinx/Db/Action/RenameTable.php b/src/Phinx/Db/Action/RenameTable.php index dd9652d95..25c4718e3 100644 --- a/src/Phinx/Db/Action/RenameTable.php +++ b/src/Phinx/Db/Action/RenameTable.php @@ -1,4 +1,5 @@ */ - protected $options = []; + protected array $options = []; /** * @var \Symfony\Component\Console\Input\InputInterface|null */ - protected $input; + protected ?InputInterface $input = null; /** * @var \Symfony\Component\Console\Output\OutputInterface */ - protected $output; + protected OutputInterface $output; /** * @var string[] */ - protected $createdTables = []; + protected array $createdTables = []; /** * @var string */ - protected $schemaTableName = 'phinxlog'; + protected string $schemaTableName = 'phinxlog'; /** * @var array */ - protected $dataDomain = []; + protected array $dataDomain = []; /** * Class Constructor. @@ -113,7 +114,7 @@ public function hasOption(string $name): bool /** * @inheritDoc */ - public function getOption(string $name) + public function getOption(string $name): mixed { if (!$this->hasOption($name)) { return null; @@ -155,7 +156,7 @@ public function setOutput(OutputInterface $output): AdapterInterface */ public function getOutput(): OutputInterface { - if ($this->output === null) { + if (!isset($this->output)) { $output = new NullOutput(); $this->setOutput($output); } @@ -222,7 +223,7 @@ public function setDataDomain(array $dataDomain) // and it is compatible with the base Phinx types. foreach ($dataDomain as $type => $options) { if (!isset($options['type'])) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'You must specify a type for data domain type "%s".', $type )); @@ -234,7 +235,7 @@ public function setDataDomain(array $dataDomain) } if (!in_array($options['type'], $this->getColumnTypes(), true)) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'An invalid column type "%s" was specified for data domain type "%s".', $options['type'], $type @@ -253,7 +254,7 @@ public function setDataDomain(array $dataDomain) if (isset($options['limit']) && !is_numeric($options['limit'])) { if (!defined('static::' . $options['limit'])) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'An invalid limit value "%s" was specified for data domain type "%s".', $options['limit'], $type diff --git a/src/Phinx/Db/Adapter/AdapterFactory.php b/src/Phinx/Db/Adapter/AdapterFactory.php index 384369144..d5a3f2fd5 100644 --- a/src/Phinx/Db/Adapter/AdapterFactory.php +++ b/src/Phinx/Db/Adapter/AdapterFactory.php @@ -1,4 +1,5 @@ */ class AdapterFactory { /** - * @var \Phinx\Db\Adapter\AdapterFactory|null + * @var static|null */ - protected static $instance; + protected static ?AdapterFactory $instance = null; /** * Get the factory singleton instance. * - * @return \Phinx\Db\Adapter\AdapterFactory + * @return static */ - public static function instance() + public static function instance(): static { if (!static::$instance) { static::$instance = new static(); @@ -43,7 +42,7 @@ public static function instance() * @var array * @phpstan-var array> */ - protected $adapters = [ + protected array $adapters = [ 'mysql' => 'Phinx\Db\Adapter\MysqlAdapter', 'pgsql' => 'Phinx\Db\Adapter\PostgresAdapter', 'sqlite' => 'Phinx\Db\Adapter\SQLiteAdapter', @@ -55,7 +54,7 @@ public static function instance() * * @var array */ - protected $wrappers = [ + protected array $wrappers = [ 'prefix' => 'Phinx\Db\Adapter\TablePrefixAdapter', 'proxy' => 'Phinx\Db\Adapter\ProxyAdapter', 'timed' => 'Phinx\Db\Adapter\TimedOutputAdapter', @@ -69,7 +68,7 @@ public static function instance() * @throws \RuntimeException * @return $this */ - public function registerAdapter(string $name, $class) + public function registerAdapter(string $name, object|string $class) { if (!is_subclass_of($class, 'Phinx\Db\Adapter\AdapterInterface')) { throw new RuntimeException(sprintf( @@ -90,7 +89,7 @@ public function registerAdapter(string $name, $class) * @return object|string * @phpstan-return object|class-string<\Phinx\Db\Adapter\AdapterInterface> */ - protected function getClass(string $name) + protected function getClass(string $name): object|string { if (empty($this->adapters[$name])) { throw new RuntimeException(sprintf( @@ -124,7 +123,7 @@ public function getAdapter(string $name, array $options): AdapterInterface * @throws \RuntimeException * @return $this */ - public function registerWrapper(string $name, $class) + public function registerWrapper(string $name, object|string $class) { if (!is_subclass_of($class, 'Phinx\Db\Adapter\WrapperInterface')) { throw new RuntimeException(sprintf( @@ -144,7 +143,7 @@ public function registerWrapper(string $name, $class) * @throws \RuntimeException * @return \Phinx\Db\Adapter\WrapperInterface|string */ - protected function getWrapperClass(string $name) + protected function getWrapperClass(string $name): WrapperInterface|string { if (empty($this->wrappers[$name])) { throw new RuntimeException(sprintf( diff --git a/src/Phinx/Db/Adapter/AdapterInterface.php b/src/Phinx/Db/Adapter/AdapterInterface.php index bf4a86590..a42da2a02 100644 --- a/src/Phinx/Db/Adapter/AdapterInterface.php +++ b/src/Phinx/Db/Adapter/AdapterInterface.php @@ -1,4 +1,5 @@ * @method \PDO getConnection() */ interface AdapterInterface @@ -120,7 +121,7 @@ public function hasOption(string $name): bool; * @param string $name Name * @return mixed */ - public function getOption(string $name); + public function getOption(string $name): mixed; /** * Sets the console input. @@ -295,7 +296,7 @@ public function getQueryBuilder(string $type): Query; * @param array $params parameters to use for prepared query * @return mixed */ - public function query(string $sql, array $params = []); + public function query(string $sql, array $params = []): mixed; /** * Executes a query and returns only one row as an array. @@ -303,7 +304,7 @@ public function query(string $sql, array $params = []); * @param string $sql SQL * @return array|false */ - public function fetchRow(string $sql); + public function fetchRow(string $sql): array|false; /** * Executes a query and returns an array of rows. @@ -397,7 +398,7 @@ public function hasColumn(string $tableName, string $columnName): bool; * @param string|string[] $columns Column(s) * @return bool */ - public function hasIndex(string $tableName, $columns): bool; + public function hasIndex(string $tableName, string|array $columns): bool; /** * Checks to see if an index specified by name exists. @@ -416,7 +417,7 @@ public function hasIndexByName(string $tableName, string $indexName): bool; * @param string|null $constraint Constraint name * @return bool */ - public function hasPrimaryKey(string $tableName, $columns, ?string $constraint = null): bool; + public function hasPrimaryKey(string $tableName, string|array $columns, ?string $constraint = null): bool; /** * Checks to see if a foreign key exists. @@ -426,7 +427,7 @@ public function hasPrimaryKey(string $tableName, $columns, ?string $constraint = * @param string|null $constraint Constraint name * @return bool */ - public function hasForeignKey(string $tableName, $columns, ?string $constraint = null): bool; + public function hasForeignKey(string $tableName, string|array $columns, ?string $constraint = null): bool; /** * Returns an array of the supported Phinx column types. @@ -450,7 +451,7 @@ public function isValidColumnType(Column $column): bool; * @param int|null $limit Limit * @return array */ - public function getSqlType($type, ?int $limit = null): array; + public function getSqlType(Literal|string $type, ?int $limit = null): array; /** * Creates a new database. @@ -501,5 +502,5 @@ public function dropSchema(string $schemaName): void; * @param mixed $value The value to be cast * @return mixed */ - public function castToBool($value); + public function castToBool(mixed $value): mixed; } diff --git a/src/Phinx/Db/Adapter/AdapterWrapper.php b/src/Phinx/Db/Adapter/AdapterWrapper.php index 6300c6305..3d4909335 100644 --- a/src/Phinx/Db/Adapter/AdapterWrapper.php +++ b/src/Phinx/Db/Adapter/AdapterWrapper.php @@ -1,4 +1,5 @@ */ abstract class AdapterWrapper implements AdapterInterface, WrapperInterface { /** * @var \Phinx\Db\Adapter\AdapterInterface */ - protected $adapter; + protected AdapterInterface $adapter; /** * @inheritDoc @@ -84,7 +85,7 @@ public function hasOption(string $name): bool /** * @inheritDoc */ - public function getOption(string $name) + public function getOption(string $name): mixed { return $this->adapter->getOption($name); } @@ -160,7 +161,7 @@ public function execute(string $sql, array $params = []): int /** * @inheritDoc */ - public function query(string $sql, array $params = []) + public function query(string $sql, array $params = []): mixed { return $this->getAdapter()->query($sql, $params); } @@ -184,7 +185,7 @@ public function bulkinsert(Table $table, array $rows): void /** * @inheritDoc */ - public function fetchRow(string $sql) + public function fetchRow(string $sql): array|false { return $this->getAdapter()->fetchRow($sql); } @@ -368,7 +369,7 @@ public function hasColumn(string $tableName, string $columnName): bool /** * @inheritDoc */ - public function hasIndex(string $tableName, $columns): bool + public function hasIndex(string $tableName, string|array $columns): bool { return $this->getAdapter()->hasIndex($tableName, $columns); } @@ -400,7 +401,7 @@ public function hasForeignKey(string $tableName, $columns, ?string $constraint = /** * @inheritDoc */ - public function getSqlType($type, ?int $limit = null): array + public function getSqlType(Literal|string $type, ?int $limit = null): array { return $this->getAdapter()->getSqlType($type, $limit); } @@ -456,7 +457,7 @@ public function truncateTable(string $tableName): void /** * @inheritDoc */ - public function castToBool($value) + public function castToBool($value): mixed { return $this->getAdapter()->castToBool($value); } @@ -464,7 +465,7 @@ public function castToBool($value) /** * @return \PDO */ - public function getConnection() + public function getConnection(): PDO { return $this->getAdapter()->getConnection(); } diff --git a/src/Phinx/Db/Adapter/DirectActionInterface.php b/src/Phinx/Db/Adapter/DirectActionInterface.php index 64b30f68a..81985c1a5 100644 --- a/src/Phinx/Db/Adapter/DirectActionInterface.php +++ b/src/Phinx/Db/Adapter/DirectActionInterface.php @@ -1,4 +1,5 @@ */ class MysqlAdapter extends PdoAdapter { /** * @var string[] */ - protected static $specificColumnTypes = [ + protected static array $specificColumnTypes = [ self::PHINX_TYPE_ENUM, self::PHINX_TYPE_SET, self::PHINX_TYPE_YEAR, @@ -45,7 +45,7 @@ class MysqlAdapter extends PdoAdapter /** * @var bool[] */ - protected $signedColumnTypes = [ + protected array $signedColumnTypes = [ self::PHINX_TYPE_INTEGER => true, self::PHINX_TYPE_TINY_INTEGER => true, self::PHINX_TYPE_SMALL_INTEGER => true, @@ -149,7 +149,7 @@ public function connect(): void if (strpos($key, 'mysql_attr_') === 0) { $pdoConstant = '\PDO::' . strtoupper($key); if (!defined($pdoConstant)) { - throw new \UnexpectedValueException('Invalid PDO attribute: ' . $key . ' (' . $pdoConstant . ')'); + throw new UnexpectedValueException('Invalid PDO attribute: ' . $key . ' (' . $pdoConstant . ')'); } $driverOptions[constant($pdoConstant)] = $option; } @@ -637,7 +637,7 @@ protected function getIndexes(string $tableName): array /** * @inheritDoc */ - public function hasIndex(string $tableName, $columns): bool + public function hasIndex(string $tableName, string|array $columns): bool { if (is_string($columns)) { $columns = [$columns]; // str to array @@ -943,8 +943,9 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr * * @throws \Phinx\Db\Adapter\UnsupportedColumnTypeException */ - public function getSqlType($type, ?int $limit = null): array + public function getSqlType(Literal|string $type, ?int $limit = null): array { + $type = (string)$type; switch ($type) { case static::PHINX_TYPE_FLOAT: case static::PHINX_TYPE_DOUBLE: @@ -1117,7 +1118,7 @@ public function getSqlType($type, ?int $limit = null): array * @throws \Phinx\Db\Adapter\UnsupportedColumnTypeException * @return array Phinx type */ - public function getPhinxType($sqlTypeDef) + public function getPhinxType(string $sqlTypeDef): array { $matches = []; if (!preg_match('/^([\w]+)(\(([\d]+)*(,([\d]+))*\))*(.+)*$/', $sqlTypeDef, $matches)) { @@ -1367,7 +1368,7 @@ protected function getColumnSqlDefinition(Column $column): string $def .= $column->isNull() ? ' NULL' : ' NOT NULL'; if ( - version_compare($this->getAttribute(\PDO::ATTR_SERVER_VERSION), '8', '>=') + version_compare($this->getAttribute(PDO::ATTR_SERVER_VERSION), '8', '>=') && in_array($column->getType(), static::PHINX_TYPES_GEOSPATIAL) && !is_null($column->getSrid()) ) { @@ -1379,7 +1380,7 @@ protected function getColumnSqlDefinition(Column $column): string $default = $column->getDefault(); // MySQL 8 supports setting default for the following tested types, but only if they are "cast as expressions" if ( - version_compare($this->getAttribute(\PDO::ATTR_SERVER_VERSION), '8', '>=') && + version_compare($this->getAttribute(PDO::ATTR_SERVER_VERSION), '8', '>=') && is_string($default) && in_array( $column->getType(), diff --git a/src/Phinx/Db/Adapter/PdoAdapter.php b/src/Phinx/Db/Adapter/PdoAdapter.php index 90838925a..6b79c2acf 100644 --- a/src/Phinx/Db/Adapter/PdoAdapter.php +++ b/src/Phinx/Db/Adapter/PdoAdapter.php @@ -1,4 +1,5 @@ */ abstract class PdoAdapter extends AbstractAdapter implements DirectActionInterface { /** * @var \PDO|null */ - protected $connection; + protected ?PDO $connection = null; /** * @var \Cake\Database\Connection|null */ - protected $decoratedConnection; + protected ?Connection $decoratedConnection = null; /** * Writes a message to stdout if verbose output is on @@ -61,7 +61,7 @@ abstract class PdoAdapter extends AbstractAdapter implements DirectActionInterfa * @param string $message The message to show * @return void */ - protected function verboseLog($message): void + protected function verboseLog(string $message): void { if ( !$this->isDryRunEnabled() && @@ -95,7 +95,7 @@ protected function createPdoConnection(string $dsn, ?string $username = null, ?s if (strpos($key, 'attr_') === 0) { $pdoConstant = '\PDO::' . strtoupper($key); if (!defined($pdoConstant)) { - throw new \UnexpectedValueException('Invalid PDO attribute: ' . $key . ' (' . $pdoConstant . ')'); + throw new UnexpectedValueException('Invalid PDO attribute: ' . $key . ' (' . $pdoConstant . ')'); } $db->setAttribute(constant($pdoConstant), $option); } @@ -219,7 +219,7 @@ abstract public function getDecoratedConnection(): Connection; * @param array $options Options. * @return \Cake\Database\Connection */ - protected function buildConnection(string $driverClass, array $options) + protected function buildConnection(string $driverClass, array $options): Connection { $driver = new $driverClass($options); $prop = new ReflectionProperty($driver, 'pdo'); @@ -248,9 +248,9 @@ public function getQueryBuilder(string $type): Query * Executes a query and returns PDOStatement. * * @param string $sql SQL - * @return \PDOStatement|false + * @return mixed */ - public function query(string $sql, array $params = []) + public function query(string $sql, array $params = []): mixed { if (empty($params)) { return $this->getConnection()->query($sql); @@ -264,7 +264,7 @@ public function query(string $sql, array $params = []) /** * @inheritDoc */ - public function fetchRow(string $sql) + public function fetchRow(string $sql): array|false { return $this->query($sql)->fetch(); } @@ -311,7 +311,7 @@ public function insert(Table $table, array $row): void * @param mixed $value The value to quote * @return mixed */ - protected function quoteValue($value) + protected function quoteValue(mixed $value): mixed { if (is_numeric($value)) { return $value; @@ -603,7 +603,7 @@ public function getColumnTypes(): array /** * @inheritDoc */ - public function castToBool($value) + public function castToBool($value): mixed { return (bool)$value ? 1 : 0; } @@ -615,7 +615,7 @@ public function castToBool($value) * @param int $attribute One of the PDO::ATTR_* constants * @return mixed */ - public function getAttribute(int $attribute) + public function getAttribute(int $attribute): mixed { return $this->connection->getAttribute($attribute); } @@ -627,7 +627,7 @@ public function getAttribute(int $attribute) * @param string|null $columnType column type added * @return string */ - protected function getDefaultValueDefinition($default, ?string $columnType = null): string + protected function getDefaultValueDefinition(mixed $default, ?string $columnType = null): string { if ($default instanceof Literal) { $default = (string)$default; @@ -764,7 +764,7 @@ public function dropIndex(string $tableName, $columns): void * @param string|string[] $columns Column(s) * @return \Phinx\Db\Util\AlterInstructions */ - abstract protected function getDropIndexByColumnsInstructions(string $tableName, $columns): AlterInstructions; + abstract protected function getDropIndexByColumnsInstructions(string $tableName, string|array $columns): AlterInstructions; /** * @inheritdoc @@ -885,7 +885,7 @@ public function changePrimaryKey(Table $table, $newColumns): void * @param string|string[]|null $newColumns Column name(s) to belong to the primary key, or null to drop the key * @return \Phinx\Db\Util\AlterInstructions */ - abstract protected function getChangePrimaryKeyInstructions(Table $table, $newColumns): AlterInstructions; + abstract protected function getChangePrimaryKeyInstructions(Table $table, string|array|null $newColumns): AlterInstructions; /** * @inheritdoc diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 0475ecdb9..03cfea6eb 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -1,4 +1,5 @@ = 10.0) * * @var bool */ - protected $useIdentity; + protected bool $useIdentity; /** * {@inheritDoc} @@ -715,7 +716,7 @@ protected function getDropColumnInstructions(string $tableName, string $columnNa * @param string $tableName Table name * @return array */ - protected function getIndexes($tableName) + protected function getIndexes(string $tableName): array { $parts = $this->getSchemaName($tableName); @@ -759,7 +760,7 @@ protected function getIndexes($tableName) /** * @inheritDoc */ - public function hasIndex(string $tableName, $columns): bool + public function hasIndex(string $tableName, string|array $columns): bool { if (is_string($columns)) { $columns = [$columns]; @@ -1039,8 +1040,9 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr * * @throws \Phinx\Db\Adapter\UnsupportedColumnTypeException */ - public function getSqlType($type, ?int $limit = null): array + public function getSqlType(Literal|string $type, ?int $limit = null): array { + $type = (string)$type; switch ($type) { case static::PHINX_TYPE_TEXT: case static::PHINX_TYPE_TIME: @@ -1513,7 +1515,7 @@ public function isValidColumnType(Column $column): bool * @param string|\Phinx\Util\Literal $columnType Column type * @return bool */ - protected function isArrayType($columnType): bool + protected function isArrayType(string|Literal $columnType): bool { if (!preg_match('/^([a-z]+)(?:\[\]){1,}$/', $columnType, $matches)) { return false; @@ -1557,7 +1559,7 @@ protected function getGlobalSchemaName(): string /** * @inheritDoc */ - public function castToBool($value) + public function castToBool($value): mixed { return (bool)$value ? 'TRUE' : 'FALSE'; } diff --git a/src/Phinx/Db/Adapter/ProxyAdapter.php b/src/Phinx/Db/Adapter/ProxyAdapter.php index 979700cec..a20bd27fb 100644 --- a/src/Phinx/Db/Adapter/ProxyAdapter.php +++ b/src/Phinx/Db/Adapter/ProxyAdapter.php @@ -1,4 +1,5 @@ */ class ProxyAdapter extends AdapterWrapper { /** * @var \Phinx\Db\Action\Action[] */ - protected $commands = []; + protected array $commands = []; /** * @inheritDoc diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index 7fc66292d..c4e286030 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1,4 +1,5 @@ - * @author Richard McIntyre */ class SQLiteAdapter extends PdoAdapter { @@ -38,7 +37,7 @@ class SQLiteAdapter extends PdoAdapter * * @var string[] */ - protected static $supportedColumnTypes = [ + protected static array $supportedColumnTypes = [ self::PHINX_TYPE_BIG_INTEGER => 'biginteger', self::PHINX_TYPE_BINARY => 'binary_blob', self::PHINX_TYPE_BINARYUUID => 'binary_blob', @@ -68,7 +67,7 @@ class SQLiteAdapter extends PdoAdapter * * @var string[] */ - protected static $supportedColumnTypeAliases = [ + protected static array $supportedColumnTypeAliases = [ 'varchar' => self::PHINX_TYPE_STRING, 'tinyint' => self::PHINX_TYPE_TINY_INTEGER, 'tinyinteger' => self::PHINX_TYPE_TINY_INTEGER, @@ -91,7 +90,7 @@ class SQLiteAdapter extends PdoAdapter * * @var string[] */ - protected static $unsupportedColumnTypes = [ + protected static array $unsupportedColumnTypes = [ self::PHINX_TYPE_BIT, self::PHINX_TYPE_CIDR, self::PHINX_TYPE_ENUM, @@ -109,7 +108,7 @@ class SQLiteAdapter extends PdoAdapter /** * @var string[] */ - protected $definitionsWithLimits = [ + protected array $definitionsWithLimits = [ 'CHAR', 'CHARACTER', 'VARCHAR', @@ -122,7 +121,7 @@ class SQLiteAdapter extends PdoAdapter /** * @var string */ - protected $suffix = '.sqlite3'; + protected string $suffix = '.sqlite3'; /** * Indicates whether the database library version is at least the specified version @@ -130,7 +129,7 @@ class SQLiteAdapter extends PdoAdapter * @param string $ver The version to check against e.g. '3.28.0' * @return bool */ - public function databaseVersionAtLeast($ver): bool + public function databaseVersionAtLeast(string $ver): bool { $actual = $this->query('SELECT sqlite_version()')->fetchColumn(); @@ -540,7 +539,7 @@ public function truncateTable(string $tableName): void * @param string $columnType The Phinx type of the column * @return mixed */ - protected function parseDefaultValue($default, string $columnType) + protected function parseDefaultValue(mixed $default, string $columnType): mixed { if ($default === null) { return null; @@ -597,7 +596,7 @@ protected function parseDefaultValue($default, string $columnType) return null; } elseif (preg_match('/^true|false$/i', $defaultBare)) { // boolean literal - return filter_var($defaultClean, \FILTER_VALIDATE_BOOLEAN); + return filter_var($defaultClean, FILTER_VALIDATE_BOOLEAN); } else { // any other expression: return the expression with parentheses, but without comments return Expression::from($defaultClean); @@ -1085,7 +1084,7 @@ protected function copyAndDropTmpTable(AlterInstructions $instructions, string $ * @throws \InvalidArgumentException * @return array */ - protected function calculateNewTableColumns(string $tableName, $columnName, $newColumnName): array + protected function calculateNewTableColumns(string $tableName, string|false $columnName, string|false $newColumnName): array { $columns = $this->fetchAll(sprintf('pragma table_info(%s)', $this->quoteTableName($tableName))); $selectColumns = []; @@ -1329,7 +1328,7 @@ protected function getIndexes(string $tableName): array * @param string|string[] $columns The columns of the index * @return array */ - protected function resolveIndex(string $tableName, $columns): array + protected function resolveIndex(string $tableName, string|array $columns): array { $columns = array_map('strtolower', (array)$columns); $indexes = $this->getIndexes($tableName); @@ -1348,7 +1347,7 @@ protected function resolveIndex(string $tableName, $columns): array /** * @inheritDoc */ - public function hasIndex(string $tableName, $columns): bool + public function hasIndex(string $tableName, string|array $columns): bool { return (bool)$this->resolveIndex($tableName, $columns); } @@ -1715,17 +1714,20 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr * * @throws \Phinx\Db\Adapter\UnsupportedColumnTypeException */ - public function getSqlType($type, ?int $limit = null): array + public function getSqlType(Literal|string $type, ?int $limit = null): array { - $typeLC = strtolower($type); if ($type instanceof Literal) { $name = $type; - } elseif (isset(static::$supportedColumnTypes[$typeLC])) { - $name = static::$supportedColumnTypes[$typeLC]; - } elseif (in_array($typeLC, static::$unsupportedColumnTypes, true)) { - throw new UnsupportedColumnTypeException('Column type "' . $type . '" is not supported by SQLite.'); } else { - throw new UnsupportedColumnTypeException('Column type "' . $type . '" is not known by SQLite.'); + $typeLC = strtolower($type); + + if (isset(static::$supportedColumnTypes[$typeLC])) { + $name = static::$supportedColumnTypes[$typeLC]; + } elseif (in_array($typeLC, static::$unsupportedColumnTypes, true)) { + throw new UnsupportedColumnTypeException('Column type "' . $type . '" is not supported by SQLite.'); + } else { + throw new UnsupportedColumnTypeException('Column type "' . $type . '" is not known by SQLite.'); + } } return ['name' => $name, 'limit' => $limit]; diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index 5493d9c29..dd4371d93 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -1,4 +1,5 @@ */ class SqlServerAdapter extends PdoAdapter { /** * @var string[] */ - protected static $specificColumnTypes = [ + protected static array $specificColumnTypes = [ self::PHINX_TYPE_FILESTREAM, self::PHINX_TYPE_BINARYUUID, ]; @@ -40,12 +40,12 @@ class SqlServerAdapter extends PdoAdapter /** * @var string */ - protected $schema = 'dbo'; + protected string $schema = 'dbo'; /** * @var bool[] */ - protected $signedColumnTypes = [ + protected array $signedColumnTypes = [ self::PHINX_TYPE_INTEGER => true, self::PHINX_TYPE_BIG_INTEGER => true, self::PHINX_TYPE_FLOAT => true, @@ -106,7 +106,7 @@ public function connect(): void if (strpos($key, 'sqlsrv_attr_') === 0) { $pdoConstant = '\PDO::' . strtoupper($key); if (!defined($pdoConstant)) { - throw new \UnexpectedValueException('Invalid PDO attribute: ' . $key . ' (' . $pdoConstant . ')'); + throw new UnexpectedValueException('Invalid PDO attribute: ' . $key . ' (' . $pdoConstant . ')'); } $driverOptions[constant($pdoConstant)] = $option; } @@ -360,7 +360,7 @@ protected function getChangeCommentInstructions(Table $table, ?string $newCommen * @param string $tableName Table name * @return string */ - protected function getColumnCommentSqlDefinition(Column $column, $tableName): string + protected function getColumnCommentSqlDefinition(Column $column, string $tableName): string { // passing 'null' is to remove column comment $currentComment = $this->getColumnComment($tableName, $column->getName()); @@ -479,7 +479,7 @@ public function getColumns(string $tableName): array ->setComment($this->getColumnComment($columnInfo['table_name'], $columnInfo['name'])); if (!empty($columnInfo['char_length'])) { - $column->setLimit($columnInfo['char_length']); + $column->setLimit((int)$columnInfo['char_length']); } $columns[$columnInfo['name']] = $column; @@ -492,7 +492,7 @@ public function getColumns(string $tableName): array * @param string|null $default Default * @return int|string|null */ - protected function parseDefault(?string $default) + protected function parseDefault(?string $default): int|string|null { // if a column is non-nullable and has no default, the value of column_default is null, // otherwise it should be a string value that we parse below, including "(NULL)" which @@ -693,7 +693,7 @@ protected function getDropDefaultConstraint(string $tableName, ?string $columnNa * @param string $columnName Column name * @return string|false */ - protected function getDefaultConstraint(string $tableName, string $columnName) + protected function getDefaultConstraint(string $tableName, string $columnName): string|false { $sql = "SELECT default_constraints.name @@ -723,11 +723,11 @@ protected function getDefaultConstraint(string $tableName, string $columnName) } /** - * @param int $tableId Table ID - * @param int $indexId Index ID + * @param string $tableId Table ID + * @param string $indexId Index ID * @return array */ - protected function getIndexColums(int $tableId, int $indexId): array + protected function getIndexColums(string $tableId, string $indexId): array { $sql = "SELECT AC.[name] AS [column_name] FROM sys.[index_columns] IC @@ -771,7 +771,7 @@ public function getIndexes(string $tableName): array /** * @inheritDoc */ - public function hasIndex(string $tableName, $columns): bool + public function hasIndex(string $tableName, string|array $columns): bool { if (is_string($columns)) { $columns = [$columns]; // str to array @@ -1062,8 +1062,9 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr * * @throws \Phinx\Db\Adapter\UnsupportedColumnTypeException */ - public function getSqlType($type, ?int $limit = null): array + public function getSqlType(Literal|string $type, ?int $limit = null): array { + $type = (string)$type; switch ($type) { case static::PHINX_TYPE_FLOAT: case static::PHINX_TYPE_DECIMAL: diff --git a/src/Phinx/Db/Adapter/TablePrefixAdapter.php b/src/Phinx/Db/Adapter/TablePrefixAdapter.php index dafc84098..cce2d5109 100644 --- a/src/Phinx/Db/Adapter/TablePrefixAdapter.php +++ b/src/Phinx/Db/Adapter/TablePrefixAdapter.php @@ -1,4 +1,5 @@ */ class TablePrefixAdapter extends AdapterWrapper implements DirectActionInterface { @@ -236,7 +235,7 @@ public function dropColumn(string $tableName, string $columnName): void /** * @inheritDoc */ - public function hasIndex(string $tableName, $columns): bool + public function hasIndex(string $tableName, string|array $columns): bool { $adapterTableName = $this->getAdapterTableName($tableName); diff --git a/src/Phinx/Db/Adapter/TimedOutputAdapter.php b/src/Phinx/Db/Adapter/TimedOutputAdapter.php index 1ef740a36..4fcecbe98 100644 --- a/src/Phinx/Db/Adapter/TimedOutputAdapter.php +++ b/src/Phinx/Db/Adapter/TimedOutputAdapter.php @@ -1,4 +1,5 @@ getOutput()->getVerbosity()) { $this->getOutput()->writeln(' -> ' . sprintf('%.4fs', $end - $started)); diff --git a/src/Phinx/Db/Adapter/UnsupportedColumnTypeException.php b/src/Phinx/Db/Adapter/UnsupportedColumnTypeException.php index 5ef75e96d..f784bf860 100644 --- a/src/Phinx/Db/Adapter/UnsupportedColumnTypeException.php +++ b/src/Phinx/Db/Adapter/UnsupportedColumnTypeException.php @@ -1,4 +1,5 @@ */ class UnsupportedColumnTypeException extends RuntimeException { diff --git a/src/Phinx/Db/Adapter/WrapperInterface.php b/src/Phinx/Db/Adapter/WrapperInterface.php index 669d0d2e3..f44601eb7 100644 --- a/src/Phinx/Db/Adapter/WrapperInterface.php +++ b/src/Phinx/Db/Adapter/WrapperInterface.php @@ -1,4 +1,5 @@ */ interface WrapperInterface { diff --git a/src/Phinx/Db/Plan/AlterTable.php b/src/Phinx/Db/Plan/AlterTable.php index 1746e1546..bdb675ee6 100644 --- a/src/Phinx/Db/Plan/AlterTable.php +++ b/src/Phinx/Db/Plan/AlterTable.php @@ -1,4 +1,5 @@ actions->addAction(new ChangePrimaryKey($this->table, $columns)); @@ -192,7 +194,7 @@ public function changePrimaryKey($columns) * @param string|null $constraint Constraint names * @return bool */ - public function hasPrimaryKey($columns, ?string $constraint = null): bool + public function hasPrimaryKey(string|array $columns, ?string $constraint = null): bool { return $this->getAdapter()->hasPrimaryKey($this->getName(), $columns, $constraint); } @@ -291,12 +293,12 @@ public function reset(): void * Valid options can be: limit, default, null, precision or scale. * * @param string|\Phinx\Db\Table\Column $columnName Column Name - * @param string|\Phinx\Util\Literal|null $type Column Type + * @param string|\Phinx\Util\Literal $type Column Type * @param array $options Column Options * @throws \InvalidArgumentException * @return $this */ - public function addColumn($columnName, $type = null, array $options = []) + public function addColumn(string|Column $columnName, string|Literal $type, array $options = []) { if ($columnName instanceof Column) { $action = new AddColumn($this->table, $columnName); @@ -357,7 +359,7 @@ public function renameColumn(string $oldName, string $newName) * @param array $options Options * @return $this */ - public function changeColumn(string $columnName, $newColumnType, array $options = []) + public function changeColumn(string $columnName, string|Column|Literal $newColumnType, array $options = []) { if ($newColumnType instanceof Column) { $action = new ChangeColumn($this->table, $columnName, $newColumnType); @@ -389,7 +391,7 @@ public function hasColumn(string $columnName): bool * @param array $options Index Options * @return $this */ - public function addIndex($columns, array $options = []) + public function addIndex(string|array|Index $columns, array $options = []) { $action = AddIndex::build($this->table, $columns, $options); $this->actions->addAction($action); @@ -403,7 +405,7 @@ public function addIndex($columns, array $options = []) * @param string|string[] $columns Columns * @return $this */ - public function removeIndex($columns) + public function removeIndex(string|array $columns) { $action = DropIndex::build($this->table, is_string($columns) ? [$columns] : $columns); $this->actions->addAction($action); @@ -431,7 +433,7 @@ public function removeIndexByName(string $name) * @param string|string[] $columns Columns * @return bool */ - public function hasIndex($columns): bool + public function hasIndex(string|array $columns): bool { return $this->getAdapter()->hasIndex($this->getName(), $columns); } @@ -442,7 +444,7 @@ public function hasIndex($columns): bool * @param string $indexName Index name * @return bool */ - public function hasIndexByName($indexName): bool + public function hasIndexByName(string $indexName): bool { return $this->getAdapter()->hasIndexByName($this->getName(), $indexName); } @@ -459,7 +461,7 @@ public function hasIndexByName($indexName): bool * @param array $options Options * @return $this */ - public function addForeignKey($columns, $referencedTable, $referencedColumns = ['id'], array $options = []) + public function addForeignKey(string|array $columns, string|TableValue $referencedTable, string|array $referencedColumns = ['id'], array $options = []) { $action = AddForeignKey::build($this->table, $columns, $referencedTable, $referencedColumns, $options); $this->actions->addAction($action); @@ -480,7 +482,7 @@ public function addForeignKey($columns, $referencedTable, $referencedColumns = [ * @param array $options Options * @return $this */ - public function addForeignKeyWithName(string $name, $columns, $referencedTable, $referencedColumns = ['id'], array $options = []) + public function addForeignKeyWithName(string $name, string|array $columns, string|TableValue $referencedTable, string|array $referencedColumns = ['id'], array $options = []) { $action = AddForeignKey::build( $this->table, @@ -502,7 +504,7 @@ public function addForeignKeyWithName(string $name, $columns, $referencedTable, * @param string|null $constraint Constraint names * @return $this */ - public function dropForeignKey($columns, ?string $constraint = null) + public function dropForeignKey(string|array $columns, ?string $constraint = null) { $action = DropForeignKey::build($this->table, $columns, $constraint); $this->actions->addAction($action); @@ -517,7 +519,7 @@ public function dropForeignKey($columns, ?string $constraint = null) * @param string|null $constraint Constraint names * @return bool */ - public function hasForeignKey($columns, ?string $constraint = null): bool + public function hasForeignKey(string|array $columns, ?string $constraint = null): bool { return $this->getAdapter()->hasForeignKey($this->getName(), $columns, $constraint); } @@ -530,13 +532,13 @@ public function hasForeignKey($columns, ?string $constraint = null): bool * @param bool $withTimezone Whether to set the timezone option on the added columns * @return $this */ - public function addTimestamps($createdAt = 'created_at', $updatedAt = 'updated_at', bool $withTimezone = false) + public function addTimestamps(string|false|null $createdAt = 'created_at', string|false|null $updatedAt = 'updated_at', bool $withTimezone = false) { $createdAt = $createdAt ?? 'created_at'; $updatedAt = $updatedAt ?? 'updated_at'; if (!$createdAt && !$updatedAt) { - throw new \RuntimeException('Cannot set both created_at and updated_at columns to false'); + throw new RuntimeException('Cannot set both created_at and updated_at columns to false'); } if ($createdAt) { @@ -567,7 +569,7 @@ public function addTimestamps($createdAt = 'created_at', $updatedAt = 'updated_a * @param string|false|null $updatedAt Alternate name for the updated_at column * @return $this */ - public function addTimestampsWithTimezone($createdAt = null, $updatedAt = null) + public function addTimestampsWithTimezone(string|false|null $createdAt = null, string|false|null $updatedAt = null) { $this->addTimestamps($createdAt, $updatedAt, true); diff --git a/src/Phinx/Db/Table/Column.php b/src/Phinx/Db/Table/Column.php index f825b151d..dde4cf2d2 100644 --- a/src/Phinx/Db/Table/Column.php +++ b/src/Phinx/Db/Table/Column.php @@ -1,4 +1,5 @@ type = $type; @@ -208,7 +210,7 @@ public function setType($type) * * @return string|\Phinx\Util\Literal */ - public function getType() + public function getType(): string|Literal { return $this->type; } @@ -275,7 +277,7 @@ public function isNull(): bool * @param mixed $default Default * @return $this */ - public function setDefault($default) + public function setDefault(mixed $default) { $this->default = $default; @@ -287,7 +289,7 @@ public function setDefault($default) * * @return mixed */ - public function getDefault() + public function getDefault(): mixed { return $this->default; } @@ -635,7 +637,7 @@ public function getProperties(): array * @param string[]|string $values Value(s) * @return $this */ - public function setValues($values) + public function setValues(array|string $values) { if (!is_array($values)) { $values = preg_split('/,\s*/', $values) ?: []; diff --git a/src/Phinx/Db/Table/ForeignKey.php b/src/Phinx/Db/Table/ForeignKey.php index cd14893f1..a734d6125 100644 --- a/src/Phinx/Db/Table/ForeignKey.php +++ b/src/Phinx/Db/Table/ForeignKey.php @@ -1,4 +1,5 @@ */ - protected static $validOptions = ['delete', 'update', 'constraint']; + protected static array $validOptions = ['delete', 'update', 'constraint']; /** * @var string[] */ - protected $columns = []; + protected array $columns = []; /** * @var \Phinx\Db\Table\Table */ - protected $referencedTable; + protected Table $referencedTable; /** * @var string[] */ - protected $referencedColumns = []; + protected array $referencedColumns = []; /** * @var string|null */ - protected $onDelete; + protected ?string $onDelete = null; /** * @var string|null */ - protected $onUpdate; + protected ?string $onUpdate = null; /** * @var string|null */ - protected $constraint; + protected ?string $constraint = null; /** * Sets the foreign key columns. @@ -58,7 +59,7 @@ class ForeignKey * @param string[]|string $columns Columns * @return $this */ - public function setColumns($columns) + public function setColumns(array|string $columns) { $this->columns = is_string($columns) ? [$columns] : $columns; diff --git a/src/Phinx/Db/Table/Index.php b/src/Phinx/Db/Table/Index.php index f405f0252..cea7b9520 100644 --- a/src/Phinx/Db/Table/Index.php +++ b/src/Phinx/Db/Table/Index.php @@ -1,4 +1,5 @@ columns = is_string($columns) ? [$columns] : $columns; @@ -131,7 +132,7 @@ public function getName(): ?string * @param int|array $limit limit value or array of limit value * @return $this */ - public function setLimit($limit) + public function setLimit(int|array $limit) { $this->limit = $limit; @@ -143,7 +144,7 @@ public function setLimit($limit) * * @return int|array|null */ - public function getLimit() + public function getLimit(): int|array|null { return $this->limit; } diff --git a/src/Phinx/Db/Table/Table.php b/src/Phinx/Db/Table/Table.php index 03521572b..30c47e277 100644 --- a/src/Phinx/Db/Table/Table.php +++ b/src/Phinx/Db/Table/Table.php @@ -1,4 +1,5 @@ */ - protected $options; + protected array $options; /** * @param string $name The table name * @param array $options The creation options for this table * @throws \InvalidArgumentException */ - public function __construct($name, array $options = []) + public function __construct(string $name, array $options = []) { if (empty($name)) { throw new InvalidArgumentException('Cannot use an empty table name'); diff --git a/src/Phinx/Db/Util/AlterInstructions.php b/src/Phinx/Db/Util/AlterInstructions.php index ddc49fc5b..bbde1b947 100644 --- a/src/Phinx/Db/Util/AlterInstructions.php +++ b/src/Phinx/Db/Util/AlterInstructions.php @@ -1,4 +1,5 @@ postSteps[] = $sql; } diff --git a/src/Phinx/Migration/AbstractMigration.php b/src/Phinx/Migration/AbstractMigration.php index 817a516c0..b567ba8ae 100644 --- a/src/Phinx/Migration/AbstractMigration.php +++ b/src/Phinx/Migration/AbstractMigration.php @@ -1,4 +1,5 @@ */ abstract class AbstractMigration implements MigrationInterface { /** * @var string */ - protected $environment; + protected string $environment; /** * @var int */ - protected $version; + protected int $version; /** * @var \Phinx\Db\Adapter\AdapterInterface|null */ - protected $adapter; + protected ?AdapterInterface $adapter = null; /** * @var \Symfony\Component\Console\Output\OutputInterface|null */ - protected $output; + protected ?OutputInterface $output = null; /** * @var \Symfony\Component\Console\Input\InputInterface|null */ - protected $input; + protected ?InputInterface $input = null; /** * Whether this migration is being applied or reverted * * @var bool */ - protected $isMigratingUp = true; + protected bool $isMigratingUp = true; /** * List of all the table objects created by this migration * * @var array<\Phinx\Db\Table> */ - protected $tables = []; + protected array $tables = []; /** * @param string $environment Environment Detected @@ -202,7 +201,7 @@ public function execute(string $sql, array $params = []): int /** * @inheritDoc */ - public function query(string $sql, array $params = []) + public function query(string $sql, array $params = []): mixed { return $this->getAdapter()->query($sql, $params); } @@ -218,7 +217,7 @@ public function getQueryBuilder(string $type): Query /** * @inheritDoc */ - public function fetchRow(string $sql) + public function fetchRow(string $sql): array|false { return $this->getAdapter()->fetchRow($sql); } diff --git a/src/Phinx/Migration/AbstractTemplateCreation.php b/src/Phinx/Migration/AbstractTemplateCreation.php index 286bc18bd..9eea24268 100644 --- a/src/Phinx/Migration/AbstractTemplateCreation.php +++ b/src/Phinx/Migration/AbstractTemplateCreation.php @@ -1,4 +1,5 @@ */ interface CreationInterface { diff --git a/src/Phinx/Migration/IrreversibleMigrationException.php b/src/Phinx/Migration/IrreversibleMigrationException.php index 376bcdc63..575c03b3e 100644 --- a/src/Phinx/Migration/IrreversibleMigrationException.php +++ b/src/Phinx/Migration/IrreversibleMigrationException.php @@ -1,4 +1,5 @@ */ class IrreversibleMigrationException extends Exception { diff --git a/src/Phinx/Migration/Manager.php b/src/Phinx/Migration/Manager.php index 76b68a032..efb5f3303 100644 --- a/src/Phinx/Migration/Manager.php +++ b/src/Phinx/Migration/Manager.php @@ -1,4 +1,5 @@ getMigrations($environment); @@ -952,7 +953,7 @@ public function getSeeds(string $environment): array // instantiate it /** @var \Phinx\Seed\AbstractSeed $seed */ - if ($this->container !== null) { + if (isset($this->container)) { $seed = $this->container->get($class); } else { $seed = new $class(); diff --git a/src/Phinx/Migration/Manager/Environment.php b/src/Phinx/Migration/Manager/Environment.php index 9a65b3fa9..f0797e3a5 100644 --- a/src/Phinx/Migration/Manager/Environment.php +++ b/src/Phinx/Migration/Manager/Environment.php @@ -1,4 +1,5 @@ */ - protected $options; + protected array $options; /** * @var \Symfony\Component\Console\Input\InputInterface|null */ - protected $input; + protected ?InputInterface $input = null; /** * @var \Symfony\Component\Console\Output\OutputInterface|null */ - protected $output; + protected ?OutputInterface $output = null; /** * @var int */ - protected $currentVersion; + protected int $currentVersion; /** * @var string */ - protected $schemaTableName = 'phinxlog'; + protected string $schemaTableName = 'phinxlog'; /** * @var \Phinx\Db\Adapter\AdapterInterface */ - protected $adapter; + protected AdapterInterface $adapter; /** * @param string $name Environment Name @@ -378,7 +379,7 @@ public function getAdapter(): AdapterInterface * @param string $schemaTableName Schema Table Name * @return $this */ - public function setSchemaTableName($schemaTableName) + public function setSchemaTableName(string $schemaTableName) { $this->schemaTableName = $schemaTableName; diff --git a/src/Phinx/Migration/MigrationInterface.php b/src/Phinx/Migration/MigrationInterface.php index 8d9d24716..1a7a9c637 100644 --- a/src/Phinx/Migration/MigrationInterface.php +++ b/src/Phinx/Migration/MigrationInterface.php @@ -1,4 +1,5 @@ */ interface MigrationInterface { @@ -151,7 +150,7 @@ public function execute(string $sql, array $params = []): int; * @param array $params parameters to use for prepared query * @return mixed */ - public function query(string $sql, array $params = []); + public function query(string $sql, array $params = []): mixed; /** * Returns a new Query object that can be used to build complex SELECT, UPDATE, INSERT or DELETE @@ -172,7 +171,7 @@ public function getQueryBuilder(string $type): Query; * @param string $sql SQL * @return array|false */ - public function fetchRow(string $sql); + public function fetchRow(string $sql): array|false; /** * Executes a query and returns an array of rows. diff --git a/src/Phinx/Seed/AbstractSeed.php b/src/Phinx/Seed/AbstractSeed.php index 7706d3013..f0f921cef 100644 --- a/src/Phinx/Seed/AbstractSeed.php +++ b/src/Phinx/Seed/AbstractSeed.php @@ -1,4 +1,5 @@ */ abstract class AbstractSeed implements SeedInterface { /** * @var string */ - protected $environment; + protected string $environment; /** * @var \Phinx\Db\Adapter\AdapterInterface */ - protected $adapter; + protected AdapterInterface $adapter; /** * @var \Symfony\Component\Console\Input\InputInterface */ - protected $input; + protected InputInterface $input; /** * @var \Symfony\Component\Console\Output\OutputInterface */ - protected $output; + protected OutputInterface $output; /** * Override to specify dependencies for dependency injection from the configured PSR-11 container @@ -149,7 +148,7 @@ public function getName(): string /** * @inheritDoc */ - public function execute(string $sql, array $params = []) + public function execute(string $sql, array $params = []): int { return $this->getAdapter()->execute($sql, $params); } @@ -157,7 +156,7 @@ public function execute(string $sql, array $params = []) /** * @inheritDoc */ - public function query(string $sql, array $params = []) + public function query(string $sql, array $params = []): mixed { return $this->getAdapter()->query($sql, $params); } @@ -165,7 +164,7 @@ public function query(string $sql, array $params = []) /** * @inheritDoc */ - public function fetchRow(string $sql) + public function fetchRow(string $sql): array|false { return $this->getAdapter()->fetchRow($sql); } diff --git a/src/Phinx/Seed/SeedInterface.php b/src/Phinx/Seed/SeedInterface.php index 6f5afc58f..d644fd542 100644 --- a/src/Phinx/Seed/SeedInterface.php +++ b/src/Phinx/Seed/SeedInterface.php @@ -1,4 +1,5 @@ */ interface SeedInterface { @@ -115,7 +115,7 @@ public function getName(): string; * @param array $params parameters to use for prepared query * @return int */ - public function execute(string $sql, array $params = []); + public function execute(string $sql, array $params = []): int; /** * Executes a SQL statement. @@ -129,7 +129,7 @@ public function execute(string $sql, array $params = []); * @param array $params parameters to use for prepared query * @return mixed */ - public function query(string $sql, array $params = []); + public function query(string $sql, array $params = []): mixed; /** * Executes a query and returns only one row as an array. @@ -137,7 +137,7 @@ public function query(string $sql, array $params = []); * @param string $sql SQL * @return array|false */ - public function fetchRow(string $sql); + public function fetchRow(string $sql): array|false; /** * Executes a query and returns an array of rows. @@ -173,7 +173,7 @@ public function hasTable(string $tableName): bool; * @param array $options Options * @return \Phinx\Db\Table */ - public function table(string $tableName, array $options): \Phinx\Db\Table; + public function table(string $tableName, array $options): Table; /** * Checks to see if the seed should be executed. diff --git a/src/Phinx/Util/Expression.php b/src/Phinx/Util/Expression.php index 23a6b9eff..0de52fc2f 100644 --- a/src/Phinx/Util/Expression.php +++ b/src/Phinx/Util/Expression.php @@ -1,4 +1,5 @@ */ class TextWrapper { /** * @var \Phinx\Console\PhinxApplication */ - protected $app; + protected PhinxApplication $app; /** * @var array */ - protected $options; + protected array $options; /** * @var int */ - protected $exitCode; + protected int $exitCode; /** * @param \Phinx\Console\PhinxApplication $app Application @@ -93,7 +92,7 @@ public function getStatus(?string $env = null): string * @param string|null $env environment name * @return bool */ - private function hasEnvValue($env): bool + private function hasEnvValue(?string $env): bool { return $env || $this->hasOption('environment'); } @@ -132,7 +131,7 @@ public function getMigrate(?string $env = null, ?string $target = null): string * @param string[]|string|null $seed Array of seed names or seed name * @return string */ - public function getSeed(?string $env = null, ?string $target = null, $seed = null): string + public function getSeed(?string $env = null, ?string $target = null, array|string|null $seed = null): string { $command = ['seed:run']; if ($this->hasEnvValue($env)) { @@ -162,7 +161,7 @@ public function getSeed(?string $env = null, ?string $target = null, $seed = nul * @param mixed $target Target version, or 0 (zero) fully revert (optional) * @return string */ - public function getRollback(?string $env = null, $target = null): string + public function getRollback(?string $env = null, mixed $target = null): string { $command = ['rollback']; if ($this->hasEnvValue($env)) { diff --git a/src/composer_autoloader.php b/src/composer_autoloader.php index 2cde6660c..51cac42c9 100644 --- a/src/composer_autoloader.php +++ b/src/composer_autoloader.php @@ -1,4 +1,5 @@ expectException(RuntimeException::class); - - $config = Config::fromPhp($path . '/config_without_array.php'); + Config::fromPhp($path . '/config_without_array.php'); } /** @@ -47,7 +46,6 @@ public function testFromJSONMethodWithoutJSON() $path = __DIR__ . '/_files'; $this->expectException(RuntimeException::class); - - $config = Config::fromPhp($path . '/empty.json'); + Config::fromPhp($path . '/empty.json'); } } diff --git a/tests/Phinx/Config/ConfigTest.php b/tests/Phinx/Config/ConfigTest.php index 8aca893c3..e8bb92ed2 100644 --- a/tests/Phinx/Config/ConfigTest.php +++ b/tests/Phinx/Config/ConfigTest.php @@ -216,41 +216,41 @@ public function testGetMigrationBaseClassNameGetsAlternativeBaseClassWithNamespa */ public function testGetTemplateValuesFalseOnEmpty() { - $config = new \Phinx\Config\Config([]); + $config = new Config([]); $this->assertFalse($config->getTemplateFile()); $this->assertFalse($config->getTemplateClass()); } public function testGetAliasNoAliasesEntry() { - $config = new \Phinx\Config\Config([]); + $config = new Config([]); $this->assertNull($config->getAlias('Short')); } public function testGetAliasEmptyAliasesEntry() { - $config = new \Phinx\Config\Config(['aliases' => []]); + $config = new Config(['aliases' => []]); $this->assertNull($config->getAlias('Short')); } public function testGetAliasInvalidAliasRequest() { - $config = new \Phinx\Config\Config(['aliases' => ['Medium' => 'Some\Long\Classname']]); + $config = new Config(['aliases' => ['Medium' => 'Some\Long\Classname']]); $this->assertNull($config->getAlias('Short')); } public function testGetAliasValidAliasRequest() { - $config = new \Phinx\Config\Config(['aliases' => ['Short' => 'Some\Long\Classname']]); + $config = new Config(['aliases' => ['Short' => 'Some\Long\Classname']]); $this->assertEquals('Some\Long\Classname', $config->getAlias('Short')); } public function testGetSeedPath() { - $config = new \Phinx\Config\Config(['paths' => ['seeds' => 'db/seeds']]); + $config = new Config(['paths' => ['seeds' => 'db/seeds']]); $this->assertEquals(['db/seeds'], $config->getSeedPaths()); - $config = new \Phinx\Config\Config(['paths' => ['seeds' => ['db/seeds1', 'db/seeds2']]]); + $config = new Config(['paths' => ['seeds' => ['db/seeds1', 'db/seeds2']]]); $this->assertEquals(['db/seeds1', 'db/seeds2'], $config->getSeedPaths()); } @@ -259,7 +259,7 @@ public function testGetSeedPath() */ public function testGetSeedPathThrowsException() { - $config = new \Phinx\Config\Config([]); + $config = new Config([]); $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Seeds path missing from config file'); @@ -296,9 +296,9 @@ public function testGetMigrationBaseClassNameNoNamespaceNoDrop() */ public function testGetVersionOrder() { - $config = new \Phinx\Config\Config([]); - $config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; - $this->assertEquals(\Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, $config->getVersionOrder()); + $config = new Config([]); + $config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; + $this->assertEquals(Config::VERSION_ORDER_EXECUTION_TIME, $config->getVersionOrder()); } /** @@ -328,11 +328,11 @@ public function isVersionOrderCreationTimeDataProvider() return [ 'With Creation Time Version Order' => [ - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, true, + Config::VERSION_ORDER_CREATION_TIME, true, ], 'With Execution Time Version Order' => [ - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, false, + Config::VERSION_ORDER_EXECUTION_TIME, false, ], ]; } @@ -345,7 +345,7 @@ public function testConfigReplacesEnvironmentTokens() $_ENV['PHINX_TEST_CONFIG_SUFFIX'] = 'foo'; try { - $config = new \Phinx\Config\Config([ + $config = new Config([ 'environments' => [ 'production' => [ 'adapter' => '%%PHINX_TEST_CONFIG_ADAPTER%%', @@ -369,7 +369,7 @@ public function testConfigReplacesEnvironmentTokens() public function testSqliteMemorySetsName() { - $config = new \Phinx\Config\Config([ + $config = new Config([ 'environments' => [ 'production' => [ 'adapter' => 'sqlite', @@ -385,7 +385,7 @@ public function testSqliteMemorySetsName() public function testSqliteMemoryOverridesName() { - $config = new \Phinx\Config\Config([ + $config = new Config([ 'environments' => [ 'production' => [ 'adapter' => 'sqlite', @@ -402,7 +402,7 @@ public function testSqliteMemoryOverridesName() public function testSqliteNonBooleanMemory() { - $config = new \Phinx\Config\Config([ + $config = new Config([ 'environments' => [ 'production' => [ 'adapter' => 'sqlite', @@ -418,7 +418,7 @@ public function testSqliteNonBooleanMemory() public function testDefaultTemplateStyle(): void { - $config = new \Phinx\Config\Config([]); + $config = new Config([]); $this->assertSame('change', $config->getTemplateStyle()); } @@ -436,7 +436,7 @@ public function templateStyleDataProvider(): array */ public function testTemplateStyle(string $style, string $expected): void { - $config = new \Phinx\Config\Config(['templates' => ['style' => $style]]); + $config = new Config(['templates' => ['style' => $style]]); $this->assertSame($expected, $config->getTemplateStyle()); } } diff --git a/tests/Phinx/Console/Command/BreakpointTest.php b/tests/Phinx/Console/Command/BreakpointTest.php index 310053f98..e1e657ced 100644 --- a/tests/Phinx/Console/Command/BreakpointTest.php +++ b/tests/Phinx/Console/Command/BreakpointTest.php @@ -1,4 +1,5 @@ config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $this->config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $application = new PhinxApplication(); $application->add(new Migrate()); diff --git a/tests/Phinx/Console/Command/RollbackTest.php b/tests/Phinx/Console/Command/RollbackTest.php index 07d47d88d..1c87f5403 100644 --- a/tests/Phinx/Console/Command/RollbackTest.php +++ b/tests/Phinx/Console/Command/RollbackTest.php @@ -1,4 +1,5 @@ add(new Rollback()); // setup dependencies - $this->config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $this->config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $command = $application->find('rollback'); @@ -203,7 +204,7 @@ public function testStartTimeVersionOrder() public function testWithDate() { - $application = new \Phinx\Console\PhinxApplication('testing'); + $application = new PhinxApplication('testing'); $date = '20160101'; $target = '20160101000000'; @@ -286,11 +287,11 @@ public function getTargetFromDateThrowsExceptionDataProvider() public function testStarTimeVersionOrderWithDate() { - $application = new \Phinx\Console\PhinxApplication('testing'); + $application = new PhinxApplication('testing'); $application->add(new Rollback()); // setup dependencies - $this->config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $this->config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $command = $application->find('rollback'); diff --git a/tests/Phinx/Console/Command/SeedCreateTest.php b/tests/Phinx/Console/Command/SeedCreateTest.php index c7176d82b..1c3aeca57 100644 --- a/tests/Phinx/Console/Command/SeedCreateTest.php +++ b/tests/Phinx/Console/Command/SeedCreateTest.php @@ -1,4 +1,5 @@ getMockBuilder(\Phinx\Migration\Manager::class) + $managerStub = $this->getMockBuilder(Manager::class) ->setConstructorArgs([$this->config, $this->input, $this->output]) ->getMock(); @@ -105,7 +107,7 @@ public function testExecuteWithInvalidClassName() // mock the manager class /** @var Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */ - $managerStub = $this->getMockBuilder(\Phinx\Migration\Manager::class) + $managerStub = $this->getMockBuilder(Manager::class) ->setConstructorArgs([$this->config, $this->input, $this->output]) ->getMock(); @@ -130,7 +132,7 @@ public function testAlternativeTemplateFromConsole() $command = $application->find('seed:create'); /** @var Manager $managerStub mock the manager class */ - $managerStub = $this->getMockBuilder(\Phinx\Migration\Manager::class) + $managerStub = $this->getMockBuilder(Manager::class) ->setConstructorArgs([$this->config, $this->input, $this->output]) ->getMock(); @@ -163,7 +165,7 @@ public function testAlternativeTemplateFromConsoleDoesntExist() $command = $application->find('seed:create'); /** @var Manager $managerStub mock the manager class */ - $managerStub = $this->getMockBuilder(\Phinx\Migration\Manager::class) + $managerStub = $this->getMockBuilder(Manager::class) ->setConstructorArgs([$this->config, $this->input, $this->output]) ->getMock(); @@ -193,7 +195,7 @@ public function testAlternativeTemplateFromConfigOnly() $this->configValues['templates']['seedFile'] = __DIR__ . '/Templates/SimpleSeeder.templateFromConfig.php.dist'; $this->config = new Config($this->configValues); /** @var Manager $managerStub mock the manager class */ - $managerStub = $this->getMockBuilder(\Phinx\Migration\Manager::class) + $managerStub = $this->getMockBuilder(Manager::class) ->setConstructorArgs([$this->config, $this->input, $this->output]) ->getMock(); @@ -230,7 +232,7 @@ public function testAlternativeTemplateFromConfigOnlyDoesntExist() $this->configValues['templates']['seedFile'] = $template; $this->config = new Config($this->configValues); /** @var Manager $managerStub mock the manager class */ - $managerStub = $this->getMockBuilder(\Phinx\Migration\Manager::class) + $managerStub = $this->getMockBuilder(Manager::class) ->setConstructorArgs([$this->config, $this->input, $this->output]) ->getMock(); @@ -259,7 +261,7 @@ public function testAlternativeTemplateFromConfigAndConsole() $this->configValues['templates']['seedFile'] = __DIR__ . '/Templates/SimpleSeeder.templateFromConfig.php.dist'; $this->config = new Config($this->configValues); /** @var Manager $managerStub mock the manager class */ - $managerStub = $this->getMockBuilder(\Phinx\Migration\Manager::class) + $managerStub = $this->getMockBuilder(Manager::class) ->setConstructorArgs([$this->config, $this->input, $this->output]) ->getMock(); diff --git a/tests/Phinx/Console/Command/SeedRunTest.php b/tests/Phinx/Console/Command/SeedRunTest.php index 6000f1189..9a6daa479 100644 --- a/tests/Phinx/Console/Command/SeedRunTest.php +++ b/tests/Phinx/Console/Command/SeedRunTest.php @@ -1,4 +1,5 @@ with(self::DEFAULT_TEST_ENVIRONMENT, null) ->will($this->returnValue(['hasMissingMigration' => false, 'hasDownMigration' => false])); - $this->config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $this->config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $command->setConfig($this->config); $command->setManager($managerStub); @@ -267,7 +268,7 @@ public function testExitCodeMissingMigrations() ->with(self::DEFAULT_TEST_ENVIRONMENT, null) ->will($this->returnValue(['hasMissingMigration' => true, 'hasDownMigration' => false])); - $this->config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $this->config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $command->setConfig($this->config); $command->setManager($managerStub); @@ -296,7 +297,7 @@ public function testExitCodeDownMigrations() ->with(self::DEFAULT_TEST_ENVIRONMENT, null) ->will($this->returnValue(['hasMissingMigration' => false, 'hasDownMigration' => true])); - $this->config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $this->config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $command->setConfig($this->config); $command->setManager($managerStub); @@ -325,7 +326,7 @@ public function testExitCodeMissingAndDownMigrations() ->with(self::DEFAULT_TEST_ENVIRONMENT, null) ->will($this->returnValue(['hasMissingMigration' => true, 'hasDownMigration' => true])); - $this->config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $this->config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $command->setConfig($this->config); $command->setManager($managerStub); diff --git a/tests/Phinx/Console/Command/TemplateGenerators/DoesNotImplementRequiredInterface.php b/tests/Phinx/Console/Command/TemplateGenerators/DoesNotImplementRequiredInterface.php index dfe660cc4..64746c728 100644 --- a/tests/Phinx/Console/Command/TemplateGenerators/DoesNotImplementRequiredInterface.php +++ b/tests/Phinx/Console/Command/TemplateGenerators/DoesNotImplementRequiredInterface.php @@ -1,4 +1,5 @@ message. */ -class RawBufferedOutput extends \Symfony\Component\Console\Output\BufferedOutput +class RawBufferedOutput extends BufferedOutput { /** * @param iterable|string $messages diff --git a/tests/Phinx/Console/PhinxApplicationTest.php b/tests/Phinx/Console/PhinxApplicationTest.php index 08c5c5b6b..aa6e36aa6 100644 --- a/tests/Phinx/Console/PhinxApplicationTest.php +++ b/tests/Phinx/Console/PhinxApplicationTest.php @@ -1,4 +1,5 @@ factory), 'getClass'); + $method = new ReflectionMethod(get_class($this->factory), 'getClass'); $method->setAccessible(true); $adapter = $method->invoke($this->factory, 'mysql'); @@ -70,7 +72,7 @@ public function testRegisterWrapper() { // WrapperFactory::getClass is protected, work around it to avoid // creating unnecessary instances and making the test more complex. - $method = new \ReflectionMethod(get_class($this->factory), 'getWrapperClass'); + $method = new ReflectionMethod(get_class($this->factory), 'getWrapperClass'); $method->setAccessible(true); $wrapper = $method->invoke($this->factory, 'proxy'); diff --git a/tests/Phinx/Db/Adapter/DataDomainTest.php b/tests/Phinx/Db/Adapter/DataDomainTest.php index 4c12a6bb2..dc35ee020 100644 --- a/tests/Phinx/Db/Adapter/DataDomainTest.php +++ b/tests/Phinx/Db/Adapter/DataDomainTest.php @@ -1,4 +1,5 @@ adapter->getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.0', '>='); + return version_compare($this->adapter->getAttribute(PDO::ATTR_SERVER_VERSION), '8.0.0', '>='); } public function testConnection() { $this->assertInstanceOf('PDO', $this->adapter->getConnection()); - $this->assertSame(\PDO::ERRMODE_EXCEPTION, $this->adapter->getConnection()->getAttribute(\PDO::ATTR_ERRMODE)); + $this->assertSame(PDO::ERRMODE_EXCEPTION, $this->adapter->getConnection()->getAttribute(PDO::ATTR_ERRMODE)); } public function testConnectionWithFetchMode() @@ -61,7 +67,7 @@ public function testConnectionWithFetchMode() $options['fetch_mode'] = 'assoc'; $this->adapter->setOptions($options); $this->assertInstanceOf('PDO', $this->adapter->getConnection()); - $this->assertSame(\PDO::FETCH_ASSOC, $this->adapter->getConnection()->getAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE)); + $this->assertSame(PDO::FETCH_ASSOC, $this->adapter->getConnection()->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE)); } public function testConnectionWithoutPort() @@ -80,7 +86,7 @@ public function testConnectionWithInvalidCredentials() $adapter = new MysqlAdapter($options, new ArrayInput([]), new NullOutput()); $adapter->connect(); $this->fail('Expected the adapter to throw an exception'); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertInstanceOf( 'InvalidArgumentException', $e, @@ -97,7 +103,7 @@ public function testConnectionWithSocketConnection() } $options = ['unix_socket' => getenv('MYSQL_UNIX_SOCKET')] + MYSQL_DB_CONFIG; - $adapter = new MysqlAdapter(MYSQL_DB_CONFIG, new ArrayInput([]), new NullOutput()); + $adapter = new MysqlAdapter($options, new ArrayInput([]), new NullOutput()); $adapter->connect(); $this->assertInstanceOf('\PDO', $this->adapter->getConnection()); @@ -117,7 +123,7 @@ public function testCreatingTheSchemaTableOnConnect() public function testSchemaTableIsCreatedWithPrimaryKey() { $this->adapter->connect(); - $table = new \Phinx\Db\Table($this->adapter->getSchemaTableName(), [], $this->adapter); + new Table($this->adapter->getSchemaTableName(), [], $this->adapter); $this->assertTrue($this->adapter->hasIndex($this->adapter->getSchemaTableName(), ['version'])); } @@ -149,7 +155,7 @@ public function testHasTableRespectsDotInTableName() public function testCreateTable() { - $table = new \Phinx\Db\Table('ntable', [], $this->adapter); + $table = new Table('ntable', [], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -168,7 +174,7 @@ public function testCreateTable() public function testCreateTableWithComment() { $tableComment = 'Table comment'; - $table = new \Phinx\Db\Table('ntable', ['comment' => $tableComment], $this->adapter); + $table = new Table('ntable', ['comment' => $tableComment], $this->adapter); $table->addColumn('realname', 'string') ->save(); $this->assertTrue($this->adapter->hasTable('ntable')); @@ -187,11 +193,11 @@ public function testCreateTableWithComment() public function testCreateTableWithForeignKeys() { - $tag_table = new \Phinx\Db\Table('ntable_tag', [], $this->adapter); + $tag_table = new Table('ntable_tag', [], $this->adapter); $tag_table->addColumn('realname', 'string') ->save(); - $table = new \Phinx\Db\Table('ntable', [], $this->adapter); + $table = new Table('ntable', [], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('tag_id', 'integer', ['signed' => false]) ->addForeignKey('tag_id', 'ntable_tag', 'id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) @@ -218,7 +224,7 @@ public function testCreateTableWithForeignKeys() public function testCreateTableCustomIdColumn() { - $table = new \Phinx\Db\Table('ntable', ['id' => 'custom_id'], $this->adapter); + $table = new Table('ntable', ['id' => 'custom_id'], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -234,7 +240,7 @@ public function testCreateTableWithNoPrimaryKey() $options = [ 'id' => false, ]; - $table = new \Phinx\Db\Table('atable', $options, $this->adapter); + $table = new Table('atable', $options, $this->adapter); $table->addColumn('user_id', 'integer') ->save(); $this->assertFalse($this->adapter->hasColumn('atable', 'id')); @@ -245,9 +251,9 @@ public function testCreateTableWithConflictingPrimaryKeys() $options = [ 'primary_key' => 'user_id', ]; - $table = new \Phinx\Db\Table('atable', $options, $this->adapter); + $table = new Table('atable', $options, $this->adapter); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('You cannot enable an auto incrementing ID field and a primary key'); $table->addColumn('user_id', 'integer')->save(); } @@ -257,7 +263,7 @@ public function testCreateTableWithPrimaryKeySetToImplicitId() $options = [ 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); @@ -269,7 +275,7 @@ public function testCreateTableWithPrimaryKeyArraySetToImplicitId() $options = [ 'primary_key' => ['id'], ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); @@ -281,8 +287,8 @@ public function testCreateTableWithMultiplePrimaryKeyArraySetToImplicitId() $options = [ 'primary_key' => ['id', 'user_id'], ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); - $this->expectException(\InvalidArgumentException::class); + $table = new Table('ztable', $options, $this->adapter); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('You cannot enable an auto incrementing ID field and a primary key'); $table->addColumn('user_id', 'integer')->save(); } @@ -293,7 +299,7 @@ public function testCreateTableWithMultiplePrimaryKeys() 'id' => false, 'primary_key' => ['user_id', 'tag_id'], ]; - $table = new \Phinx\Db\Table('table1', $options, $this->adapter); + $table = new Table('table1', $options, $this->adapter); $table->addColumn('user_id', 'integer', ['null' => false]) ->addColumn('tag_id', 'integer', ['null' => false]) ->save(); @@ -312,7 +318,7 @@ public function testCreateTableWithPrimaryKeyAsUuid() 'id' => false, 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('id', 'uuid', ['null' => false])->save(); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); @@ -329,7 +335,7 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid() 'id' => false, 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('id', 'binaryuuid', ['null' => false])->save(); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); @@ -339,7 +345,7 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid() public function testCreateTableWithMultipleIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('name', 'string') ->addIndex('email') @@ -353,7 +359,7 @@ public function testCreateTableWithMultipleIndexes() public function testCreateTableWithUniqueIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string', ['limit' => 191]) ->addIndex('email', ['unique' => true]) ->save(); @@ -363,7 +369,7 @@ public function testCreateTableWithUniqueIndexes() public function testCreateTableWithFullTextIndex() { - $table = new \Phinx\Db\Table('table1', ['engine' => 'MyISAM'], $this->adapter); + $table = new Table('table1', ['engine' => 'MyISAM'], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['type' => 'fulltext']) ->save(); @@ -373,7 +379,7 @@ public function testCreateTableWithFullTextIndex() public function testCreateTableWithNamedIndex() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailindex']) ->save(); @@ -389,7 +395,7 @@ public function testCreateTableWithMultiplePKsAndUniqueIndexes() public function testCreateTableWithMyISAMEngine() { - $table = new \Phinx\Db\Table('ntable', ['engine' => 'MyISAM'], $this->adapter); + $table = new Table('ntable', ['engine' => 'MyISAM'], $this->adapter); $table->addColumn('realname', 'string') ->save(); $this->assertTrue($this->adapter->hasTable('ntable')); @@ -410,7 +416,7 @@ public function testCreateTableAndInheritDefaultCollation() $adapter->createDatabase($options['name']); $adapter->disconnect(); - $table = new \Phinx\Db\Table('table_with_default_collation', [], $adapter); + $table = new Table('table_with_default_collation', [], $adapter); $table->addColumn('name', 'string') ->save(); $this->assertTrue($adapter->hasTable('table_with_default_collation')); @@ -420,7 +426,7 @@ public function testCreateTableAndInheritDefaultCollation() public function testCreateTableWithLatin1Collate() { - $table = new \Phinx\Db\Table('latin1_table', ['collation' => 'latin1_general_ci'], $this->adapter); + $table = new Table('latin1_table', ['collation' => 'latin1_general_ci'], $this->adapter); $table->addColumn('name', 'string') ->save(); $this->assertTrue($this->adapter->hasTable('latin1_table')); @@ -430,7 +436,7 @@ public function testCreateTableWithLatin1Collate() public function testCreateTableWithSignedPK() { - $table = new \Phinx\Db\Table('ntable', ['signed' => true], $this->adapter); + $table = new Table('ntable', ['signed' => true], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -449,7 +455,7 @@ public function testCreateTableWithSignedPK() public function testCreateTableWithUnsignedPK() { - $table = new \Phinx\Db\Table('ntable', ['signed' => false], $this->adapter); + $table = new Table('ntable', ['signed' => false], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -468,7 +474,7 @@ public function testCreateTableWithUnsignedPK() public function testCreateTableWithUnsignedNamedPK() { - $table = new \Phinx\Db\Table('ntable', ['id' => 'named_id', 'signed' => false], $this->adapter); + $table = new Table('ntable', ['id' => 'named_id', 'signed' => false], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -494,7 +500,7 @@ public function testUnsignedPksFeatureFlag() FeatureFlags::$unsignedPrimaryKeys = false; - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->create(); $columns = $this->adapter->getColumns('table1'); @@ -505,7 +511,7 @@ public function testUnsignedPksFeatureFlag() public function testCreateTableWithLimitPK() { - $table = new \Phinx\Db\Table('ntable', ['id' => 'id', 'limit' => 4], $this->adapter); + $table = new Table('ntable', ['id' => 'id', 'limit' => 4], $this->adapter); $table->save(); $this->assertTrue($this->adapter->hasTable('ntable')); $this->assertTrue($this->adapter->hasColumn('ntable', 'id')); @@ -515,7 +521,7 @@ public function testCreateTableWithLimitPK() public function testCreateTableWithSchema() { - $table = new \Phinx\Db\Table(MYSQL_DB_CONFIG['name'] . '.ntable', [], $this->adapter); + $table = new Table(MYSQL_DB_CONFIG['name'] . '.ntable', [], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -524,7 +530,7 @@ public function testCreateTableWithSchema() public function testAddPrimarykey() { - $table = new \Phinx\Db\Table('table1', ['id' => false], $this->adapter); + $table = new Table('table1', ['id' => false], $this->adapter); $table ->addColumn('column1', 'integer') ->save(); @@ -538,7 +544,7 @@ public function testAddPrimarykey() public function testChangePrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'integer', ['null' => false]) ->addColumn('column2', 'integer') @@ -555,7 +561,7 @@ public function testChangePrimaryKey() public function testDropPrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'integer', ['null' => false]) ->save(); @@ -569,7 +575,7 @@ public function testDropPrimaryKey() public function testAddComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table @@ -591,7 +597,7 @@ public function testAddComment() public function testChangeComment() { - $table = new \Phinx\Db\Table('table1', ['comment' => 'comment1'], $this->adapter); + $table = new Table('table1', ['comment' => 'comment1'], $this->adapter); $table->save(); $table @@ -613,7 +619,7 @@ public function testChangeComment() public function testDropComment() { - $table = new \Phinx\Db\Table('table1', ['comment' => 'comment1'], $this->adapter); + $table = new Table('table1', ['comment' => 'comment1'], $this->adapter); $table->save(); $table @@ -635,7 +641,7 @@ public function testDropComment() public function testRenameTable() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertTrue($this->adapter->hasTable('table1')); $this->assertFalse($this->adapter->hasTable('table2')); @@ -647,7 +653,7 @@ public function testRenameTable() public function testAddColumn() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('email')); $table->addColumn('email', 'string') @@ -661,7 +667,7 @@ public function testAddColumn() public function testAddColumnWithDefaultValue() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_zero', 'string', ['default' => 'test']) ->save(); @@ -671,7 +677,7 @@ public function testAddColumnWithDefaultValue() public function testAddColumnWithDefaultZero() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_zero', 'integer', ['default' => 0]) ->save(); @@ -682,7 +688,7 @@ public function testAddColumnWithDefaultZero() public function testAddColumnWithDefaultEmptyString() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_empty', 'string', ['default' => '']) ->save(); @@ -692,7 +698,7 @@ public function testAddColumnWithDefaultEmptyString() public function testAddColumnWithDefaultBoolean() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_true', 'boolean', ['default' => true]) ->addColumn('default_false', 'boolean', ['default' => false]) @@ -706,7 +712,7 @@ public function testAddColumnWithDefaultBoolean() public function testAddColumnWithDefaultLiteral() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_ts', 'timestamp', ['default' => Literal::from('CURRENT_TIMESTAMP')]) ->save(); @@ -730,7 +736,7 @@ public function testAddColumnWithCustomType() ], ]); - (new \Phinx\Db\Table('table1', [], $this->adapter)) + (new Table('table1', [], $this->adapter)) ->addColumn('custom1', 'custom1') ->addColumn('custom2', 'custom2') ->addColumn('custom_ext', 'custom2', [ @@ -764,7 +770,7 @@ public function testAddColumnWithCustomType() public function testAddColumnFirst() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('new_id', 'integer', ['after' => MysqlAdapter::FIRST]) ->save(); @@ -792,7 +798,7 @@ public function integerDataProvider() */ public function testIntegerColumnTypes($phinx_type, $options, $sql_type, $width, $extra) { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('user_id')); $table->addColumn('user_id', $phinx_type, $options) @@ -809,7 +815,7 @@ public function testIntegerColumnTypes($phinx_type, $options, $sql_type, $width, public function testAddDoubleColumnWithDefaultSigned() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('user_id')); $table->addColumn('foo', 'double') @@ -820,7 +826,7 @@ public function testAddDoubleColumnWithDefaultSigned() public function testAddDoubleColumnWithSignedEqualsFalse() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('user_id')); $table->addColumn('foo', 'double', ['signed' => false]) @@ -831,7 +837,7 @@ public function testAddDoubleColumnWithSignedEqualsFalse() public function testAddBooleanColumnWithSignedEqualsFalse() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('test_boolean')); $table->addColumn('test_boolean', 'boolean', ['signed' => false]) @@ -844,7 +850,7 @@ public function testAddBooleanColumnWithSignedEqualsFalse() public function testAddStringColumnWithSignedEqualsFalse() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('user_id')); $table->addColumn('user_id', 'string', ['signed' => false]) @@ -855,7 +861,7 @@ public function testAddStringColumnWithSignedEqualsFalse() public function testAddStringColumnWithCustomCollation() { - $table = new \Phinx\Db\Table('table_custom_collation', ['collation' => 'utf8mb4_unicode_ci'], $this->adapter); + $table = new Table('table_custom_collation', ['collation' => 'utf8mb4_unicode_ci'], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('string_collation_default')); $this->assertFalse($table->hasColumn('string_collation_custom')); @@ -868,7 +874,7 @@ public function testAddStringColumnWithCustomCollation() public function testRenameColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -881,7 +887,7 @@ public function testRenameColumn() public function testRenameColumnPreserveComment() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['comment' => 'comment1']) ->save(); @@ -900,14 +906,14 @@ public function testRenameColumnPreserveComment() public function testRenamingANonExistentColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); try { $table->renameColumn('column2', 'column1')->save(); $this->fail('Expected the adapter to throw an exception'); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertInstanceOf( 'InvalidArgumentException', $e, @@ -919,14 +925,14 @@ public function testRenamingANonExistentColumn() public function testChangeColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); $table->changeColumn('column1', 'string')->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); - $newColumn2 = new \Phinx\Db\Table\Column(); + $newColumn2 = new Column(); $newColumn2->setName('column2') ->setType('string'); $table->changeColumn('column1', $newColumn2)->save(); @@ -936,10 +942,10 @@ public function testChangeColumn() public function testChangeColumnDefaultValue() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['default' => 'test']) ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setDefault('test1') ->setType('string'); $table->changeColumn('column1', $newColumn1)->save(); @@ -950,10 +956,10 @@ public function testChangeColumnDefaultValue() public function testChangeColumnDefaultToZero() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer') ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setDefault(0) ->setType('integer'); $table->changeColumn('column1', $newColumn1)->save(); @@ -964,10 +970,10 @@ public function testChangeColumnDefaultToZero() public function testChangeColumnDefaultToNull() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['default' => 'test']) ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setDefault(null) ->setType('string'); $table->changeColumn('column1', $newColumn1)->save(); @@ -1018,7 +1024,7 @@ public function testGetSqlTypeIntegerConversion(string $type, $limit, string $ex public function testLongTextColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'text', ['limit' => MysqlAdapter::TEXT_LONG]) ->save(); $columns = $table->getColumns(); @@ -1028,7 +1034,7 @@ public function testLongTextColumn() public function testMediumTextColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'text', ['limit' => MysqlAdapter::TEXT_MEDIUM]) ->save(); $columns = $table->getColumns(); @@ -1038,7 +1044,7 @@ public function testMediumTextColumn() public function testTinyTextColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'text', ['limit' => MysqlAdapter::TEXT_TINY]) ->save(); $columns = $table->getColumns(); @@ -1064,7 +1070,7 @@ public function binaryToBlobAutomaticConversionData() /** @dataProvider binaryToBlobAutomaticConversionData */ public function testBinaryToBlobAutomaticConversion(?int $limit, string $expectedType, int $expectedLimit) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'binary', ['limit' => $limit]) ->save(); $columns = $table->getColumns(); @@ -1091,7 +1097,7 @@ public function varbinaryToBlobAutomaticConversionData() /** @dataProvider varbinaryToBlobAutomaticConversionData */ public function testVarbinaryToBlobAutomaticConversion(?int $limit, string $expectedType, int $expectedLimit) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'varbinary', ['limit' => $limit]) ->save(); $columns = $table->getColumns(); @@ -1133,7 +1139,7 @@ public function blobColumnsData() /** @dataProvider blobColumnsData */ public function testblobColumns(string $type, string $expectedType, ?int $limit, int $expectedLimit) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', $type, ['limit' => $limit]) ->save(); $columns = $table->getColumns(); @@ -1144,7 +1150,7 @@ public function testblobColumns(string $type, string $expectedType, ?int $limit, public function testBigIntegerColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer', ['limit' => MysqlAdapter::INT_BIG]) ->save(); $columns = $table->getColumns(); @@ -1154,7 +1160,7 @@ public function testBigIntegerColumn() public function testMediumIntegerColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer', ['limit' => MysqlAdapter::INT_MEDIUM]) ->save(); $columns = $table->getColumns(); @@ -1164,7 +1170,7 @@ public function testMediumIntegerColumn() public function testSmallIntegerColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer', ['limit' => MysqlAdapter::INT_SMALL]) ->save(); $columns = $table->getColumns(); @@ -1174,7 +1180,7 @@ public function testSmallIntegerColumn() public function testTinyIntegerColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer', ['limit' => MysqlAdapter::INT_TINY]) ->save(); $columns = $table->getColumns(); @@ -1185,7 +1191,7 @@ public function testTinyIntegerColumn() public function testIntegerColumnLimit() { $limit = 8; - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer', ['limit' => $limit]) ->save(); $columns = $table->getColumns(); @@ -1196,10 +1202,10 @@ public function testIntegerColumnLimit() public function testDatetimeColumn() { $this->adapter->connect(); - if (version_compare($this->adapter->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { + if (version_compare($this->adapter->getAttribute(PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { $this->markTestSkipped('Cannot test datetime limit on versions less than 5.6.4'); } - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'datetime')->save(); $columns = $table->getColumns(); $sqlType = $this->adapter->getSqlType($columns[1]->getType(), $columns[1]->getLimit()); @@ -1209,11 +1215,11 @@ public function testDatetimeColumn() public function testDatetimeColumnLimit() { $this->adapter->connect(); - if (version_compare($this->adapter->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { + if (version_compare($this->adapter->getAttribute(PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { $this->markTestSkipped('Cannot test datetime limit on versions less than 5.6.4'); } $limit = 6; - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'datetime', ['limit' => $limit])->save(); $columns = $table->getColumns(); $sqlType = $this->adapter->getSqlType($columns[1]->getType(), $columns[1]->getLimit()); @@ -1223,11 +1229,11 @@ public function testDatetimeColumnLimit() public function testTimeColumnLimit() { $this->adapter->connect(); - if (version_compare($this->adapter->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { + if (version_compare($this->adapter->getAttribute(PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { $this->markTestSkipped('Cannot test datetime limit on versions less than 5.6.4'); } $limit = 3; - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'time', ['limit' => $limit])->save(); $columns = $table->getColumns(); $sqlType = $this->adapter->getSqlType($columns[1]->getType(), $columns[1]->getLimit()); @@ -1237,11 +1243,11 @@ public function testTimeColumnLimit() public function testTimestampColumnLimit() { $this->adapter->connect(); - if (version_compare($this->adapter->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { + if (version_compare($this->adapter->getAttribute(PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { $this->markTestSkipped('Cannot test datetime limit on versions less than 5.6.4'); } $limit = 1; - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'timestamp', ['limit' => $limit])->save(); $columns = $table->getColumns(); $sqlType = $this->adapter->getSqlType($columns[1]->getType(), $columns[1]->getLimit()); @@ -1251,10 +1257,10 @@ public function testTimestampColumnLimit() public function testTimestampInvalidLimit() { $this->adapter->connect(); - if (version_compare($this->adapter->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { + if (version_compare($this->adapter->getAttribute(PDO::ATTR_SERVER_VERSION), '5.6.4') === -1) { $this->markTestSkipped('Cannot test datetime limit on versions less than 5.6.4'); } - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $this->expectException(PDOException::class); @@ -1263,7 +1269,7 @@ public function testTimestampInvalidLimit() public function testDropColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -1311,7 +1317,7 @@ public function columnsProvider() */ public function testGetColumns($colName, $type, $options) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn($colName, $type, $options)->save(); $columns = $this->adapter->getColumns('t'); @@ -1345,7 +1351,7 @@ public function testGetColumnsInteger() $colName = 'column15'; $type = 'integer'; $options = ['limit' => 10]; - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn($colName, $type, $options)->save(); $columns = $this->adapter->getColumns('t'); @@ -1358,7 +1364,7 @@ public function testGetColumnsInteger() public function testDescribeTable() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string'); $table->save(); @@ -1372,7 +1378,7 @@ public function testDescribeTable() public function testGetColumnsReservedTableName() { - $table = new \Phinx\Db\Table('group', [], $this->adapter); + $table = new Table('group', [], $this->adapter); $table->addColumn('column1', 'string')->save(); $columns = $this->adapter->getColumns('group'); $this->assertCount(2, $columns); @@ -1380,7 +1386,7 @@ public function testGetColumnsReservedTableName() public function testAddIndex() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->save(); $this->assertFalse($table->hasIndex('email')); @@ -1395,7 +1401,7 @@ public function testAddIndexWithSort() if (!$this->usingMysql8()) { $this->markTestSkipped('Cannot test index order on mysql versions less than 8'); } - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('username', 'string') ->save(); @@ -1414,7 +1420,7 @@ public function testAddIndexWithSort() public function testAddMultipleFulltextIndex() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('username', 'string') ->addColumn('bio', 'text') @@ -1435,7 +1441,7 @@ public function testAddMultipleFulltextIndex() public function testAddIndexWithLimit() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->save(); $this->assertFalse($table->hasIndex('email')); @@ -1445,14 +1451,14 @@ public function testAddIndexWithLimit() $index_data = $this->adapter->query(sprintf( 'SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "%s" AND TABLE_NAME = "table1" AND INDEX_NAME = "email"', MYSQL_DB_CONFIG['name'] - ))->fetch(\PDO::FETCH_ASSOC); + ))->fetch(PDO::FETCH_ASSOC); $expected_limit = $index_data['SUB_PART']; $this->assertEquals($expected_limit, 50); } public function testAddMultiIndexesWithLimitSpecifier() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('username', 'string') ->save(); @@ -1463,20 +1469,20 @@ public function testAddMultiIndexesWithLimitSpecifier() $index_data = $this->adapter->query(sprintf( 'SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "%s" AND TABLE_NAME = "table1" AND INDEX_NAME = "email" AND COLUMN_NAME = "email"', MYSQL_DB_CONFIG['name'] - ))->fetch(\PDO::FETCH_ASSOC); + ))->fetch(PDO::FETCH_ASSOC); $expected_limit = $index_data['SUB_PART']; $this->assertEquals($expected_limit, 3); $index_data = $this->adapter->query(sprintf( 'SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "%s" AND TABLE_NAME = "table1" AND INDEX_NAME = "email" AND COLUMN_NAME = "username"', MYSQL_DB_CONFIG['name'] - ))->fetch(\PDO::FETCH_ASSOC); + ))->fetch(PDO::FETCH_ASSOC); $expected_limit = $index_data['SUB_PART']; $this->assertEquals($expected_limit, 2); } public function testAddSingleIndexesWithLimitSpecifier() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('username', 'string') ->save(); @@ -1487,7 +1493,7 @@ public function testAddSingleIndexesWithLimitSpecifier() $index_data = $this->adapter->query(sprintf( 'SELECT SUB_PART FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = "%s" AND TABLE_NAME = "table1" AND INDEX_NAME = "email" AND COLUMN_NAME = "email"', MYSQL_DB_CONFIG['name'] - ))->fetch(\PDO::FETCH_ASSOC); + ))->fetch(PDO::FETCH_ASSOC); $expected_limit = $index_data['SUB_PART']; $this->assertEquals($expected_limit, 3); } @@ -1495,7 +1501,7 @@ public function testAddSingleIndexesWithLimitSpecifier() public function testDropIndex() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email') ->save(); @@ -1504,7 +1510,7 @@ public function testDropIndex() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname']) @@ -1514,7 +1520,7 @@ public function testDropIndex() $this->assertFalse($table2->hasIndex(['fname', 'lname'])); // index with name specified, but dropping it by column name - $table3 = new \Phinx\Db\Table('table3', [], $this->adapter); + $table3 = new Table('table3', [], $this->adapter); $table3->addColumn('email', 'string') ->addIndex('email', ['name' => 'someindexname']) ->save(); @@ -1523,7 +1529,7 @@ public function testDropIndex() $this->assertFalse($table3->hasIndex('email')); // multiple column index with name specified - $table4 = new \Phinx\Db\Table('table4', [], $this->adapter); + $table4 = new Table('table4', [], $this->adapter); $table4->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname'], ['name' => 'multiname']) @@ -1533,7 +1539,7 @@ public function testDropIndex() $this->assertFalse($table4->hasIndex(['fname', 'lname'])); // don't drop multiple column index when dropping single column - $table2 = new \Phinx\Db\Table('table5', [], $this->adapter); + $table2 = new Table('table5', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname']) @@ -1542,13 +1548,13 @@ public function testDropIndex() try { $table2->removeIndex(['fname'])->save(); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { } $this->assertTrue($table2->hasIndex(['fname', 'lname'])); // don't drop multiple column index with name specified when dropping // single column - $table4 = new \Phinx\Db\Table('table6', [], $this->adapter); + $table4 = new Table('table6', [], $this->adapter); $table4->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname'], ['name' => 'multiname']) @@ -1557,7 +1563,7 @@ public function testDropIndex() try { $table4->removeIndex(['fname'])->save(); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { } $this->assertTrue($table4->hasIndex(['fname', 'lname'])); @@ -1566,7 +1572,7 @@ public function testDropIndex() public function testDropIndexByName() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailindex']) ->save(); @@ -1575,7 +1581,7 @@ public function testDropIndexByName() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname'], ['name' => 'twocolumnindex']) @@ -1587,10 +1593,10 @@ public function testDropIndexByName() public function testAddForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer', ['signed' => false]) ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1601,10 +1607,10 @@ public function testAddForeignKey() public function testAddForeignKeyForTableWithSignedPK() { - $refTable = new \Phinx\Db\Table('ref_table', ['signed' => true], $this->adapter); + $refTable = new Table('ref_table', ['signed' => true], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1615,10 +1621,10 @@ public function testAddForeignKeyForTableWithSignedPK() public function testDropForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer', ['signed' => false]) ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1630,10 +1636,10 @@ public function testDropForeignKey() public function testDropForeignKeyForTableWithSignedPK() { - $refTable = new \Phinx\Db\Table('ref_table', ['signed' => true], $this->adapter); + $refTable = new Table('ref_table', ['signed' => true], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1645,10 +1651,10 @@ public function testDropForeignKeyForTableWithSignedPK() public function testDropForeignKeyAsString() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer', ['signed' => false]) ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1660,10 +1666,10 @@ public function testDropForeignKeyAsString() public function testHasForeignKeyAsString() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer', ['signed' => false]) ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1675,10 +1681,10 @@ public function testHasForeignKeyAsString() public function testHasForeignKeyWithConstraint() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer', ['signed' => false]) ->addForeignKeyWithName('my_constraint', ['ref_table_id'], 'ref_table', ['id']) @@ -1690,10 +1696,10 @@ public function testHasForeignKeyWithConstraint() public function testHasForeignKeyWithConstraintForTableWithSignedPK() { - $refTable = new \Phinx\Db\Table('ref_table', ['signed' => true], $this->adapter); + $refTable = new Table('ref_table', ['signed' => true], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKeyWithName('my_constraint', ['ref_table_id'], 'ref_table', ['id']) @@ -1705,10 +1711,10 @@ public function testHasForeignKeyWithConstraintForTableWithSignedPK() public function testsHasForeignKeyWithSchemaDotTableName() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer', ['signed' => false]) ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1734,7 +1740,7 @@ public function testDropDatabase() public function testAddColumnWithComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string', ['comment' => $comment = 'Comments from "column1"']) ->save(); @@ -1753,7 +1759,7 @@ public function testAddColumnWithComment() public function testAddGeoSpatialColumns() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('geo_geom')); $table->addColumn('geo_geom', 'geometry') @@ -1764,7 +1770,7 @@ public function testAddGeoSpatialColumns() public function testAddSetColumn() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('set_column')); $table->addColumn('set_column', 'set', ['values' => ['one', 'two']]) @@ -1775,7 +1781,7 @@ public function testAddSetColumn() public function testAddEnumColumn() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('enum_column')); $table->addColumn('enum_column', 'enum', ['values' => ['one', 'two']]) @@ -1787,12 +1793,12 @@ public function testAddEnumColumn() public function testEnumColumnValuesFilledUpFromSchema() { // Creating column with values - (new \Phinx\Db\Table('table1', [], $this->adapter)) + (new Table('table1', [], $this->adapter)) ->addColumn('enum_column', 'enum', ['values' => ['one', 'two']]) ->save(); // Reading them back - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $columns = $table->getColumns(); $enumColumn = end($columns); $this->assertEquals(AdapterInterface::PHINX_TYPE_ENUM, $enumColumn->getType()); @@ -1801,7 +1807,7 @@ public function testEnumColumnValuesFilledUpFromSchema() public function testEnumColumnWithNullValue() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('enum_column', 'enum', ['values' => ['one', 'two', null]]); $this->expectException(PDOException::class); @@ -1810,7 +1816,7 @@ public function testEnumColumnWithNullValue() public function testHasColumn() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); @@ -1820,7 +1826,7 @@ public function testHasColumn() public function testHasColumnReservedName() { - $tableQuoted = new \Phinx\Db\Table('group', [], $this->adapter); + $tableQuoted = new Table('group', [], $this->adapter); $tableQuoted->addColumn('value', 'string') ->save(); @@ -1844,7 +1850,7 @@ public function testBulkInsertData() 'column2' => 3, ], ]; - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->addColumn('column3', 'string', ['default' => 'test']) @@ -1879,7 +1885,7 @@ public function testInsertData() 'column3' => 'foo', ], ]; - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->addColumn('column3', 'string', ['default' => 'test']) @@ -1905,7 +1911,7 @@ public function testDumpCreateTable() $consoleOutput = new BufferedOutput(); $this->adapter->setOutput($consoleOutput); - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string', ['null' => false]) ->addColumn('column2', 'integer') @@ -1926,7 +1932,7 @@ public function testDumpCreateTable() */ public function testDumpInsert() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -1975,7 +1981,7 @@ public function testDumpInsert() */ public function testDumpBulkinsert() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -2017,13 +2023,13 @@ public function testDumpCreateTableAndThenInsert() $consoleOutput = new BufferedOutput(); $this->adapter->setOutput($consoleOutput); - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => ['column1']], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => ['column1']], $this->adapter); $table->addColumn('column1', 'string', ['null' => false]) ->addColumn('column2', 'integer') ->save(); - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->insert([ 'column1' => 'id1', 'column2' => 1, @@ -2049,7 +2055,7 @@ public function testDumpTransaction() $this->adapter->setOutput($consoleOutput); $this->adapter->beginTransaction(); - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') @@ -2070,7 +2076,7 @@ public function testDumpTransaction() */ public function testQueryBuilder() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -2109,7 +2115,7 @@ public function testQueryBuilder() public function testQueryWithParams() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -2144,7 +2150,7 @@ public function testLiteralSupport() CREATE TABLE `test` (`double_col` double NOT NULL) INPUT; $this->adapter->execute($createQuery); - $table = new \Phinx\Db\Table('test', [], $this->adapter); + $table = new Table('test', [], $this->adapter); $columns = $table->getColumns(); $this->assertCount(1, $columns); $this->assertEquals(Literal::from('double'), array_pop($columns)->getType()); @@ -2172,7 +2178,7 @@ public function testGeometrySridSupport($type, $geom) $this->markTestSkipped('Cannot test geometry srid on mysql versions less than 8'); } - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table ->addColumn('geom', $type, ['srid' => 4326]) ->save(); @@ -2196,7 +2202,7 @@ public function testGeometrySridThrowsInsertDifferentSrid($type, $geom) $this->markTestSkipped('Cannot test geometry srid on mysql versions less than 8'); } - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table ->addColumn('geom', $type, ['srid' => 4326]) ->save(); @@ -2213,7 +2219,7 @@ public function testGeometrySridThrowsInsertDifferentSrid($type, $geom) */ public function testMysqlBlobsConstants() { - $reflector = new \ReflectionClass(AdapterInterface::class); + $reflector = new ReflectionClass(AdapterInterface::class); $validTypes = array_filter($reflector->getConstants(), function ($constant) { return substr($constant, 0, strlen('PHINX_TYPE_')) === 'PHINX_TYPE_'; @@ -2250,7 +2256,7 @@ public function testDefaultsCastAsExpressionsForCertainTypes(string $type, strin { $this->adapter->connect(); - $table = new \Phinx\Db\Table('table1', ['id' => false], $this->adapter); + $table = new Table('table1', ['id' => false], $this->adapter); if (!$this->usingMysql8()) { $this->expectException(PDOException::class); } @@ -2267,7 +2273,7 @@ public function testDefaultsCastAsExpressionsForCertainTypes(string $type, strin public function testCreateTableWithPrecisionCurrentTimestamp() { $this->adapter->connect(); - (new \Phinx\Db\Table('exampleCurrentTimestamp3', ['id' => false], $this->adapter)) + (new Table('exampleCurrentTimestamp3', ['id' => false], $this->adapter)) ->addColumn('timestamp_3', 'timestamp', [ 'null' => false, 'default' => 'CURRENT_TIMESTAMP(3)', @@ -2297,7 +2303,7 @@ public function pdoAttributeProvider() public function testInvalidPdoAttribute($attribute) { $adapter = new MysqlAdapter(MYSQL_DB_CONFIG + [$attribute => true]); - $this->expectException(\UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Invalid PDO attribute: ' . $attribute . ' (\PDO::' . strtoupper($attribute) . ')'); $adapter->connect(); } @@ -2344,12 +2350,12 @@ public function testGetPhinxTypeFromSQLDefinition(string $sqlDefinition, array $ public function testPdoPersistentConnection() { $adapter = new MysqlAdapter(MYSQL_DB_CONFIG + ['attr_persistent' => true]); - $this->assertTrue($adapter->getConnection()->getAttribute(\PDO::ATTR_PERSISTENT)); + $this->assertTrue($adapter->getConnection()->getAttribute(PDO::ATTR_PERSISTENT)); } public function testPdoNotPersistentConnection() { $adapter = new MysqlAdapter(MYSQL_DB_CONFIG); - $this->assertFalse($adapter->getConnection()->getAttribute(\PDO::ATTR_PERSISTENT)); + $this->assertFalse($adapter->getConnection()->getAttribute(PDO::ATTR_PERSISTENT)); } } diff --git a/tests/Phinx/Db/Adapter/PdoAdapterTest.php b/tests/Phinx/Db/Adapter/PdoAdapterTest.php index 623201b04..efd880b36 100644 --- a/tests/Phinx/Db/Adapter/PdoAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PdoAdapterTest.php @@ -1,9 +1,11 @@ [ - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, 'version ASC', + Config::VERSION_ORDER_CREATION_TIME, 'version ASC', ], 'With Execution Time Version Order' => [ - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, 'start_time ASC, version ASC', + Config::VERSION_ORDER_EXECUTION_TIME, 'start_time ASC, version ASC', ], ]; } @@ -147,7 +149,7 @@ public function testGetVersionLongDryRun() { $adapter = $this->getMockForAbstractClass( '\Phinx\Db\Adapter\PdoAdapter', - [['version_order' => \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME]], + [['version_order' => Config::VERSION_ORDER_CREATION_TIME]], '', true, true, diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index 005325d48..851b628ff 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -1,11 +1,17 @@ adapter->getConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION), '10.0.0', '>='); + return version_compare($this->adapter->getConnection()->getAttribute(PDO::ATTR_SERVER_VERSION), '10.0.0', '>='); } public function testConnection() { $this->assertInstanceOf('PDO', $this->adapter->getConnection()); - $this->assertSame(\PDO::ERRMODE_EXCEPTION, $this->adapter->getConnection()->getAttribute(\PDO::ATTR_ERRMODE)); + $this->assertSame(PDO::ERRMODE_EXCEPTION, $this->adapter->getConnection()->getAttribute(PDO::ATTR_ERRMODE)); } public function testConnectionWithFetchMode() @@ -86,7 +93,7 @@ public function testConnectionWithFetchMode() $options['fetch_mode'] = 'assoc'; $this->adapter->setOptions($options); $this->assertInstanceOf('PDO', $this->adapter->getConnection()); - $this->assertSame(\PDO::FETCH_ASSOC, $this->adapter->getConnection()->getAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE)); + $this->assertSame(PDO::FETCH_ASSOC, $this->adapter->getConnection()->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE)); } public function testConnectionWithoutPort() @@ -105,7 +112,7 @@ public function testConnectionWithInvalidCredentials() $adapter = new PostgresAdapter($options, new ArrayInput([]), new NullOutput()); $adapter->connect(); $this->fail('Expected the adapter to throw an exception'); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertInstanceOf( 'InvalidArgumentException', $e, @@ -143,7 +150,7 @@ public function testCreatingTheSchemaTableOnConnect() public function testSchemaTableIsCreatedWithPrimaryKey() { $this->adapter->connect(); - $table = new \Phinx\Db\Table($this->adapter->getSchemaTableName(), [], $this->adapter); + new Table($this->adapter->getSchemaTableName(), [], $this->adapter); $this->assertTrue($this->adapter->hasIndex($this->adapter->getSchemaTableName(), ['version'])); } @@ -167,7 +174,7 @@ public function testQuoteColumnName() public function testCreateTable() { - $table = new \Phinx\Db\Table('ntable', [], $this->adapter); + $table = new Table('ntable', [], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -182,7 +189,7 @@ public function testCreateTableWithSchema() { $this->adapter->createSchema('nschema'); - $table = new \Phinx\Db\Table('nschema.ntable', [], $this->adapter); + $table = new Table('nschema.ntable', [], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -197,7 +204,7 @@ public function testCreateTableWithSchema() public function testCreateTableCustomIdColumn() { - $table = new \Phinx\Db\Table('ntable', ['id' => 'custom_id'], $this->adapter); + $table = new Table('ntable', ['id' => 'custom_id'], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -213,7 +220,7 @@ public function testCreateTableWithNoPrimaryKey() $options = [ 'id' => false, ]; - $table = new \Phinx\Db\Table('atable', $options, $this->adapter); + $table = new Table('atable', $options, $this->adapter); $table->addColumn('user_id', 'integer') ->save(); $this->assertFalse($this->adapter->hasColumn('atable', 'id')); @@ -224,9 +231,9 @@ public function testCreateTableWithConflictingPrimaryKeys() $options = [ 'primary_key' => 'user_id', ]; - $table = new \Phinx\Db\Table('atable', $options, $this->adapter); + $table = new Table('atable', $options, $this->adapter); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('You cannot enable an auto incrementing ID field and a primary key'); $table->addColumn('user_id', 'integer')->save(); } @@ -236,7 +243,7 @@ public function testCreateTableWithPrimaryKeySetToImplicitId() $options = [ 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); @@ -248,7 +255,7 @@ public function testCreateTableWithPrimaryKeyArraySetToImplicitId() $options = [ 'primary_key' => ['id'], ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); @@ -260,8 +267,8 @@ public function testCreateTableWithMultiplePrimaryKeyArraySetToImplicitId() $options = [ 'primary_key' => ['id', 'user_id'], ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); - $this->expectException(\InvalidArgumentException::class); + $table = new Table('ztable', $options, $this->adapter); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('You cannot enable an auto incrementing ID field and a primary key'); $table->addColumn('user_id', 'integer')->save(); } @@ -272,7 +279,7 @@ public function testCreateTableWithMultiplePrimaryKeys() 'id' => false, 'primary_key' => ['user_id', 'tag_id'], ]; - $table = new \Phinx\Db\Table('table1', $options, $this->adapter); + $table = new Table('table1', $options, $this->adapter); $table->addColumn('user_id', 'integer') ->addColumn('tag_id', 'integer') ->save(); @@ -289,7 +296,7 @@ public function testCreateTableWithMultiplePrimaryKeysWithSchema() 'id' => false, 'primary_key' => ['user_id', 'tag_id'], ]; - $table = new \Phinx\Db\Table('schema1.table1', $options, $this->adapter); + $table = new Table('schema1.table1', $options, $this->adapter); $table->addColumn('user_id', 'integer') ->addColumn('tag_id', 'integer') ->save(); @@ -309,7 +316,7 @@ public function testCreateTableWithPrimaryKeyAsUuid() 'id' => false, 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('id', 'uuid')->save(); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); @@ -326,7 +333,7 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid() 'id' => false, 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('id', 'binaryuuid')->save(); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); @@ -336,7 +343,7 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid() public function testCreateTableWithMultipleIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('name', 'string') ->addIndex('email') @@ -350,7 +357,7 @@ public function testCreateTableWithMultipleIndexes() public function testCreateTableWithUniqueIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['unique' => true]) ->save(); @@ -360,7 +367,7 @@ public function testCreateTableWithUniqueIndexes() public function testCreateTableWithFullTextSearchIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('names', 'jsonb') ->addIndex('names', ['type' => 'gin']) ->save(); @@ -370,7 +377,7 @@ public function testCreateTableWithFullTextSearchIndexes() public function testCreateTableWithNamedIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailindex']) ->save(); @@ -381,7 +388,7 @@ public function testCreateTableWithNamedIndexes() public function testAddPrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false], $this->adapter); + $table = new Table('table1', ['id' => false], $this->adapter); $table ->addColumn('column1', 'integer') ->save(); @@ -395,7 +402,7 @@ public function testAddPrimaryKey() public function testChangePrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'integer') ->addColumn('column2', 'integer') @@ -412,7 +419,7 @@ public function testChangePrimaryKey() public function testDropPrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'integer') ->save(); @@ -426,7 +433,7 @@ public function testDropPrimaryKey() public function testAddComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table @@ -447,7 +454,7 @@ public function testAddComment() public function testChangeComment() { - $table = new \Phinx\Db\Table('table1', ['comment' => 'comment1'], $this->adapter); + $table = new Table('table1', ['comment' => 'comment1'], $this->adapter); $table->save(); $table @@ -468,7 +475,7 @@ public function testChangeComment() public function testDropComment() { - $table = new \Phinx\Db\Table('table1', ['comment' => 'comment1'], $this->adapter); + $table = new Table('table1', ['comment' => 'comment1'], $this->adapter); $table->save(); $table @@ -489,7 +496,7 @@ public function testDropComment() public function testRenameTable() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertTrue($this->adapter->hasTable('table1')); $this->assertFalse($this->adapter->hasTable('table2')); @@ -503,7 +510,7 @@ public function testRenameTableWithSchema() { $this->adapter->createSchema('schema1'); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->save(); $this->assertTrue($this->adapter->hasTable('schema1.table1')); $this->assertFalse($this->adapter->hasTable('schema1.table2')); @@ -516,7 +523,7 @@ public function testRenameTableWithSchema() public function testAddColumn() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('email')); $table->addColumn('email', 'string') @@ -526,7 +533,7 @@ public function testAddColumn() public function testAddColumnWithDefaultValue() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_zero', 'string', ['default' => 'test']) ->save(); @@ -540,7 +547,7 @@ public function testAddColumnWithDefaultValue() public function testAddColumnWithDefaultZero() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_zero', 'integer', ['default' => 0]) ->save(); @@ -558,7 +565,7 @@ public function testAddColumnWithAutoIdentity() if (!$this->usingPostgres10()) { $this->markTestSkipped('Test Skipped because of PostgreSQL version is < 10.0'); } - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $columns = $this->adapter->getColumns('table1'); foreach ($columns as $column) { @@ -586,7 +593,7 @@ public function testAddColumnIdentity($generated, $addToColumn) if (!$this->usingPostgres10()) { $this->markTestSkipped('Test Skipped because of PostgreSQL version is < 10.0'); } - $table = new \Phinx\Db\Table('table1', ['id' => false], $this->adapter); + $table = new Table('table1', ['id' => false], $this->adapter); $table->save(); $options = ['identity' => true]; if ($addToColumn !== false) { @@ -605,7 +612,7 @@ public function testAddColumnIdentity($generated, $addToColumn) public function testAddColumnWithDefaultBoolean() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_true', 'boolean', ['default' => true]) ->addColumn('default_false', 'boolean', ['default' => false]) @@ -629,7 +636,7 @@ public function testAddColumnWithDefaultBoolean() public function testAddColumnWithBooleanIgnoreLimitCastDefault() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('limit_bool_true', 'boolean', [ 'default' => 1, @@ -679,7 +686,7 @@ public function providerIgnoresLimit(): array */ public function testAddColumnIgnoresLimit(string $column_type, ?string $actual_type = null): void { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('column1', $column_type, ['limit' => 1]); $table->save(); @@ -694,7 +701,7 @@ public function testAddColumnIgnoresLimit(string $column_type, ?string $actual_t public function testAddColumnWithDefaultLiteral() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_ts', 'timestamp', ['default' => Literal::from('now()')]) ->save(); @@ -709,7 +716,7 @@ public function testAddColumnWithDefaultLiteral() public function testAddColumnWithLiteralType() { - $table = new \Phinx\Db\Table('citable', ['id' => false], $this->adapter); + $table = new Table('citable', ['id' => false], $this->adapter); $table ->addColumn('insensitive', Literal::from('citext')) ->save(); @@ -731,7 +738,7 @@ public function testAddColumnWithLiteralType() public function testAddColumnWithComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('email')); @@ -761,7 +768,7 @@ public function testAddColumnWithComment() public function testAddStringWithLimit() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('string1', 'string', ['limit' => 10]) ->addColumn('char1', 'char', ['limit' => 20]) @@ -780,7 +787,7 @@ public function testAddStringWithLimit() public function testAddDecimalWithPrecisionAndScale() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('number', 'decimal', ['precision' => 10, 'scale' => 2]) ->addColumn('number2', 'decimal', ['limit' => 12]) @@ -802,7 +809,7 @@ public function testAddDecimalWithPrecisionAndScale() public function testAddTimestampWithPrecision() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('timestamp1', 'timestamp', ['precision' => 0]) ->addColumn('timestamp2', 'timestamp', ['precision' => 4]) @@ -849,7 +856,7 @@ public function providerArrayType() */ public function testAddColumnArrayType($column_name, $column_type) { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn($column_name)); $table->addColumn($column_name, $column_type) @@ -866,7 +873,7 @@ public function testAddColumnWithCustomType() ], ]); - (new \Phinx\Db\Table('table1', [], $this->adapter)) + (new Table('table1', [], $this->adapter)) ->addColumn('custom', 'custom') ->addColumn('custom_ext', 'custom', [ 'null' => false, @@ -892,7 +899,7 @@ public function testAddColumnWithCustomType() public function testRenameColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -904,7 +911,7 @@ public function testRenameColumn() public function testRenameColumnIsCaseSensitive() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('columnOne', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'columnOne')); @@ -916,14 +923,14 @@ public function testRenameColumnIsCaseSensitive() public function testRenamingANonExistentColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); try { $this->adapter->renameColumn('t', 'column2', 'column1'); $this->fail('Expected the adapter to throw an exception'); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertInstanceOf( 'InvalidArgumentException', $e, @@ -935,14 +942,14 @@ public function testRenamingANonExistentColumn() public function testChangeColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); $table->changeColumn('column1', 'string')->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); - $newColumn2 = new \Phinx\Db\Table\Column(); + $newColumn2 = new Column(); $newColumn2->setName('column2') ->setType('string'); $table->changeColumn('column1', $newColumn2)->save(); @@ -966,7 +973,7 @@ public function testChangeColumnIdentity($generated) if (!$this->usingPostgres10()) { $this->markTestSkipped('Test Skipped because of PostgreSQL version is < 10.0'); } - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'integer'); $table->save(); @@ -986,7 +993,7 @@ public function testChangeColumnDropIdentity() if (!$this->usingPostgres10()) { $this->markTestSkipped('Test Skipped because of PostgreSQL version is < 10.0'); } - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->changeColumn('id', 'integer', ['identity' => false]); $table->save(); @@ -1003,7 +1010,7 @@ public function testChangeColumnChangeIdentity() if (!$this->usingPostgres10()) { $this->markTestSkipped('Test Skipped because of PostgreSQL version is < 10.0'); } - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->changeColumn('id', 'integer', ['identity' => true, 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT]); $table->save(); @@ -1030,7 +1037,7 @@ public function integersProvider() */ public function testChangeColumnFromTextToInteger($type, $value) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'text') ->insert(['column1' => (string)$value]) ->save(); @@ -1045,7 +1052,7 @@ public function testChangeColumnFromTextToInteger($type, $value) public function testChangeBooleanOptions() { - $table = new \Phinx\Db\Table('t', ['id' => false], $this->adapter); + $table = new Table('t', ['id' => false], $this->adapter); $table->addColumn('my_bool', 'boolean', ['default' => true, 'null' => true]) ->create(); $table @@ -1068,7 +1075,7 @@ public function testChangeBooleanOptions() public function testChangeColumnFromIntegerToBoolean() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer', ['default' => 0]) ->save(); $table->changeColumn('column1', 'boolean', ['default' => 't', 'null' => true]) @@ -1084,7 +1091,7 @@ public function testChangeColumnFromIntegerToBoolean() public function testChangeColumnCharToUuid() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'char', ['default' => null, 'limit' => 36]) ->save(); $table->changeColumn('column1', 'uuid', ['default' => null, 'null' => true]) @@ -1102,11 +1109,11 @@ public function testChangeColumnCharToUuid() public function testChangeColumnWithDefault() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setName('column1') ->setType('string') ->setNull(true); @@ -1125,7 +1132,7 @@ public function testChangeColumnWithDefault() public function testChangeColumnWithDropDefault() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['default' => 'Test']) ->save(); @@ -1136,7 +1143,7 @@ public function testChangeColumnWithDropDefault() } } - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setName('column1') ->setType('string'); @@ -1152,7 +1159,7 @@ public function testChangeColumnWithDropDefault() public function testDropColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -1190,7 +1197,7 @@ public function columnsProvider() */ public function testGetColumns($colName, $type, $options, $actualType = null) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn($colName, $type, $options)->save(); $columns = $this->adapter->getColumns('t'); @@ -1215,7 +1222,7 @@ public function testGetColumnsWithSchema($colName, $type, $options, $actualType { $this->adapter->createSchema('tschema'); - $table = new \Phinx\Db\Table('tschema.t', [], $this->adapter); + $table = new Table('tschema.t', [], $this->adapter); $table->addColumn($colName, $type, $options)->save(); $columns = $this->adapter->getColumns('tschema.t'); @@ -1237,7 +1244,7 @@ public function testGetColumnsWithSchema($colName, $type, $options, $actualType public function testAddIndex() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->save(); $this->assertFalse($table->hasIndex('email')); @@ -1248,7 +1255,7 @@ public function testAddIndex() public function testAddIndexWithSort() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('username', 'string') ->save(); @@ -1294,7 +1301,7 @@ public function testAddIndexWithIncludeColumns() $this->markTestSkipped('Cannot test index include collumns (non-key columns) on postgresql versions less than 11'); } - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('firstname', 'string') ->addColumn('lastname', 'string') @@ -1345,7 +1352,7 @@ public function testAddIndexWithSchema() { $this->adapter->createSchema('schema1'); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->addColumn('email', 'string') ->save(); $this->assertFalse($table->hasIndex('email')); @@ -1360,7 +1367,7 @@ public function testAddIndexWithNameWithSchema() { $this->adapter->createSchema('schema1'); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->addColumn('email', 'string') ->save(); $this->assertFalse($table->hasIndex('email')); @@ -1373,7 +1380,7 @@ public function testAddIndexWithNameWithSchema() public function testAddIndexIsCaseSensitive() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('theEmail', 'string') ->save(); $this->assertFalse($table->hasIndex('theEmail')); @@ -1385,7 +1392,7 @@ public function testAddIndexIsCaseSensitive() public function testDropIndex() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email') ->save(); @@ -1394,7 +1401,7 @@ public function testDropIndex() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname']) @@ -1404,7 +1411,7 @@ public function testDropIndex() $this->assertFalse($table2->hasIndex(['fname', 'lname'])); // index with name specified, but dropping it by column name - $table3 = new \Phinx\Db\Table('table3', [], $this->adapter); + $table3 = new Table('table3', [], $this->adapter); $table3->addColumn('email', 'string') ->addIndex('email', ['name' => 'someindexname']) ->save(); @@ -1413,7 +1420,7 @@ public function testDropIndex() $this->assertFalse($table3->hasIndex('email')); // multiple column index with name specified - $table4 = new \Phinx\Db\Table('table4', [], $this->adapter); + $table4 = new Table('table4', [], $this->adapter); $table4->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname'], ['name' => 'multiname']) @@ -1428,7 +1435,7 @@ public function testDropIndexWithSchema() $this->adapter->createSchema('schema1'); // single column index - $table = new \Phinx\Db\Table('schema1.table5', [], $this->adapter); + $table = new Table('schema1.table5', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email') ->save(); @@ -1437,7 +1444,7 @@ public function testDropIndexWithSchema() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('schema1.table6', [], $this->adapter); + $table2 = new Table('schema1.table6', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname']) @@ -1447,7 +1454,7 @@ public function testDropIndexWithSchema() $this->assertFalse($table2->hasIndex(['fname', 'lname'])); // index with name specified, but dropping it by column name - $table3 = new \Phinx\Db\Table('schema1.table7', [], $this->adapter); + $table3 = new Table('schema1.table7', [], $this->adapter); $table3->addColumn('email', 'string') ->addIndex('email', ['name' => 'someIndexName']) ->save(); @@ -1456,7 +1463,7 @@ public function testDropIndexWithSchema() $this->assertFalse($table3->hasIndex('email')); // multiple column index with name specified - $table4 = new \Phinx\Db\Table('schema1.table8', [], $this->adapter); + $table4 = new Table('schema1.table8', [], $this->adapter); $table4->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname'], ['name' => 'multiname']) @@ -1471,7 +1478,7 @@ public function testDropIndexWithSchema() public function testDropIndexByName() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailindex']) ->save(); @@ -1480,7 +1487,7 @@ public function testDropIndexByName() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex( @@ -1498,7 +1505,7 @@ public function testDropIndexByNameWithSchema() $this->adapter->createSchema('schema1'); // single column index - $table = new \Phinx\Db\Table('schema1.Table1', [], $this->adapter); + $table = new Table('schema1.Table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailIndex']) ->save(); @@ -1507,7 +1514,7 @@ public function testDropIndexByNameWithSchema() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('schema1.table2', [], $this->adapter); + $table2 = new Table('schema1.table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex( @@ -1524,10 +1531,10 @@ public function testDropIndexByNameWithSchema() public function testAddForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1541,10 +1548,10 @@ public function testAddForeignKeyWithSchema() $this->adapter->createSchema('schema1'); $this->adapter->createSchema('schema2'); - $refTable = new \Phinx\Db\Table('schema1.ref_table', [], $this->adapter); + $refTable = new Table('schema1.ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('schema2.table', [], $this->adapter); + $table = new Table('schema2.table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'schema1.ref_table', ['id']) @@ -1558,10 +1565,10 @@ public function testAddForeignKeyWithSchema() public function testDropForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1576,10 +1583,10 @@ public function testDropForeignKeyWithSchema() $this->adapter->createSchema('schema1'); $this->adapter->createSchema('schema2'); - $refTable = new \Phinx\Db\Table('schema1.ref_table', [], $this->adapter); + $refTable = new Table('schema1.ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('schema2.table', [], $this->adapter); + $table = new Table('schema2.table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'schema1.ref_table', ['id']) @@ -1594,10 +1601,10 @@ public function testDropForeignKeyWithSchema() public function testDropForeignKeyNotDroppingPrimaryKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [ + $table = new Table('table', [ 'id' => false, 'primary_key' => ['ref_table_id'], ], $this->adapter); @@ -1701,7 +1708,7 @@ public function testGetPhinxType() public function testCreateTableWithComment() { $tableComment = 'Table comment'; - $table = new \Phinx\Db\Table('ntable', ['comment' => $tableComment], $this->adapter); + $table = new Table('ntable', ['comment' => $tableComment], $this->adapter); $table->addColumn('realname', 'string') ->save(); $this->assertTrue($this->adapter->hasTable('ntable')); @@ -1722,7 +1729,7 @@ public function testCreateTableWithComment() public function testCanAddColumnComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn( 'field1', 'string', @@ -1745,7 +1752,7 @@ public function testCanAddColumnComment() public function testCanAddCommentForColumnWithReservedName() { - $table = new \Phinx\Db\Table('user', [], $this->adapter); + $table = new Table('user', [], $this->adapter); $table->addColumn('index', 'string', ['comment' => $comment = 'Comments from column "index"']) ->save(); @@ -1772,7 +1779,7 @@ public function testCanAddCommentForColumnWithReservedName() */ public function testCanChangeColumnComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('field1', 'string', ['comment' => 'Comments from column "field1"']) ->save(); @@ -1801,7 +1808,7 @@ public function testCanChangeColumnComment() */ public function testCanRemoveColumnComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('field1', 'string', ['comment' => 'Comments from column "field1"']) ->save(); @@ -1827,7 +1834,7 @@ public function testCanRemoveColumnComment() */ public function testCanAddMultipleCommentsToOneTable() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('comment1', 'string', [ 'comment' => $comment1 = 'first comment', ]) @@ -1868,13 +1875,13 @@ public function testCanAddMultipleCommentsToOneTable() */ public function testColumnsAreResetBetweenTables() { - $table = new \Phinx\Db\Table('widgets', [], $this->adapter); + $table = new Table('widgets', [], $this->adapter); $table->addColumn('transport', 'string', [ 'comment' => $comment = 'One of: car, boat, truck, plane, train', ]) ->save(); - $table = new \Phinx\Db\Table('things', [], $this->adapter); + $table = new Table('things', [], $this->adapter); $table->addColumn('speed', 'integer') ->save(); @@ -1900,10 +1907,10 @@ public function testForeignKeysAreProperlyEscaped() $userId = 'user'; $sessionId = 'session'; - $local = new \Phinx\Db\Table('users', ['id' => $userId], $this->adapter); + $local = new Table('users', ['id' => $userId], $this->adapter); $local->create(); - $foreign = new \Phinx\Db\Table( + $foreign = new Table( 'sessions', ['id' => $sessionId], $this->adapter @@ -1922,14 +1929,14 @@ public function testForeignKeysAreProperlyEscapedWithSchema() $userId = 'user'; $sessionId = 'session'; - $local = new \Phinx\Db\Table( + $local = new Table( 'schema_users.users', ['id' => $userId], $this->adapter ); $local->create(); - $foreign = new \Phinx\Db\Table( + $foreign = new Table( 'schema_users.sessions', ['id' => $sessionId], $this->adapter @@ -1951,14 +1958,14 @@ public function testForeignKeysAreProperlyEscapedWithSchema2() $userId = 'user'; $sessionId = 'session'; - $local = new \Phinx\Db\Table( + $local = new Table( 'schema_users.users', ['id' => $userId], $this->adapter ); $local->create(); - $foreign = new \Phinx\Db\Table( + $foreign = new Table( 'schema_sessions.sessions', ['id' => $sessionId], $this->adapter @@ -1975,7 +1982,7 @@ public function testForeignKeysAreProperlyEscapedWithSchema2() public function testTimestampWithTimezone() { - $table = new \Phinx\Db\Table('tztable', ['id' => false], $this->adapter); + $table = new Table('tztable', ['id' => false], $this->adapter); $table ->addColumn('timestamp_tz', 'timestamp', ['timezone' => true]) ->addColumn('time_tz', 'time', ['timezone' => true]) @@ -2004,7 +2011,7 @@ public function testTimestampWithTimezoneWithSchema() { $this->adapter->createSchema('tzschema'); - $table = new \Phinx\Db\Table('tzschema.tztable', ['id' => false], $this->adapter); + $table = new Table('tzschema.tztable', ['id' => false], $this->adapter); $table ->addColumn('timestamp_tz', 'timestamp', ['timezone' => true]) ->addColumn('time_tz', 'time', ['timezone' => true]) @@ -2047,7 +2054,7 @@ public function testBulkInsertData() 'column2' => 3, ], ]; - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->addColumn('column3', 'string', ['default' => 'test']) @@ -2078,7 +2085,7 @@ public function testBulkInsertBoolean() 'column1' => null, ], ]; - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'boolean', ['null' => true]) ->insert($data) ->save(); @@ -2091,7 +2098,7 @@ public function testBulkInsertBoolean() public function testInsertData() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->insert([ @@ -2115,7 +2122,7 @@ public function testInsertData() public function testInsertBoolean() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'boolean', ['null' => true]) ->addColumn('column2', 'text', ['null' => true]) ->insert([ @@ -2142,7 +2149,7 @@ public function testInsertDataWithSchema() { $this->adapter->createSchema('schema1'); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->insert([ @@ -2168,7 +2175,7 @@ public function testInsertDataWithSchema() public function testTruncateTable() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->insert([ @@ -2194,7 +2201,7 @@ public function testTruncateTableWithSchema() { $this->adapter->createSchema('schema1'); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->insert([ @@ -2226,7 +2233,7 @@ public function testDumpCreateTable() $consoleOutput = new BufferedOutput(); $this->adapter->setOutput($consoleOutput); - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer', ['null' => true]) @@ -2258,7 +2265,7 @@ public function testDumpCreateTableWithSchema() $consoleOutput = new BufferedOutput(); $this->adapter->setOutput($consoleOutput); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer', ['null' => true]) @@ -2289,7 +2296,7 @@ public function testDumpCreateTableWithSchema() */ public function testDumpInsert() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -2346,7 +2353,7 @@ public function testDumpInsert() */ public function testDumpBulkinsert() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -2399,12 +2406,12 @@ public function testDumpCreateTableAndThenInsert() $consoleOutput = new BufferedOutput(); $this->adapter->setOutput($consoleOutput); - $table = new \Phinx\Db\Table('schema1.table1', ['id' => false, 'primary_key' => ['column1']], $this->adapter); + $table = new Table('schema1.table1', ['id' => false, 'primary_key' => ['column1']], $this->adapter); $table->addColumn('column1', 'string', ['null' => false]) ->addColumn('column2', 'integer') ->save(); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->insert([ 'column1' => 'id1', 'column2' => 1, @@ -2435,7 +2442,7 @@ public function testDumpTransaction() $this->adapter->setOutput($consoleOutput); $this->adapter->beginTransaction(); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') @@ -2454,7 +2461,7 @@ public function testDumpTransaction() */ public function testQueryBuilder() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -2493,7 +2500,7 @@ public function testQueryBuilder() public function testQueryWithParams() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -2524,7 +2531,7 @@ public function testQueryWithParams() public function testRenameMixedCaseTableAndColumns() { - $table = new \Phinx\Db\Table('OrganizationSettings', [], $this->adapter); + $table = new Table('OrganizationSettings', [], $this->adapter); $table->addColumn('SettingType', 'string') ->create(); @@ -2533,7 +2540,7 @@ public function testRenameMixedCaseTableAndColumns() $this->assertTrue($this->adapter->hasColumn('OrganizationSettings', 'SettingType')); $this->assertFalse($this->adapter->hasColumn('OrganizationSettings', 'SettingTypeId')); - $table = new \Phinx\Db\Table('OrganizationSettings', [], $this->adapter); + $table = new Table('OrganizationSettings', [], $this->adapter); $table ->renameColumn('SettingType', 'SettingTypeId') ->update(); @@ -2547,9 +2554,9 @@ public function testRenameMixedCaseTableAndColumns() public function serialProvider(): array { return [ - [\Phinx\Db\Adapter\AdapterInterface::PHINX_TYPE_SMALL_INTEGER], - [\Phinx\Db\Adapter\AdapterInterface::PHINX_TYPE_INTEGER], - [\Phinx\Db\Adapter\AdapterInterface::PHINX_TYPE_BIG_INTEGER], + [AdapterInterface::PHINX_TYPE_SMALL_INTEGER], + [AdapterInterface::PHINX_TYPE_INTEGER], + [AdapterInterface::PHINX_TYPE_BIG_INTEGER], ]; } @@ -2558,7 +2565,7 @@ public function serialProvider(): array */ public function testSerialAliases(string $columnType): void { - $table = new \Phinx\Db\Table('test', ['id' => false], $this->adapter); + $table = new Table('test', ['id' => false], $this->adapter); $table->addColumn('id', $columnType, ['identity' => true, 'generated' => null])->create(); $columns = $table->getColumns(); @@ -2571,7 +2578,7 @@ public function testSerialAliases(string $columnType): void public function testInvalidPdoAttribute() { $adapter = new PostgresAdapter(PGSQL_DB_CONFIG + ['attr_invalid' => true]); - $this->expectException(\UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Invalid PDO attribute: attr_invalid (\PDO::ATTR_INVALID)'); $adapter->connect(); } @@ -2579,12 +2586,12 @@ public function testInvalidPdoAttribute() public function testPdoPersistentConnection() { $adapter = new PostgresAdapter(PGSQL_DB_CONFIG + ['attr_persistent' => true]); - $this->assertTrue($adapter->getConnection()->getAttribute(\PDO::ATTR_PERSISTENT)); + $this->assertTrue($adapter->getConnection()->getAttribute(PDO::ATTR_PERSISTENT)); } public function testPdoNotPersistentConnection() { $adapter = new PostgresAdapter(PGSQL_DB_CONFIG); - $this->assertFalse($adapter->getConnection()->getAttribute(\PDO::ATTR_PERSISTENT)); + $this->assertFalse($adapter->getConnection()->getAttribute(PDO::ATTR_PERSISTENT)); } } diff --git a/tests/Phinx/Db/Adapter/ProxyAdapterTest.php b/tests/Phinx/Db/Adapter/ProxyAdapterTest.php index 79799a333..78a662903 100644 --- a/tests/Phinx/Db/Adapter/ProxyAdapterTest.php +++ b/tests/Phinx/Db/Adapter/ProxyAdapterTest.php @@ -1,8 +1,10 @@ adapter); + $table = new Table('atable', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); @@ -46,7 +48,7 @@ public function testProxyAdapterCanInvertCreateTable() public function testProxyAdapterCanInvertRenameTable() { - $table = new \Phinx\Db\Table('oldname', [], $this->adapter); + $table = new Table('oldname', [], $this->adapter); $table->rename('newname') ->save(); @@ -75,7 +77,7 @@ public function testProxyAdapterCanInvertAddColumn() ->setOptions($options); }); - $table = new \Phinx\Db\Table('atable', [], $this->adapter); + $table = new Table('atable', [], $this->adapter); $table->addColumn('acolumn', 'string') ->save(); @@ -93,7 +95,7 @@ public function testProxyAdapterCanInvertRenameColumn() ->method('hasTable') ->will($this->returnValue(true)); - $table = new \Phinx\Db\Table('atable', [], $this->adapter); + $table = new Table('atable', [], $this->adapter); $table->renameColumn('oldname', 'newname') ->save(); @@ -111,7 +113,7 @@ public function testProxyAdapterCanInvertAddIndex() ->method('hasTable') ->will($this->returnValue(true)); - $table = new \Phinx\Db\Table('atable', [], $this->adapter); + $table = new Table('atable', [], $this->adapter); $table->addIndex(['email']) ->save(); @@ -129,7 +131,7 @@ public function testProxyAdapterCanInvertAddForeignKey() ->method('hasTable') ->will($this->returnValue(true)); - $table = new \Phinx\Db\Table('atable', [], $this->adapter); + $table = new Table('atable', [], $this->adapter); $table->addForeignKey(['ref_table_id'], 'refTable') ->save(); @@ -147,7 +149,7 @@ public function testGetInvertedCommandsThrowsExceptionForIrreversibleCommand() ->method('hasTable') ->will($this->returnValue(true)); - $table = new \Phinx\Db\Table('atable', [], $this->adapter); + $table = new Table('atable', [], $this->adapter); $table->removeColumn('thing') ->save(); diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index 80c0a5ee9..718e7dfb4 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -1,21 +1,30 @@ assertInstanceOf('PDO', $this->adapter->getConnection()); - $this->assertSame(\PDO::ERRMODE_EXCEPTION, $this->adapter->getConnection()->getAttribute(\PDO::ATTR_ERRMODE)); + $this->assertSame(PDO::ERRMODE_EXCEPTION, $this->adapter->getConnection()->getAttribute(PDO::ATTR_ERRMODE)); } public function testConnectionWithFetchMode() @@ -59,7 +68,7 @@ public function testConnectionWithFetchMode() $options['fetch_mode'] = 'assoc'; $this->adapter->setOptions($options); $this->assertInstanceOf('PDO', $this->adapter->getConnection()); - $this->assertSame(\PDO::FETCH_ASSOC, $this->adapter->getConnection()->getAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE)); + $this->assertSame(PDO::FETCH_ASSOC, $this->adapter->getConnection()->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE)); } public function testBeginTransaction() @@ -75,7 +84,7 @@ public function testBeginTransaction() public function testRollbackTransaction() { $this->adapter->getConnection() - ->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->adapter->beginTransaction(); $this->adapter->rollbackTransaction(); @@ -88,7 +97,7 @@ public function testRollbackTransaction() public function testCommitTransactionTransaction() { $this->adapter->getConnection() - ->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->adapter->beginTransaction(); $this->adapter->commitTransaction(); @@ -112,7 +121,7 @@ public function testCreatingTheSchemaTableOnConnect() public function testSchemaTableIsCreatedWithPrimaryKey() { $this->adapter->connect(); - $table = new \Phinx\Db\Table($this->adapter->getSchemaTableName(), [], $this->adapter); + new Table($this->adapter->getSchemaTableName(), [], $this->adapter); $this->assertTrue($this->adapter->hasIndex($this->adapter->getSchemaTableName(), ['version'])); } @@ -128,7 +137,7 @@ public function testQuoteColumnName() public function testCreateTable() { - $table = new \Phinx\Db\Table('ntable', [], $this->adapter); + $table = new Table('ntable', [], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -141,7 +150,7 @@ public function testCreateTable() public function testCreateTableCustomIdColumn() { - $table = new \Phinx\Db\Table('ntable', ['id' => 'custom_id'], $this->adapter); + $table = new Table('ntable', ['id' => 'custom_id'], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -161,7 +170,7 @@ public function testCreateTableCustomIdColumn() public function testCreateTableIdentityIdColumn() { - $table = new \Phinx\Db\Table('ntable', ['id' => false, 'primary_key' => ['custom_id']], $this->adapter); + $table = new Table('ntable', ['id' => false, 'primary_key' => ['custom_id']], $this->adapter); $table->addColumn('custom_id', 'integer', ['identity' => true]) ->save(); @@ -178,7 +187,7 @@ public function testCreateTableWithNoPrimaryKey() $options = [ 'id' => false, ]; - $table = new \Phinx\Db\Table('atable', $options, $this->adapter); + $table = new Table('atable', $options, $this->adapter); $table->addColumn('user_id', 'integer') ->save(); $this->assertFalse($this->adapter->hasColumn('atable', 'id')); @@ -190,7 +199,7 @@ public function testCreateTableWithMultiplePrimaryKeys() 'id' => false, 'primary_key' => ['user_id', 'tag_id'], ]; - $table = new \Phinx\Db\Table('table1', $options, $this->adapter); + $table = new Table('table1', $options, $this->adapter); $table->addColumn('user_id', 'integer') ->addColumn('tag_id', 'integer') ->save(); @@ -209,7 +218,7 @@ public function testCreateTableWithPrimaryKeyAsUuid() 'id' => false, 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('id', 'uuid')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); @@ -224,7 +233,7 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid() 'id' => false, 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('id', 'binaryuuid')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); @@ -232,7 +241,7 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid() public function testCreateTableWithMultipleIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('name', 'string') ->addIndex('email') @@ -246,7 +255,7 @@ public function testCreateTableWithMultipleIndexes() public function testCreateTableWithUniqueIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['unique' => true]) ->save(); @@ -256,7 +265,7 @@ public function testCreateTableWithUniqueIndexes() public function testCreateTableWithNamedIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailindex']) ->save(); @@ -272,10 +281,10 @@ public function testCreateTableWithMultiplePKsAndUniqueIndexes() public function testCreateTableWithForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->addColumn('ref_table_id', 'integer'); $table->addForeignKey('ref_table_id', 'ref_table', 'id'); $table->save(); @@ -286,10 +295,10 @@ public function testCreateTableWithForeignKey() public function testCreateTableWithIndexesAndForeignKey() { - $refTable = new \Phinx\Db\Table('tbl_master', [], $this->adapter); + $refTable = new Table('tbl_master', [], $this->adapter); $refTable->create(); - $table = new \Phinx\Db\Table('tbl_child', [], $this->adapter); + $table = new Table('tbl_child', [], $this->adapter); $table ->addColumn('column1', 'integer') ->addColumn('column2', 'integer') @@ -319,11 +328,11 @@ public function testCreateTableWithIndexesAndForeignKey() public function testCreateTableWithoutAutoIncrementingPrimaryKeyAndWithForeignKey() { - $refTable = (new \Phinx\Db\Table('tbl_master', ['id' => false, 'primary_key' => 'id'], $this->adapter)) + $refTable = (new Table('tbl_master', ['id' => false, 'primary_key' => 'id'], $this->adapter)) ->addColumn('id', 'text'); $refTable->create(); - $table = (new \Phinx\Db\Table('tbl_child', ['id' => false, 'primary_key' => 'master_id'], $this->adapter)) + $table = (new Table('tbl_child', ['id' => false, 'primary_key' => 'master_id'], $this->adapter)) ->addColumn('master_id', 'text') ->addForeignKey( 'master_id', @@ -346,7 +355,7 @@ public function testCreateTableWithoutAutoIncrementingPrimaryKeyAndWithForeignKe public function testAddPrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false], $this->adapter); + $table = new Table('table1', ['id' => false], $this->adapter); $table ->addColumn('column1', 'integer') ->addColumn('column2', 'integer') @@ -361,7 +370,7 @@ public function testAddPrimaryKey() public function testChangePrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'integer') ->addColumn('column2', 'integer') @@ -377,7 +386,7 @@ public function testChangePrimaryKey() public function testChangePrimaryKeyNonInteger() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'string') ->addColumn('column2', 'string') @@ -393,7 +402,7 @@ public function testChangePrimaryKeyNonInteger() public function testDropPrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'integer') ->addColumn('column2', 'integer') @@ -408,7 +417,7 @@ public function testDropPrimaryKey() public function testAddMultipleColumnPrimaryKeyFails() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table ->addColumn('column1', 'integer') ->addColumn('column2', 'integer') @@ -423,7 +432,7 @@ public function testAddMultipleColumnPrimaryKeyFails() public function testChangeCommentFails() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->expectException(BadMethodCallException::class); @@ -435,7 +444,7 @@ public function testChangeCommentFails() public function testRenameTable() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertTrue($this->adapter->hasTable('table1')); $this->assertFalse($this->adapter->hasTable('table2')); @@ -446,7 +455,7 @@ public function testRenameTable() public function testAddColumn() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('email')); $table->addColumn('email', 'string', ['null' => true]) @@ -461,7 +470,7 @@ public function testAddColumn() public function testAddColumnWithDefaultValue() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_zero', 'string', ['default' => 'test']) ->save(); @@ -471,7 +480,7 @@ public function testAddColumnWithDefaultValue() public function testAddColumnWithDefaultZero() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_zero', 'integer', ['default' => 0]) ->save(); @@ -482,7 +491,7 @@ public function testAddColumnWithDefaultZero() public function testAddColumnWithDefaultEmptyString() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_empty', 'string', ['default' => '']) ->save(); @@ -500,7 +509,7 @@ public function testAddColumnWithCustomType() ], ]); - (new \Phinx\Db\Table('table1', [], $this->adapter)) + (new Table('table1', [], $this->adapter)) ->addColumn('custom', 'custom') ->addColumn('custom_ext', 'custom', [ 'null' => false, @@ -543,7 +552,7 @@ public function irregularCreateTableProvider() public function testAddColumnToIrregularCreateTableStatements(string $createTableSql, array $expectedColumns): void { $this->adapter->execute($createTableSql); - $table = new \Phinx\Db\Table('users', [], $this->adapter); + $table = new Table('users', [], $this->adapter); $table->addColumn('foo', 'string'); $table->update(); @@ -556,7 +565,7 @@ public function testAddColumnToIrregularCreateTableStatements(string $createTabl public function testAddDoubleColumn() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('foo', 'double', ['null' => true]) ->save(); @@ -566,7 +575,7 @@ public function testAddDoubleColumn() public function testRenameColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -577,7 +586,7 @@ public function testRenameColumn() public function testRenamingANonExistentColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); @@ -588,7 +597,7 @@ public function testRenamingANonExistentColumn() public function testRenameColumnWithIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addIndex('indexcol') @@ -605,7 +614,7 @@ public function testRenameColumnWithIndex() public function testRenameColumnWithUniqueIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addIndex('indexcol', ['unique' => true]) @@ -622,7 +631,7 @@ public function testRenameColumnWithUniqueIndex() public function testRenameColumnWithCompositeIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol1', 'integer') ->addColumn('indexcol2', 'integer') @@ -644,7 +653,7 @@ public function testRenameColumnWithCompositeIndex() */ public function testRenameColumnWithIndexMatchingTheTableName() { - $table = new \Phinx\Db\Table('indexcol', [], $this->adapter); + $table = new Table('indexcol', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addIndex('indexcol') @@ -665,7 +674,7 @@ public function testRenameColumnWithIndexMatchingTheTableName() */ public function testRenameColumnWithIndexColumnPartialMatch() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addColumn('indexcolumn', 'integer') @@ -684,7 +693,7 @@ public function testRenameColumnWithIndexColumnPartialMatch() public function testRenameColumnWithIndexColumnRequiringQuoting() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addIndex('indexcol') @@ -704,7 +713,7 @@ public function testRenameColumnWithIndexColumnRequiringQuoting() */ public function testRenameColumnWithExpressionIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->create(); @@ -713,7 +722,7 @@ public function testRenameColumnWithExpressionIndex() $this->assertTrue($this->adapter->hasIndexByName('t', 'custom_idx')); - $this->expectException(\PDOException::class); + $this->expectException(PDOException::class); $this->expectExceptionMessage('no such column: indexcol'); $table->renameColumn('indexcol', 'newindexcol')->update(); @@ -792,7 +801,7 @@ public function customIndexSQLDataProvider(): array */ public function testRenameColumnWithCustomIndex(string $indexSQL, string $newIndexSQL) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->create(); @@ -891,7 +900,7 @@ public function customCompositeIndexSQLDataProvider(): array */ public function testRenameColumnWithCustomCompositeIndex(string $indexSQL, string $newIndexSQL) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol1', 'integer') ->addColumn('indexcol2', 'integer') @@ -914,15 +923,15 @@ public function testRenameColumnWithCustomCompositeIndex(string $indexSQL, strin public function testChangeColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setType('string'); $table->changeColumn('column1', $newColumn1); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); - $newColumn2 = new \Phinx\Db\Table\Column(); + $newColumn2 = new Column(); $newColumn2->setName('column2') ->setType('string'); $table->changeColumn('column1', $newColumn2)->save(); @@ -932,10 +941,10 @@ public function testChangeColumn() public function testChangeColumnDefaultValue() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['default' => 'test']) ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setDefault('test1') ->setType('string'); $table->changeColumn('column1', $newColumn1)->save(); @@ -949,10 +958,10 @@ public function testChangeColumnDefaultValue() */ public function testChangeColumnWithForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('another_table', [], $this->adapter); + $table = new Table('another_table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -967,7 +976,7 @@ public function testChangeColumnWithForeignKey() public function testChangeColumnWithIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addIndex( @@ -985,7 +994,7 @@ public function testChangeColumnWithIndex() public function testChangeColumnWithTrigger() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('triggercol', 'integer') ->addColumn('othercol', 'integer') @@ -1020,10 +1029,10 @@ public function testChangeColumnWithTrigger() public function testChangeColumnDefaultToZero() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer') ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setDefault(0) ->setType('integer'); $table->changeColumn('column1', $newColumn1)->save(); @@ -1033,10 +1042,10 @@ public function testChangeColumnDefaultToZero() public function testChangeColumnDefaultToNull() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['default' => 'test']) ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setDefault(null) ->setType('string'); $table->changeColumn('column1', $newColumn1)->save(); @@ -1046,10 +1055,10 @@ public function testChangeColumnDefaultToNull() public function testChangeColumnWithCommasInCommentsOrDefaultValue() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['default' => 'one, two or three', 'comment' => 'three, two or one']) ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setDefault('another default') ->setComment('another comment') ->setType('string'); @@ -1063,7 +1072,7 @@ public function testChangeColumnWithCommasInCommentsOrDefaultValue() */ public function testDropColumn($columnCreationArgs) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $columnName = $columnCreationArgs[0]; call_user_func_array([$table, 'addColumn'], $columnCreationArgs); $table->save(); @@ -1076,7 +1085,7 @@ public function testDropColumn($columnCreationArgs) public function testDropColumnWithIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addIndex('indexcol') @@ -1091,7 +1100,7 @@ public function testDropColumnWithIndex() public function testDropColumnWithUniqueIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addIndex('indexcol', ['unique' => true]) @@ -1106,7 +1115,7 @@ public function testDropColumnWithUniqueIndex() public function testDropColumnWithCompositeIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol1', 'integer') ->addColumn('indexcol2', 'integer') @@ -1126,7 +1135,7 @@ public function testDropColumnWithCompositeIndex() */ public function testDropColumnWithIndexMatchingTheTableName() { - $table = new \Phinx\Db\Table('indexcol', [], $this->adapter); + $table = new Table('indexcol', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addColumn('indexcolumn', 'integer') @@ -1146,7 +1155,7 @@ public function testDropColumnWithIndexMatchingTheTableName() */ public function testDropColumnWithIndexColumnPartialMatch() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->addColumn('indexcolumn', 'integer') @@ -1166,7 +1175,7 @@ public function testDropColumnWithIndexColumnPartialMatch() */ public function testDropColumnWithExpressionIndex() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->create(); @@ -1175,7 +1184,7 @@ public function testDropColumnWithExpressionIndex() $this->assertTrue($this->adapter->hasIndexByName('t', 'custom_idx')); - $this->expectException(\PDOException::class); + $this->expectException(PDOException::class); $this->expectExceptionMessage('no such column: indexcol'); $table->removeColumn('indexcol')->update(); @@ -1187,7 +1196,7 @@ public function testDropColumnWithExpressionIndex() */ public function testDropColumnWithCustomIndex(string $indexSQL) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol', 'integer') ->create(); @@ -1207,7 +1216,7 @@ public function testDropColumnWithCustomIndex(string $indexSQL) */ public function testDropColumnWithCustomCompositeIndex(string $indexSQL) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn('indexcol1', 'integer') ->addColumn('indexcol2', 'integer') @@ -1255,7 +1264,7 @@ public function columnsProvider() public function testAddIndex() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->save(); $this->assertFalse($table->hasIndex('email')); @@ -1267,7 +1276,7 @@ public function testAddIndex() public function testDropIndex() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email') ->save(); @@ -1276,7 +1285,7 @@ public function testDropIndex() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname']) @@ -1286,7 +1295,7 @@ public function testDropIndex() $this->assertFalse($table2->hasIndex(['fname', 'lname'])); // single column index with name specified - $table3 = new \Phinx\Db\Table('table3', [], $this->adapter); + $table3 = new Table('table3', [], $this->adapter); $table3->addColumn('email', 'string') ->addIndex('email', ['name' => 'someindexname']) ->save(); @@ -1295,7 +1304,7 @@ public function testDropIndex() $this->assertFalse($table3->hasIndex('email')); // multiple column index with name specified - $table4 = new \Phinx\Db\Table('table4', [], $this->adapter); + $table4 = new Table('table4', [], $this->adapter); $table4->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname'], ['name' => 'multiname']) @@ -1308,7 +1317,7 @@ public function testDropIndex() public function testDropIndexByName() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailindex']) ->save(); @@ -1317,7 +1326,7 @@ public function testDropIndexByName() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname'], ['name' => 'twocolumnindex']) @@ -1329,10 +1338,10 @@ public function testDropIndexByName() public function testAddForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1343,12 +1352,12 @@ public function testAddForeignKey() public function testDropForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string') ->addIndex(['field1'], ['unique' => true]) ->save(); - $table = new \Phinx\Db\Table('another_table', [], $this->adapter); + $table = new Table('another_table', [], $this->adapter); $opts = [ 'update' => 'CASCADE', 'delete' => 'CASCADE', @@ -1373,10 +1382,10 @@ public function testDropForeignKey() public function testFailingDropForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->save(); - $table = new \Phinx\Db\Table('another_table', [], $this->adapter); + $table = new Table('another_table', [], $this->adapter); $table ->addColumn('ref_table_id', 'integer') ->addForeignKey(['ref_table_id'], 'ref_table', ['id']) @@ -1407,7 +1416,7 @@ public function testDropDatabase() public function testAddColumnWithComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string', ['comment' => $comment = 'Comments from "column1"']) ->save(); @@ -1446,10 +1455,10 @@ public function testPhinxTypeNotValidTypeRegex() public function testAddIndexTwoTablesSameIndex() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->save(); - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('email', 'string') ->save(); @@ -1467,7 +1476,7 @@ public function testAddIndexTwoTablesSameIndex() public function testBulkInsertData() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer', ['null' => true]) ->insert([ @@ -1507,7 +1516,7 @@ public function testBulkInsertData() public function testInsertData() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer', ['null' => true]) ->insert([ @@ -1548,7 +1557,7 @@ public function testInsertData() public function testBulkInsertDataEnum() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'string', ['null' => true]) ->addColumn('column3', 'string', ['default' => 'c']) @@ -1569,7 +1578,7 @@ public function testNullWithoutDefaultValue() $this->markTestSkipped('Skipping for now. See Github Issue #265.'); // construct table with default/null combinations - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('aa', 'string', ['null' => true]) // no default value ->addColumn('bb', 'string', ['null' => false]) // no default value ->addColumn('cc', 'string', ['null' => true, 'default' => 'some1']) @@ -1611,7 +1620,7 @@ public function testDumpCreateTable() $consoleOutput = new BufferedOutput(); $this->adapter->setOutput($consoleOutput); - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string', ['null' => false]) ->addColumn('column2', 'integer') @@ -1632,7 +1641,7 @@ public function testDumpCreateTable() */ public function testDumpInsert() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -1677,7 +1686,7 @@ public function testDumpInsert() */ public function testDumpBulkinsert() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -1719,7 +1728,7 @@ public function testDumpCreateTableAndThenInsert() $consoleOutput = new BufferedOutput(); $this->adapter->setOutput($consoleOutput); - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => ['column1']], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => ['column1']], $this->adapter); $table->addColumn('column1', 'string', ['null' => false]) ->addColumn('column2', 'integer') @@ -1727,7 +1736,7 @@ public function testDumpCreateTableAndThenInsert() $expectedOutput = 'C'; - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->insert([ 'column1' => 'id1', 'column2' => 1, @@ -1747,7 +1756,7 @@ public function testDumpCreateTableAndThenInsert() */ public function testQueryBuilder() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -1786,7 +1795,7 @@ public function testQueryBuilder() public function testQueryWithParams() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -1821,7 +1830,7 @@ public function testQueryWithParams() */ public function testAlterTableColumnAdd() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->create(); $table->addColumn('string_col', 'string', ['default' => '']); @@ -1853,10 +1862,10 @@ public function testAlterTableColumnAdd() public function testAlterTableWithConstraints() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->create(); - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->create(); $table @@ -1895,12 +1904,12 @@ public function testAlterTableDoesNotViolateRestrictedForeignKeyConstraint() { $this->adapter->execute('PRAGMA foreign_keys = ON'); - $articlesTable = new \Phinx\Db\Table('articles', [], $this->adapter); + $articlesTable = new Table('articles', [], $this->adapter); $articlesTable ->insert(['id' => 1]) ->save(); - $commentsTable = new \Phinx\Db\Table('comments', [], $this->adapter); + $commentsTable = new Table('comments', [], $this->adapter); $commentsTable ->addColumn('article_id', 'integer') ->addForeignKey('article_id', 'articles', 'id', [ @@ -1960,12 +1969,12 @@ public function testAlterTableDoesNotViolateRestrictedForeignKeyConstraint() */ public function testAlterTableDoesViolateForeignKeyConstraintOnTargetTableChange() { - $articlesTable = new \Phinx\Db\Table('articles', [], $this->adapter); + $articlesTable = new Table('articles', [], $this->adapter); $articlesTable ->insert(['id' => 1]) ->save(); - $commentsTable = new \Phinx\Db\Table('comments', [], $this->adapter); + $commentsTable = new Table('comments', [], $this->adapter); $commentsTable ->addColumn('article_id', 'integer') ->addForeignKey('article_id', 'articles', 'id', [ @@ -1981,7 +1990,7 @@ public function testAlterTableDoesViolateForeignKeyConstraintOnTargetTableChange $this->adapter->execute('DELETE FROM articles'); $this->adapter->execute('PRAGMA foreign_keys = ON'); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Integrity constraint violation: FOREIGN KEY constraint on `comments` failed.'); $articlesTable @@ -2002,7 +2011,7 @@ public function testAlterTableDoesViolateForeignKeyConstraintOnSourceTableChange ->onlyMethods(['query']) ->getMock(); - $adapterReflection = new \ReflectionObject($adapter); + $adapterReflection = new ReflectionObject($adapter); $queryReflection = $adapterReflection->getParentClass()->getMethod('query'); $adapter @@ -2018,12 +2027,12 @@ public function testAlterTableDoesViolateForeignKeyConstraintOnSourceTableChange return $queryReflection->invoke($adapter, $sql, $params); }); - $articlesTable = new \Phinx\Db\Table('articles', [], $adapter); + $articlesTable = new Table('articles', [], $adapter); $articlesTable ->insert(['id' => 1]) ->save(); - $commentsTable = new \Phinx\Db\Table('comments', [], $adapter); + $commentsTable = new Table('comments', [], $adapter); $commentsTable ->addColumn('article_id', 'integer') ->addForeignKey('article_id', 'articles', 'id', [ @@ -2035,7 +2044,7 @@ public function testAlterTableDoesViolateForeignKeyConstraintOnSourceTableChange $this->assertTrue($adapter->hasForeignKey('comments', ['article_id'])); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Integrity constraint violation: FOREIGN KEY constraint on `comments` failed.'); $commentsTable @@ -2049,12 +2058,12 @@ public function testAlterTableDoesViolateForeignKeyConstraintOnSourceTableChange */ public function testAlterTableForeignKeyConstraintValidationNotRunningWithDisabledForeignKeys() { - $articlesTable = new \Phinx\Db\Table('articles', [], $this->adapter); + $articlesTable = new Table('articles', [], $this->adapter); $articlesTable ->insert(['id' => 1]) ->save(); - $commentsTable = new \Phinx\Db\Table('comments', [], $this->adapter); + $commentsTable = new Table('comments', [], $this->adapter); $commentsTable ->addColumn('article_id', 'integer') ->addForeignKey('article_id', 'articles', 'id', [ @@ -2082,7 +2091,7 @@ public function testAlterTableForeignKeyConstraintValidationNotRunningWithDisabl $this->adapter->execute('PRAGMA foreign_keys = ON'); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Integrity constraint violation: FOREIGN KEY constraint on `comments` failed.'); $articlesTable @@ -2096,7 +2105,7 @@ public function testLiteralSupport() CREATE TABLE `test` (`real_col` DECIMAL) INPUT; $this->adapter->execute($createQuery); - $table = new \Phinx\Db\Table('test', [], $this->adapter); + $table = new Table('test', [], $this->adapter); $columns = $table->getColumns(); $this->assertCount(1, $columns); $this->assertEquals(Literal::from('decimal'), array_pop($columns)->getType()); @@ -2280,7 +2289,7 @@ public function providePrimaryKeysToCheck() */ public function testHasNamedPrimaryKey() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->adapter->hasPrimaryKey('t', [], 'named_constraint'); } @@ -2331,13 +2340,13 @@ public function provideForeignKeysToCheck() /** @covers \Phinx\Db\Adapter\SQLiteAdapter::hasForeignKey */ public function testHasNamedForeignKey() { - $refTable = new \Phinx\Db\Table('tbl_parent_1', [], $this->adapter); + $refTable = new Table('tbl_parent_1', [], $this->adapter); $refTable->addColumn('column', 'string')->create(); - $refTable = new \Phinx\Db\Table('tbl_parent_2', [], $this->adapter); + $refTable = new Table('tbl_parent_2', [], $this->adapter); $refTable->create(); - $refTable = new \Phinx\Db\Table('tbl_parent_3', [ + $refTable = new Table('tbl_parent_3', [ 'id' => false, 'primary_key' => ['id', 'column'], ], $this->adapter); @@ -2372,7 +2381,7 @@ public function testHasNamedForeignKey() */ public function testGetSqlType($phinxType, $limit, $exp) { - if ($exp instanceof \Exception) { + if ($exp instanceof Exception) { $this->expectException(get_class($exp)); $this->adapter->getSqlType($phinxType, $limit); @@ -2384,7 +2393,7 @@ public function testGetSqlType($phinxType, $limit, $exp) public function providePhinxTypes() { - $unsupported = new \Phinx\Db\Adapter\UnsupportedColumnTypeException(); + $unsupported = new UnsupportedColumnTypeException(); return [ [SQLiteAdapter::PHINX_TYPE_BIG_INTEGER, null, SQLiteAdapter::PHINX_TYPE_BIG_INTEGER], @@ -2740,7 +2749,6 @@ public function provideColumnNamesToCheck() ['create table t("0" text)', '0', true], ['create table t("0" text)', '0e0', false], ['create table t("0e0" text)', '0', false], - ['create table t("0" text)', 0, true], ['create table t(b text); create temp table t(a text)', 'a', true], ['create table not_t(a text)', 'a', false], ]; @@ -2959,10 +2967,10 @@ public function testForeignKeyReferenceCorrectAfterRenameColumn() $refTableColumnId = 'ref_table_id'; $refTableColumnToRename = 'columnToRename'; $refTableRenamedColumn = 'renamedColumn'; - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn($refTableColumnToRename, 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->addColumn($refTableColumnId, 'integer'); $table->addForeignKey($refTableColumnId, $refTable->getName(), 'id'); $table->save(); @@ -2986,10 +2994,10 @@ public function testForeignKeyReferenceCorrectAfterChangeColumn() { $refTableColumnId = 'ref_table_id'; $refTableColumnToChange = 'columnToChange'; - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn($refTableColumnToChange, 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->addColumn($refTableColumnId, 'integer'); $table->addForeignKey($refTableColumnId, $refTable->getName(), 'id'); $table->save(); @@ -3013,10 +3021,10 @@ public function testForeignKeyReferenceCorrectAfterRemoveColumn() { $refTableColumnId = 'ref_table_id'; $refTableColumnToRemove = 'columnToRemove'; - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn($refTableColumnToRemove, 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->addColumn($refTableColumnId, 'integer'); $table->addForeignKey($refTableColumnId, $refTable->getName(), 'id'); $table->save(); @@ -3040,10 +3048,10 @@ public function testForeignKeyReferenceCorrectAfterChangePrimaryKey() { $refTableColumnAdditionalId = 'additional_id'; $refTableColumnId = 'ref_table_id'; - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn($refTableColumnAdditionalId, 'integer')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->addColumn($refTableColumnId, 'integer'); $table->addForeignKey($refTableColumnId, $refTable->getName(), 'id'); $table->save(); @@ -3069,16 +3077,16 @@ public function testForeignKeyReferenceCorrectAfterChangePrimaryKey() public function testForeignKeyReferenceCorrectAfterDropForeignKey() { $refTableAdditionalColumnId = 'ref_table_additional_id'; - $refTableAdditional = new \Phinx\Db\Table('ref_table_additional', [], $this->adapter); + $refTableAdditional = new Table('ref_table_additional', [], $this->adapter); $refTableAdditional->save(); $refTableColumnId = 'ref_table_id'; - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn($refTableAdditionalColumnId, 'integer'); $refTable->addForeignKey($refTableAdditionalColumnId, $refTableAdditional->getName(), 'id'); $refTable->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->addColumn($refTableColumnId, 'integer'); $table->addForeignKey($refTableColumnId, $refTable->getName(), 'id'); $table->save(); @@ -3101,27 +3109,27 @@ public function testForeignKeyReferenceCorrectAfterDropForeignKey() public function testInvalidPdoAttribute() { $adapter = new SQLiteAdapter(SQLITE_DB_CONFIG + ['attr_invalid' => true]); - $this->expectException(\UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Invalid PDO attribute: attr_invalid (\PDO::ATTR_INVALID)'); $adapter->connect(); } public function testPdoExceptionUpdateNonExistingTable() { - $this->expectException(\PDOException::class); - $table = new \Phinx\Db\Table('non_existing_table', [], $this->adapter); + $this->expectException(PDOException::class); + $table = new Table('non_existing_table', [], $this->adapter); $table->addColumn('column', 'string')->update(); } public function testPdoPersistentConnection() { $adapter = new SQLiteAdapter(SQLITE_DB_CONFIG + ['attr_persistent' => true]); - $this->assertTrue($adapter->getConnection()->getAttribute(\PDO::ATTR_PERSISTENT)); + $this->assertTrue($adapter->getConnection()->getAttribute(PDO::ATTR_PERSISTENT)); } public function testPdoNotPersistentConnection() { $adapter = new SQLiteAdapter(SQLITE_DB_CONFIG); - $this->assertFalse($adapter->getConnection()->getAttribute(\PDO::ATTR_PERSISTENT)); + $this->assertFalse($adapter->getConnection()->getAttribute(PDO::ATTR_PERSISTENT)); } } diff --git a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php index e2ee43aac..7e6ee0fca 100644 --- a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php @@ -1,10 +1,16 @@ assertInstanceOf('PDO', $this->adapter->getConnection()); - $this->assertSame(\PDO::ERRMODE_EXCEPTION, $this->adapter->getConnection()->getAttribute(\PDO::ATTR_ERRMODE)); + $this->assertSame(PDO::ERRMODE_EXCEPTION, $this->adapter->getConnection()->getAttribute(PDO::ATTR_ERRMODE)); } public function testConnectionWithDsnOptions() @@ -65,7 +72,7 @@ public function testConnectionWithFetchMode() $options['fetch_mode'] = 'assoc'; $this->adapter->setOptions($options); $this->assertInstanceOf('PDO', $this->adapter->getConnection()); - $this->assertSame(\PDO::FETCH_ASSOC, $this->adapter->getConnection()->getAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE)); + $this->assertSame(PDO::FETCH_ASSOC, $this->adapter->getConnection()->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE)); } public function testConnectionWithoutPort() @@ -85,7 +92,7 @@ public function testConnectionWithInvalidCredentials() $adapter = new SqlServerAdapter($options, new ArrayInput([]), new NullOutput()); $adapter->connect(); $this->fail('Expected the adapter to throw an exception'); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertInstanceOf( 'InvalidArgumentException', $e, @@ -113,7 +120,7 @@ public function testCreatingTheSchemaTableOnConnect() public function testSchemaTableIsCreatedWithPrimaryKey() { $this->adapter->connect(); - $table = new \Phinx\Db\Table($this->adapter->getSchemaTableName(), [], $this->adapter); + new Table($this->adapter->getSchemaTableName(), [], $this->adapter); $this->assertTrue($this->adapter->hasIndex($this->adapter->getSchemaTableName(), ['version'])); } @@ -129,7 +136,7 @@ public function testQuoteColumnName() public function testCreateTable() { - $table = new \Phinx\Db\Table('ntable', [], $this->adapter); + $table = new Table('ntable', [], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -142,7 +149,7 @@ public function testCreateTable() public function testCreateTableCustomIdColumn() { - $table = new \Phinx\Db\Table('ntable', ['id' => 'custom_id'], $this->adapter); + $table = new Table('ntable', ['id' => 'custom_id'], $this->adapter); $table->addColumn('realname', 'string') ->addColumn('email', 'integer') ->save(); @@ -155,7 +162,7 @@ public function testCreateTableCustomIdColumn() public function testCreateTableIdentityColumn() { - $table = new \Phinx\Db\Table('ntable', ['id' => false, 'primary_key' => 'id'], $this->adapter); + $table = new Table('ntable', ['id' => false, 'primary_key' => 'id'], $this->adapter); $table->addColumn('id', 'integer', ['identity' => true, 'seed' => 1, 'increment' => 10 ]) ->save(); $this->assertTrue($this->adapter->hasTable('ntable')); @@ -175,7 +182,7 @@ public function testCreateTableWithNoPrimaryKey() $options = [ 'id' => false, ]; - $table = new \Phinx\Db\Table('atable', $options, $this->adapter); + $table = new Table('atable', $options, $this->adapter); $table->addColumn('user_id', 'integer') ->save(); $this->assertFalse($this->adapter->hasColumn('atable', 'id')); @@ -186,9 +193,9 @@ public function testCreateTableWithConflictingPrimaryKeys() $options = [ 'primary_key' => 'user_id', ]; - $table = new \Phinx\Db\Table('atable', $options, $this->adapter); + $table = new Table('atable', $options, $this->adapter); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('You cannot enable an auto incrementing ID field and a primary key'); $table->addColumn('user_id', 'integer')->save(); } @@ -198,7 +205,7 @@ public function testCreateTableWithPrimaryKeySetToImplicitId() $options = [ 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); @@ -210,7 +217,7 @@ public function testCreateTableWithPrimaryKeyArraySetToImplicitId() $options = [ 'primary_key' => ['id'], ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); @@ -222,8 +229,8 @@ public function testCreateTableWithMultiplePrimaryKeyArraySetToImplicitId() $options = [ 'primary_key' => ['id', 'user_id'], ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); - $this->expectException(\InvalidArgumentException::class); + $table = new Table('ztable', $options, $this->adapter); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('You cannot enable an auto incrementing ID field and a primary key'); $table->addColumn('user_id', 'integer')->save(); } @@ -234,7 +241,7 @@ public function testCreateTableWithMultiplePrimaryKeys() 'id' => false, 'primary_key' => ['user_id', 'tag_id'], ]; - $table = new \Phinx\Db\Table('table1', $options, $this->adapter); + $table = new Table('table1', $options, $this->adapter); $table->addColumn('user_id', 'integer', ['null' => false]) ->addColumn('tag_id', 'integer', ['null' => false]) ->save(); @@ -249,7 +256,7 @@ public function testCreateTableWithPrimaryKeyAsUuid() 'id' => false, 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('id', 'uuid', ['null' => false])->save(); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); @@ -263,7 +270,7 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid() 'id' => false, 'primary_key' => 'id', ]; - $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table = new Table('ztable', $options, $this->adapter); $table->addColumn('id', 'binaryuuid', ['null' => false])->save(); $table->addColumn('user_id', 'integer')->save(); $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); @@ -273,7 +280,7 @@ public function testCreateTableWithPrimaryKeyAsBinaryUuid() public function testCreateTableWithMultipleIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('name', 'string') ->addIndex('email') @@ -287,7 +294,7 @@ public function testCreateTableWithMultipleIndexes() public function testCreateTableWithUniqueIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['unique' => true]) ->save(); @@ -297,7 +304,7 @@ public function testCreateTableWithUniqueIndexes() public function testCreateTableWithNamedIndexes() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailindex']) ->save(); @@ -308,7 +315,7 @@ public function testCreateTableWithNamedIndexes() public function testAddPrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false], $this->adapter); + $table = new Table('table1', ['id' => false], $this->adapter); $table ->addColumn('column1', 'integer', ['null' => false]) ->save(); @@ -322,7 +329,7 @@ public function testAddPrimaryKey() public function testChangePrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'integer', ['null' => false]) ->addColumn('column2', 'integer', ['null' => false]) @@ -339,7 +346,7 @@ public function testChangePrimaryKey() public function testDropPrimaryKey() { - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => 'column1'], $this->adapter); $table ->addColumn('column1', 'integer', ['null' => false]) ->save(); @@ -353,7 +360,7 @@ public function testDropPrimaryKey() public function testChangeCommentFails() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->expectException(BadMethodCallException::class); @@ -365,7 +372,7 @@ public function testChangeCommentFails() public function testRenameTable() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertTrue($this->adapter->hasTable('table1')); $this->assertFalse($this->adapter->hasTable('table2')); @@ -376,7 +383,7 @@ public function testRenameTable() public function testAddColumn() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $this->assertFalse($table->hasColumn('email')); $table->addColumn('email', 'string') @@ -386,7 +393,7 @@ public function testAddColumn() public function testAddColumnWithDefaultValue() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_zero', 'string', ['default' => 'test']) ->save(); @@ -400,7 +407,7 @@ public function testAddColumnWithDefaultValue() public function testAddColumnWithDefaultZero() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_zero', 'integer', ['default' => 0]) ->save(); @@ -415,7 +422,7 @@ public function testAddColumnWithDefaultZero() public function testAddColumnWithDefaultNull() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table->addColumn('default_null', 'string', ['null' => true, 'default' => null]) ->save(); @@ -429,7 +436,7 @@ public function testAddColumnWithDefaultNull() public function testAddColumnWithNotNullableNoDefault() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table ->addColumn('col', 'string', ['null' => false]) ->create(); @@ -444,7 +451,7 @@ public function testAddColumnWithNotNullableNoDefault() public function testAddColumnWithDefaultBool() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->save(); $table ->addColumn('default_false', 'integer', ['default' => false]) @@ -470,7 +477,7 @@ public function testAddColumnWithCustomType() ], ]); - (new \Phinx\Db\Table('table1', [], $this->adapter)) + (new Table('table1', [], $this->adapter)) ->addColumn('custom', 'custom') ->addColumn('custom_ext', 'custom', [ 'null' => false, @@ -496,7 +503,7 @@ public function testAddColumnWithCustomType() public function testRenameColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -508,14 +515,14 @@ public function testRenameColumn() public function testRenamingANonExistentColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); try { $this->adapter->renameColumn('t', 'column2', 'column1'); $this->fail('Expected the adapter to throw an exception'); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { $this->assertInstanceOf( 'InvalidArgumentException', $e, @@ -527,11 +534,11 @@ public function testRenamingANonExistentColumn() public function testChangeColumnType() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1->setType('string'); $table->changeColumn('column1', $newColumn1)->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -545,10 +552,10 @@ public function testChangeColumnType() public function testChangeColumnNameAndNull() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['null' => false]) ->save(); - $newColumn2 = new \Phinx\Db\Table\Column(); + $newColumn2 = new Column(); $newColumn2->setName('column2') ->setType('string') ->setNull(true); @@ -565,7 +572,7 @@ public function testChangeColumnNameAndNull() public function testChangeColumnDefaults() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['default' => 'test']) ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -573,7 +580,7 @@ public function testChangeColumnDefaults() $columns = $this->adapter->getColumns('t'); $this->assertSame('test', $columns['column1']->getDefault()); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1 ->setType('string') ->setDefault('another test'); @@ -586,10 +593,10 @@ public function testChangeColumnDefaults() public function testChangeColumnDefaultToNull() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string', ['null' => true, 'default' => 'test']) ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1 ->setType('string') ->setDefault(null); @@ -600,10 +607,10 @@ public function testChangeColumnDefaultToNull() public function testChangeColumnDefaultToZero() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'integer') ->save(); - $newColumn1 = new \Phinx\Db\Table\Column(); + $newColumn1 = new Column(); $newColumn1 ->setType('string') ->setDefault(0); @@ -614,7 +621,7 @@ public function testChangeColumnDefaultToZero() public function testDropColumn() { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table->addColumn('column1', 'string') ->save(); $this->assertTrue($this->adapter->hasColumn('t', 'column1')); @@ -650,7 +657,7 @@ public function columnsProvider() */ public function testGetColumns($colName, $type, $options) { - $table = new \Phinx\Db\Table('t', [], $this->adapter); + $table = new Table('t', [], $this->adapter); $table ->addColumn($colName, $type, $options) ->save(); @@ -663,7 +670,7 @@ public function testGetColumns($colName, $type, $options) public function testAddIndex() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->save(); $this->assertFalse($table->hasIndex('email')); @@ -674,7 +681,7 @@ public function testAddIndex() public function testAddIndexWithSort() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('username', 'string') ->save(); @@ -702,7 +709,7 @@ public function testAddIndexWithSort() public function testAddIndexWithIncludeColumns() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('firstname', 'string') ->addColumn('lastname', 'string') @@ -740,7 +747,7 @@ public function testAddIndexWithIncludeColumns() public function testGetIndexes() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addColumn('username', 'string') ->addIndex('email') @@ -760,7 +767,7 @@ public function testGetIndexes() public function testDropIndex() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email') ->save(); @@ -769,7 +776,7 @@ public function testDropIndex() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname']) @@ -779,7 +786,7 @@ public function testDropIndex() $this->assertFalse($table2->hasIndex(['fname', 'lname'])); // index with name specified, but dropping it by column name - $table3 = new \Phinx\Db\Table('table3', [], $this->adapter); + $table3 = new Table('table3', [], $this->adapter); $table3->addColumn('email', 'string') ->addIndex('email', ['name' => 'someindexname']) ->save(); @@ -788,7 +795,7 @@ public function testDropIndex() $this->assertFalse($table3->hasIndex('email')); // multiple column index with name specified - $table4 = new \Phinx\Db\Table('table4', [], $this->adapter); + $table4 = new Table('table4', [], $this->adapter); $table4->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex(['fname', 'lname'], ['name' => 'multiname']) @@ -801,7 +808,7 @@ public function testDropIndex() public function testDropIndexByName() { // single column index - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('email', 'string') ->addIndex('email', ['name' => 'myemailindex']) ->save(); @@ -810,7 +817,7 @@ public function testDropIndexByName() $this->assertFalse($table->hasIndex('email')); // multiple column index - $table2 = new \Phinx\Db\Table('table2', [], $this->adapter); + $table2 = new Table('table2', [], $this->adapter); $table2->addColumn('fname', 'string') ->addColumn('lname', 'string') ->addIndex( @@ -825,13 +832,13 @@ public function testDropIndexByName() public function testAddForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->addColumn('ref_table_id', 'integer')->save(); - $fk = new \Phinx\Db\Table\ForeignKey(); + $fk = new ForeignKey(); $fk->setReferencedTable($refTable->getTable()) ->setColumns(['ref_table_id']) ->setReferencedColumns(['id']) @@ -843,13 +850,13 @@ public function testAddForeignKey() public function dropForeignKey() { - $refTable = new \Phinx\Db\Table('ref_table', [], $this->adapter); + $refTable = new Table('ref_table', [], $this->adapter); $refTable->addColumn('field1', 'string')->save(); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->addColumn('ref_table_id', 'integer')->save(); - $fk = new \Phinx\Db\Table\ForeignKey(); + $fk = new ForeignKey(); $fk->setReferencedTable($refTable) ->setColumns(['ref_table_id']) ->setReferencedColumns(['id']); @@ -914,7 +921,7 @@ public function testGetPhinxType() public function testAddColumnComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('field1', 'string', ['comment' => $comment = 'Comments from column "field1"']) ->save(); @@ -928,7 +935,7 @@ public function testAddColumnComment() */ public function testChangeColumnComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('field1', 'string', ['comment' => 'Comments from column "field1"']) ->save(); @@ -945,7 +952,7 @@ public function testChangeColumnComment() */ public function testRemoveColumnComment() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('field1', 'string', ['comment' => 'Comments from column "field1"']) ->save(); @@ -965,10 +972,10 @@ public function testForignKeysArePropertlyEscaped() $userId = 'user'; $sessionId = 'session'; - $local = new \Phinx\Db\Table('users', ['id' => $userId], $this->adapter); + $local = new Table('users', ['id' => $userId], $this->adapter); $local->create(); - $foreign = new \Phinx\Db\Table('sessions', ['id' => $sessionId], $this->adapter); + $foreign = new Table('sessions', ['id' => $sessionId], $this->adapter); $foreign->addColumn('user', 'integer') ->addForeignKey('user', 'users', $userId) ->create(); @@ -978,7 +985,7 @@ public function testForignKeysArePropertlyEscaped() public function testBulkInsertData() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->save(); @@ -1013,7 +1020,7 @@ public function testBulkInsertData() public function testInsertData() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->insert([ @@ -1046,7 +1053,7 @@ public function testInsertData() public function testTruncateTable() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') ->insert([ @@ -1076,7 +1083,7 @@ public function testDumpCreateTableAndThenInsert() $consoleOutput = new BufferedOutput(); $this->adapter->setOutput($consoleOutput); - $table = new \Phinx\Db\Table('table1', ['id' => false, 'primary_key' => ['column1']], $this->adapter); + $table = new Table('table1', ['id' => false, 'primary_key' => ['column1']], $this->adapter); $table->addColumn('column1', 'string', ['null' => false]) ->addColumn('column2', 'integer') @@ -1084,7 +1091,7 @@ public function testDumpCreateTableAndThenInsert() $expectedOutput = 'C'; - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->insert([ 'column1' => 'id1', 'column2' => 1, @@ -1107,7 +1114,7 @@ public function testDumpTransaction() $this->adapter->setOutput($consoleOutput); $this->adapter->beginTransaction(); - $table = new \Phinx\Db\Table('schema1.table1', [], $this->adapter); + $table = new Table('schema1.table1', [], $this->adapter); $table->addColumn('column1', 'string') ->addColumn('column2', 'integer') @@ -1126,7 +1133,7 @@ public function testDumpTransaction() */ public function testQueryBuilder() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -1167,7 +1174,7 @@ public function testQueryBuilder() public function testQueryWithParams() { - $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table = new Table('table1', [], $this->adapter); $table->addColumn('string_col', 'string') ->addColumn('int_col', 'integer') ->save(); @@ -1202,7 +1209,7 @@ public function testLiteralSupport() CREATE TABLE test (smallmoney_col smallmoney) INPUT; $this->adapter->execute($createQuery); - $table = new \Phinx\Db\Table('test', [], $this->adapter); + $table = new Table('test', [], $this->adapter); $columns = $table->getColumns(); $this->assertCount(1, $columns); $this->assertEquals(Literal::from('smallmoney'), array_pop($columns)->getType()); @@ -1222,7 +1229,7 @@ public function pdoAttributeProvider() public function testInvalidPdoAttribute($attribute) { $adapter = new SqlServerAdapter(SQLSRV_DB_CONFIG + [$attribute => true]); - $this->expectException(\UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Invalid PDO attribute: ' . $attribute . ' (\PDO::' . strtoupper($attribute) . ')'); $adapter->connect(); } diff --git a/tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php b/tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php index 7c281bc38..e9a638562 100644 --- a/tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php +++ b/tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php @@ -1,4 +1,5 @@ mock ->expects($this->once()) @@ -109,10 +111,10 @@ function ($table) { public function testChangePrimaryKey() { - $table = new Table('table'); + $table = new TableValue('table'); $newColumns = 'column1'; - $expectedTable = new Table('pre_table_suf'); + $expectedTable = new TableValue('pre_table_suf'); $this->mock ->expects($this->once()) ->method('changePrimaryKey') @@ -126,10 +128,10 @@ public function testChangePrimaryKey() public function testChangeComment() { - $table = new Table('table'); + $table = new TableValue('table'); $newComment = 'comment'; - $expectedTable = new Table('pre_table_suf'); + $expectedTable = new TableValue('pre_table_suf'); $this->mock ->expects($this->once()) ->method('changeComment') @@ -189,7 +191,7 @@ public function testHasColumn() public function testAddColumn() { - $table = new Table('table'); + $table = new TableValue('table'); $column = new Column(); $this->mock @@ -327,7 +329,7 @@ public function testHasForeignKey() public function testAddForeignKey() { - $table = new Table('table'); + $table = new TableValue('table'); $foreignKey = new ForeignKey(); $this->mock @@ -374,20 +376,20 @@ function ($table) { $this->equalTo($row) )); - $table = new \Phinx\Db\Table('table', [], $this->adapter); + $table = new Table('table', [], $this->adapter); $table->insert($row) ->save(); } public function actionsProvider() { - $table = new Table('my_test'); + $table = new TableValue('my_test'); return [ - [AddColumn::build($table, 'acolumn')], + [AddColumn::build($table, 'acolumn', 'int')], [AddIndex::build($table, ['acolumn'])], [AddForeignKey::build($table, ['acolumn'], 'another_table'), true], - [ChangeColumn::build($table, 'acolumn')], + [ChangeColumn::build($table, 'acolumn', 'int')], [DropForeignKey::build($table, ['acolumn'])], [DropIndex::build($table, ['acolumn'])], [new DropTable($table)], @@ -426,7 +428,7 @@ public function testExecuteActions($action, $checkReferecedTable = false) } })); - $table = new Table('my_test'); + $table = new TableValue('my_test'); $this->adapter->executeActions($table, [$action]); } } diff --git a/tests/Phinx/Db/Table/ColumnTest.php b/tests/Phinx/Db/Table/ColumnTest.php index d2000ce0d..38481488d 100644 --- a/tests/Phinx/Db/Table/ColumnTest.php +++ b/tests/Phinx/Db/Table/ColumnTest.php @@ -1,4 +1,5 @@ setType('badtype'); - $table = new \Phinx\Db\Table('ntable', [], $adapter); - $table->addColumn($column); - } catch (\InvalidArgumentException $e) { + $table = new Table('ntable', [], $adapter); + $table->addColumn($column, 'int'); + } catch (InvalidArgumentException $e) { $this->assertInstanceOf( 'InvalidArgumentException', $e, @@ -59,11 +65,11 @@ public function testAddColumnWithAnInvalidColumnType() public function testAddColumnWithColumnObject() { $adapter = new MysqlAdapter([]); - $column = new \Phinx\Db\Table\Column(); + $column = new Column(); $column->setName('email') ->setType('integer'); - $table = new \Phinx\Db\Table('ntable', [], $adapter); - $table->addColumn($column); + $table = new Table('ntable', [], $adapter); + $table->addColumn($column, 'int'); $actions = $this->getPendingActions($table); $this->assertInstanceOf('Phinx\Db\Action\AddColumn', $actions[0]); $this->assertSame($column, $actions[0]->getColumn()); @@ -72,10 +78,10 @@ public function testAddColumnWithColumnObject() public function testAddColumnWithNoAdapterSpecified() { try { - $table = new \Phinx\Db\Table('ntable'); + $table = new Table('ntable'); $table->addColumn('realname', 'string'); $this->fail('Expected the table object to throw an exception'); - } catch (\RuntimeException $e) { + } catch (RuntimeException $e) { $this->assertInstanceOf( 'RuntimeException', $e, @@ -87,7 +93,7 @@ public function testAddColumnWithNoAdapterSpecified() public function testAddComment() { $adapter = new MysqlAdapter([]); - $table = new \Phinx\Db\Table('ntable', ['comment' => 'test comment'], $adapter); + $table = new Table('ntable', ['comment' => 'test comment'], $adapter); $options = $table->getOptions(); $this->assertEquals('test comment', $options['comment']); } @@ -95,10 +101,10 @@ public function testAddComment() public function testAddIndexWithIndexObject() { $adapter = new MysqlAdapter([]); - $index = new \Phinx\Db\Table\Index(); - $index->setType(\Phinx\Db\Table\Index::INDEX) + $index = new Index(); + $index->setType(Index::INDEX) ->setColumns(['email']); - $table = new \Phinx\Db\Table('ntable', [], $adapter); + $table = new Table('ntable', [], $adapter); $table->addIndex($index); $actions = $this->getPendingActions($table); $this->assertInstanceOf('Phinx\Db\Action\AddIndex', $actions[0]); @@ -116,7 +122,7 @@ public function testAddIndexWithIndexObject() */ public function testAddTimestamps(AdapterInterface $adapter, $createdAtColumnName, $updatedAtColumnName, $expectedCreatedAtColumnName, $expectedUpdatedAtColumnName, $withTimezone) { - $table = new \Phinx\Db\Table('ntable', [], $adapter); + $table = new Table('ntable', [], $adapter); $table->addTimestamps($createdAtColumnName, $updatedAtColumnName, $withTimezone); $actions = $this->getPendingActions($table); @@ -146,7 +152,7 @@ public function testAddTimestamps(AdapterInterface $adapter, $createdAtColumnNam */ public function testAddTimestampsNoUpdated(AdapterInterface $adapter) { - $table = new \Phinx\Db\Table('ntable', [], $adapter); + $table = new Table('ntable', [], $adapter); $table->addTimestamps(null, false); $actions = $this->getPendingActions($table); @@ -171,7 +177,7 @@ public function testAddTimestampsNoUpdated(AdapterInterface $adapter) */ public function testAddTimestampsNoCreated(AdapterInterface $adapter) { - $table = new \Phinx\Db\Table('ntable', [], $adapter); + $table = new Table('ntable', [], $adapter); $table->addTimestamps(false, null); $actions = $this->getPendingActions($table); @@ -197,8 +203,8 @@ public function testAddTimestampsNoCreated(AdapterInterface $adapter) */ public function testAddTimestampsThrowsOnBothFalse(AdapterInterface $adapter) { - $table = new \Phinx\Db\Table('ntable', [], $adapter); - $this->expectException(\RuntimeException::class); + $table = new Table('ntable', [], $adapter); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Cannot set both created_at and updated_at columns to false'); $table->addTimestamps(false, false); } @@ -214,7 +220,7 @@ public function testAddTimestampsThrowsOnBothFalse(AdapterInterface $adapter) */ public function testAddTimestampsWithTimezone(AdapterInterface $adapter, $createdAtColumnName, $updatedAtColumnName, $expectedCreatedAtColumnName, $expectedUpdatedAtColumnName, $withTimezone) { - $table = new \Phinx\Db\Table('ntable', [], $adapter); + $table = new Table('ntable', [], $adapter); $table->addTimestampsWithTimezone($createdAtColumnName, $updatedAtColumnName); $actions = $this->getPendingActions($table); @@ -243,7 +249,7 @@ public function testInsert() $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') ->setConstructorArgs([[]]) ->getMock(); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $data = [ 'column1' => 'value1', 'column2' => 'value2', @@ -260,7 +266,7 @@ public function testInsertMultipleRowsWithoutZeroKey() $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') ->setConstructorArgs([[]]) ->getMock(); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $data = [ 1 => [ 'column1' => 'value1', @@ -281,7 +287,7 @@ public function testInsertSaveEmptyData() $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') ->setConstructorArgs([[]]) ->getMock(); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $adapterStub->expects($this->never())->method('bulkinsert'); @@ -293,7 +299,7 @@ public function testInsertSaveData() $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') ->setConstructorArgs([[]]) ->getMock(); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $data = [ [ 'column1' => 'value1', @@ -326,7 +332,7 @@ public function testSaveAfterSaveData() $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') ->setConstructorArgs([[]]) ->getMock(); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $data = [ [ 'column1' => 'value1', @@ -359,7 +365,7 @@ public function testResetAfterAddingData() $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') ->setConstructorArgs([[]]) ->getMock(); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $columns = ['column1']; $data = [['value1']]; $table->insert($columns, $data)->save(); @@ -371,7 +377,7 @@ public function testPendingAfterAddingData() $adapterStub = $this->getMockBuilder('\Phinx\Db\Adapter\MysqlAdapter') ->setConstructorArgs([[]]) ->getMock(); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $columns = ['column1']; $data = [['value1']]; $table->insert($columns, $data); @@ -386,7 +392,7 @@ public function testPendingAfterAddingColumn() $adapterStub->expects($this->any()) ->method('isValidColumnType') ->willReturn(true); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $table->addColumn('column1', 'integer', ['null' => true]); $this->assertTrue($table->hasPendingActions()); } @@ -397,7 +403,7 @@ public function testGetColumn() ->setConstructorArgs([[]]) ->getMock(); - $column1 = (new \Phinx\Db\Table\Column())->setName('column1'); + $column1 = (new Column())->setName('column1'); $adapterStub->expects($this->exactly(2)) ->method('getColumns') @@ -405,7 +411,7 @@ public function testGetColumn() $column1, ]); - $table = new \Phinx\Db\Table('ntable', [], $adapterStub); + $table = new Table('ntable', [], $adapterStub); $this->assertEquals($column1, $table->getColumn('column1')); $this->assertNull($table->getColumn('column2')); @@ -422,7 +428,7 @@ public function testRemoveIndex($indexIdentifier, Index $index) ->setConstructorArgs([[]]) ->getMock(); - $table = new \Phinx\Db\Table('table', [], $adapterStub); + $table = new Table('table', [], $adapterStub); $table->removeIndex($indexIdentifier); $indexes = array_map(function (DropIndex $action) { @@ -452,7 +458,7 @@ public function removeIndexDataprovider() protected function getPendingActions($table) { - $prop = new \ReflectionProperty(get_class($table), 'actions'); + $prop = new ReflectionProperty(get_class($table), 'actions'); $prop->setAccessible(true); return $prop->getValue($table)->getActions(); diff --git a/tests/Phinx/Migration/AbstractMigrationTest.php b/tests/Phinx/Migration/AbstractMigrationTest.php index b617752e6..d5c1edede 100644 --- a/tests/Phinx/Migration/AbstractMigrationTest.php +++ b/tests/Phinx/Migration/AbstractMigrationTest.php @@ -1,8 +1,10 @@ table('test_table'); $table->addColumn('column1', 'integer', ['null' => true]); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Migration has pending actions after execution!'); $migrationStub->postFlightCheck(); diff --git a/tests/Phinx/Migration/Manager/EnvironmentTest.php b/tests/Phinx/Migration/Manager/EnvironmentTest.php index 4ebeea88b..1e6b95587 100644 --- a/tests/Phinx/Migration/Manager/EnvironmentTest.php +++ b/tests/Phinx/Migration/Manager/EnvironmentTest.php @@ -1,13 +1,16 @@ registerAdapter('pdomock', $adapter); $this->environment->setOptions(['connection' => $this->getPdoMock()]); $options = $this->environment->getAdapter()->getOptions(); - $this->assertEquals(\PDO::ERRMODE_EXCEPTION, $options['connection']->getAttribute(\PDO::ATTR_ERRMODE)); + $this->assertEquals(PDO::ERRMODE_EXCEPTION, $options['connection']->getAttribute(PDO::ATTR_ERRMODE)); } public function testGetAdapterWithBadExistingPdoInstance() { - $this->environment->setOptions(['connection' => new \stdClass()]); + $this->environment->setOptions(['connection' => new stdClass()]); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('The specified connection is not a PDO instance'); @@ -104,7 +107,7 @@ public function testGetAdapterWithBadExistingPdoInstance() public function testTablePrefixAdapter() { $this->environment->setOptions(['table_prefix' => 'tbl_', 'adapter' => 'mysql']); - $this->assertInstanceOf(\Phinx\Db\Adapter\TablePrefixAdapter::class, $this->environment->getAdapter()); + $this->assertInstanceOf(TablePrefixAdapter::class, $this->environment->getAdapter()); $tablePrefixAdapter = $this->environment->getAdapter(); $this->assertInstanceOf('Phinx\Db\Adapter\MysqlAdapter', $tablePrefixAdapter->getAdapter()->getAdapter()); @@ -125,11 +128,11 @@ public function testCurrentVersion() ->getMock(); $stub->expects($this->any()) ->method('getVersions') - ->will($this->returnValue(['20110301080000'])); + ->will($this->returnValue([20110301080000])); $this->environment->setAdapter($stub); - $this->assertEquals('20110301080000', $this->environment->getCurrentVersion()); + $this->assertEquals(20110301080000, $this->environment->getCurrentVersion()); } public function testExecutingAMigrationUp() diff --git a/tests/Phinx/Migration/ManagerTest.php b/tests/Phinx/Migration/ManagerTest.php index f5b280d6b..d558adb28 100644 --- a/tests/Phinx/Migration/ManagerTest.php +++ b/tests/Phinx/Migration/ManagerTest.php @@ -1,7 +1,9 @@ will($this->returnValue($availableMigrations)); } $this->manager->setEnvironments(['mockenv' => $envStub]); - $this->manager->migrateToDateTime('mockenv', new \DateTime($dateString)); + $this->manager->migrateToDateTime('mockenv', new DateTime($dateString)); rewind($this->manager->getOutput()->getStream()); $output = stream_get_contents($this->manager->getOutput()->getStream()); if (is_null($expectedMigration)) { @@ -1514,7 +1516,7 @@ public function testRollbackToVersionByExecutionTime($availableRollbacks, $versi // get a manager with a config whose version order is set to execution time $configArray = $this->getConfigArray(); - $configArray['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $configArray['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $config = new Config($configArray); $this->input = new ArrayInput([]); $this->output = new StreamOutput(fopen('php://memory', 'a', false)); @@ -1557,7 +1559,7 @@ public function testRollbackToVersionByName($availableRollbacks, $version, $expe // get a manager with a config whose version order is set to execution time $configArray = $this->getConfigArray(); - $configArray['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $configArray['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $config = new Config($configArray); $this->input = new ArrayInput([]); $this->output = new StreamOutput(fopen('php://memory', 'a', false)); @@ -1600,7 +1602,7 @@ public function testRollbackToVersionByExecutionTimeWithNamespace($availableRoll // get a manager with a config whose version order is set to execution time $config = $this->getConfigWithNamespace(); - $config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $this->input = new ArrayInput([]); $this->output = new StreamOutput(fopen('php://memory', 'a', false)); $this->output->setDecorated(false); @@ -1642,7 +1644,7 @@ public function testRollbackToDateByExecutionTime($availableRollbacks, $date, $e // get a manager with a config whose version order is set to execution time $configArray = $this->getConfigArray(); - $configArray['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $configArray['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $config = new Config($configArray); $this->input = new ArrayInput([]); $this->output = new StreamOutput(fopen('php://memory', 'a', false)); @@ -1685,7 +1687,7 @@ public function testRollbackToDateByExecutionTimeWithNamespace($availableRollbac // get a manager with a config whose version order is set to execution time $config = $this->getConfigWithNamespace(); - $config['version_order'] = \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME; + $config['version_order'] = Config::VERSION_ORDER_EXECUTION_TIME; $this->input = new ArrayInput([]); $this->output = new StreamOutput(fopen('php://memory', 'a', false)); $this->output->setDecorated(false); @@ -4809,7 +4811,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 0], '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20120116183504 TestMigration2: reverted', ], @@ -4819,7 +4821,7 @@ public function rollbackLastDataProvider() '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-10 18:35:04', 'breakpoint' => 0], '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20120111235330 TestMigration: reverted', ], @@ -4830,7 +4832,7 @@ public function rollbackLastDataProvider() '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 0], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20120116183504 TestMigration2: reverted', ], @@ -4841,7 +4843,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 0], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20120111235330 TestMigration: reverted', ], @@ -4853,7 +4855,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 0], '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -4863,7 +4865,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 1], '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20120116183504 TestMigration2: reverted', ], @@ -4874,7 +4876,7 @@ public function rollbackLastDataProvider() '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 1], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -4885,7 +4887,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 1], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -4896,7 +4898,7 @@ public function rollbackLastDataProvider() '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 0], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20120116183504 TestMigration2: reverted', ], @@ -4907,7 +4909,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 0], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20120111235330 TestMigration: reverted', ], @@ -4919,7 +4921,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 1], '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -4929,7 +4931,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 1], '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -4940,7 +4942,7 @@ public function rollbackLastDataProvider() '20120116183504' => ['version' => '20120116183504', 'start_time' => '2012-01-16 18:35:04', 'breakpoint' => 1], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -4951,7 +4953,7 @@ public function rollbackLastDataProvider() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2012-01-12 23:53:30', 'breakpoint' => 1], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], ]; @@ -4974,7 +4976,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 0], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20160116183504 Foo\Bar\TestMigration2: reverted', ], @@ -4984,7 +4986,7 @@ public function rollbackLastDataProviderWithNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-10 18:35:04', 'breakpoint' => 0], '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20160111235330 Foo\Bar\TestMigration: reverted', ], @@ -4995,7 +4997,7 @@ public function rollbackLastDataProviderWithNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 0], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20160116183504 Foo\Bar\TestMigration2: reverted', ], @@ -5006,7 +5008,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 0], '20170101225232' => ['version' => '20130101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20160111235330 Foo\Bar\TestMigration: reverted', ], @@ -5018,7 +5020,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 0], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5028,7 +5030,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 1], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20160116183504 Foo\Bar\TestMigration2: reverted', ], @@ -5039,7 +5041,7 @@ public function rollbackLastDataProviderWithNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 1], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5050,7 +5052,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 1], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5061,7 +5063,7 @@ public function rollbackLastDataProviderWithNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 0], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20160116183504 Foo\Bar\TestMigration2: reverted', ], @@ -5072,7 +5074,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 0], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20160111235330 Foo\Bar\TestMigration: reverted', ], @@ -5084,7 +5086,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 1], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5094,7 +5096,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 1], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5105,7 +5107,7 @@ public function rollbackLastDataProviderWithNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2016-01-16 18:35:04', 'breakpoint' => 1], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5116,7 +5118,7 @@ public function rollbackLastDataProviderWithNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2016-01-12 23:53:30', 'breakpoint' => 1], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], ]; @@ -5143,7 +5145,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2017-01-01 00:00:04', 'breakpoint' => 0], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20160116183504 Foo\Bar\TestMigration2: reverted', ], @@ -5157,7 +5159,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20150111235330' => ['version' => '20150111235330', 'start_time' => '2017-01-01 00:00:06', 'breakpoint' => 0], '20150116183504' => ['version' => '20150116183504', 'start_time' => '2017-01-01 00:00:07', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20150116183504 Baz\TestMigration2: reverted', ], @@ -5172,7 +5174,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 0], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20160116183504 Foo\Bar\TestMigration2: reverted', ], @@ -5187,7 +5189,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20120116183504' => ['version' => '20120116183504', 'start_time' => '2017-01-01 00:00:07', 'breakpoint' => 0], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20120116183504 TestMigration2: reverted', ], @@ -5203,7 +5205,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2017-01-01 00:00:04', 'breakpoint' => 0], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5217,7 +5219,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2017-01-01 00:00:04', 'breakpoint' => 1], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20160116183504 Foo\Bar\TestMigration2: reverted', ], @@ -5232,7 +5234,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 1], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5247,7 +5249,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 1], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 0], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5262,7 +5264,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 0], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, '== 20160116183504 Foo\Bar\TestMigration2: reverted', ], @@ -5277,7 +5279,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20120111235330' => ['version' => '20120111235330', 'start_time' => '2017-01-01 00:00:06', 'breakpoint' => 0], '20130101225232' => ['version' => '20130101225232', 'start_time' => '2013-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, '== 20120111235330 TestMigration: reverted', ], @@ -5293,7 +5295,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2017-01-01 00:00:04', 'breakpoint' => 1], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5307,7 +5309,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160111235330' => ['version' => '20160111235330', 'start_time' => '2017-01-01 00:00:04', 'breakpoint' => 1], '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5322,7 +5324,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 1], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME, + Config::VERSION_ORDER_CREATION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], @@ -5337,7 +5339,7 @@ public function rollbackLastDataProviderWithMixedNamespace() '20160116183504' => ['version' => '20160116183504', 'start_time' => '2017-01-01 00:00:05', 'breakpoint' => 1], '20170101225232' => ['version' => '20170101225232', 'start_time' => '2017-01-01 22:52:32', 'breakpoint' => 1], ], - \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME, + Config::VERSION_ORDER_EXECUTION_TIME, 'Breakpoint reached. Further rollbacks inhibited.', ], ]; @@ -6034,7 +6036,7 @@ public function testMigrationWithDropColumnAndForeignKeyAndIndex() $adapter->disconnect(); $this->manager->setConfig($config); - $this->manager->migrate('production', '20190928205056'); + $this->manager->migrate('production', 20190928205056); $this->assertTrue($adapter->hasTable('table1')); $this->assertTrue($adapter->hasTable('table2')); @@ -6097,7 +6099,7 @@ public function testInvalidVersionBreakpoint() $this->manager->setEnvironments(['mockenv' => $envStub]); $this->manager->getOutput()->setDecorated(false); - $return = $this->manager->setBreakpoint('mockenv', '20120133235330'); + $this->manager->setBreakpoint('mockenv', 20120133235330); rewind($this->manager->getOutput()->getStream()); $outputStr = stream_get_contents($this->manager->getOutput()->getStream()); @@ -6123,12 +6125,12 @@ public function testMigrationWillNotBeExecuted() // Run the migration with shouldExecute returning false: the table should not be created $this->manager->setConfig($config); - $this->manager->migrate('production', '20201207205056'); + $this->manager->migrate('production', 20201207205056); $this->assertFalse($adapter->hasTable('info')); // Run the migration with shouldExecute returning true: the table should be created - $this->manager->migrate('production', '20201207205057'); + $this->manager->migrate('production', 20201207205057); $this->assertTrue($adapter->hasTable('info')); } diff --git a/tests/Phinx/TestCase.php b/tests/Phinx/TestCase.php index a9c047c75..e86d2e522 100644 --- a/tests/Phinx/TestCase.php +++ b/tests/Phinx/TestCase.php @@ -1,5 +1,4 @@ isDir()) { rmdir($file->getPathname()); diff --git a/tests/Phinx/Util/ExpressionTest.php b/tests/Phinx/Util/ExpressionTest.php index 0715c2a4c..0ae75fe71 100644 --- a/tests/Phinx/Util/ExpressionTest.php +++ b/tests/Phinx/Util/ExpressionTest.php @@ -1,5 +1,5 @@ format(Util::DATE_FORMAT); $current = Util::getCurrentTimestamp(); diff --git a/tests/Phinx/Wrapper/TextWrapperTest.php b/tests/Phinx/Wrapper/TextWrapperTest.php index 13203c915..1c4afa858 100644 --- a/tests/Phinx/Wrapper/TextWrapperTest.php +++ b/tests/Phinx/Wrapper/TextWrapperTest.php @@ -1,5 +1,4 @@