Search code examples
phpcakephpcakephp-3.0phinx

CakePHP 3 / Phinx exception when runned from the CLI


I have a running CakePHP 3 project on which I use Phinx migrations. This morning I just changed one migration file, didn't do a rollback, but instead I dropped all tables and hoped that it will just re-run the migrations as before. So when I issue these commands:

bin/cake migrations migrate
bin/cake migrations rollback
bin/cake migrations status

Or whatever related to migrations, I get the following exception thrown in the CLI:

Exception: Argument 2 passed to Phinx\Migration\Manager::__construct() must
implement interface Symfony\Component\Console\Input\InputInterface, instance of
Symfony\Component\Console\Output\ConsoleOutput given, called in
/var/www/html/vendor/cakephp/migrations/src/ConfigurationTrait.php on line 191
in [/var/www/html/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php, line 89]

I have tried re-running composer update / install even dump-autoload, but nothing changed.

I do not know where to start debugging this.

One thing worth mentioning is that I use a custom error handler, for both the CLI and the web interaface. Respectivelly both of my custom error handlers extend their appopriate classes: \Cake\Console\ConsoleErrorHandler and \Cake\Error\ErrorHandler.

When I run composer info I get this output:

ajgl/breakpoint-twig-extension             0.3.1                     Twig extension to set breakpoints
aptoma/twig-markdown                       2.0.0                     Twig extension to work with Markdown content
asm89/twig-cache-extension                 1.3.2                     Cache fragments of templates directly within Twig.
aura/intl                                  3.0.0                     The Aura Intl package provides internationalization tools, specifically message trans...
cakephp/bake                               1.7.2                     Bake plugin for CakePHP 3
cakephp/cakephp                            3.6.1                     The CakePHP framework
cakephp/cakephp-codesniffer                3.0.3                     CakePHP CodeSniffer Standards
cakephp/chronos                            1.1.4                     A simple API extension for DateTime.
cakephp/debug_kit                          3.15.2                    CakePHP Debug Kit
cakephp/migrations                         1.3                       Database Migration plugin for CakePHP 3.0 based on Phinx
cakephp/plugin-installer                   1.1.0                     A composer installer for CakePHP 3.0+ plugins.
composer/ca-bundle                         1.1.1                     Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla ...
composer/composer                          1.6.4                     Composer helps you declare, manage and install dependencies of PHP projects, ensuring...
composer/semver                            1.4.2                     Semver library that offers utilities, version constraint parsing and validation.
composer/spdx-licenses                     1.3.0                     SPDX licenses list and validation library.
crabstudio/recaptcha                       2.1.0                     Easily use Google Recaptcha in CakePHP 3.2+ projects
dnoegel/php-xdg-base-dir                   0.1                       implementation of xdg base directory specification for php
florianwolters/component-core-stringutils  v0.3.1                    Offers operations on the data type string as a PHP component.
florianwolters/component-util-reflection   v0.2.0                    Provides operations for the PHP Reflection API as a PHP component.
florianwolters/component-util-singleton    v0.3.2                    The Singleton (and Registry of Singletons a.k.a. Multiton) design pattern as a PHP co...
guzzlehttp/guzzle                          6.3.3                     Guzzle is a PHP HTTP client library
guzzlehttp/promises                        v1.3.1                    Guzzle promises library
guzzlehttp/psr7                            1.4.2                     PSR-7 message implementation that also provides common utility methods
jakub-onderka/php-console-color            0.1                      
jakub-onderka/php-console-highlighter      v0.3.2                   
jasny/twig-extensions                      v1.2.0                    A set of useful Twig filters
jdorn/sql-formatter                        v1.2.17                   a PHP SQL highlighting library
josegonzalez/dotenv                        2.1.0                     dotenv file parsing for PHP
justinrainbow/json-schema                  5.2.7                     A library to validate a json schema.
m1/env                                     2.1.0                     Env is a lightweight library bringing .env file parser compatibility to PHP. In short...
mnsami/composer-custom-directory-installer 1.1.1                     A composer plugin, to help install packages of different types in custom paths.
mobiledetect/mobiledetectlib               2.8.31                    Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the Us...
nikic/php-parser                           v4.0.1                    A PHP parser written in PHP
predis/predis                              v1.1.1                    Flexible and feature-complete Redis client for PHP and HHVM
psr/http-message                           1.0.1                     Common interface for HTTP messages
psr/log                                    1.0.2                     Common interface for logging libraries
psy/psysh                                  v0.9.3                    An interactive shell for modern PHP.
robmorgan/phinx                            0.9.2                     Phinx makes it ridiculously easy to manage the database migrations for your PHP app.
seld/cli-prompt                            1.0.3                     Allows you to prompt for user input on the command line, and optionally hide the char...
seld/jsonlint                              1.7.1                     JSON Linter
seld/phar-utils                            1.0.1                     PHAR file format utilities, for when PHP phars you up
squizlabs/php_codesniffer                  3.2.3                     PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a d...
symfony/config                             v4.0.8                    Symfony Config Component
symfony/console                            v4.0.8                    Symfony Console Component
symfony/filesystem                         v4.0.8                    Symfony Filesystem Component
symfony/finder                             v4.0.8                    Symfony Finder Component
symfony/polyfill-mbstring                  v1.7.0                    Symfony polyfill for the Mbstring extension
symfony/polyfill-php72                     v1.7.0                    Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process                            v4.0.8                    Symfony Process Component
symfony/var-dumper                         v4.0.8                    Symfony mechanism for exploring and dumping PHP variables
symfony/yaml                               v4.0.8                    Symfony Yaml Component
twig/twig                                  v1.35.3                   Twig, the flexible, fast, and secure template language for PHP
umpirsky/twig-php-function                 v0.1                      Call (almost) any PHP function from your Twig templates.
wyrihaximus/twig-view                      4.3.4                     Twig powered View for CakePHP3
zendframework/zend-diactoros               1.7.1                     PSR HTTP Message implementations

And the contents of composer.json file are as:

{
    "name": "cakephp/app",
    "description": "CakePHP skeleton app",
    "homepage": "https://cakephp.org",
    "type": "project",
    "license": "MIT",
    "require": {
        "php": ">=5.6",
        "cakephp/cakephp": "^3.5",
        "cakephp/migrations": "^1.8",
        "cakephp/plugin-installer": "^1.0",
        "crabstudio/recaptcha": "^2.0",
        "guzzlehttp/guzzle": "^6.3",
        "josegonzalez/dotenv": "2.*",
        "mobiledetect/mobiledetectlib": "2.*"
    },
    "require-dev": {
        "cakephp/bake": "^1.1",
        "cakephp/cakephp-codesniffer": "^3.0",
        "cakephp/debug_kit": "^3.2",
        "psy/psysh": "@stable"
    },
    "suggest": {
        "markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
        "dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan compatibility.",
        "phpunit/phpunit": "Allows automated tests to be run without system-wide install.",
        "cakephp/cakephp-codesniffer": "Allows to check the code against the coding standards used in CakePHP."
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Test\\": "tests/",
            "Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
        }
    },
    "scripts": {
        "post-install-cmd": "App\\Console\\Installer::postInstall",
        "post-create-project-cmd": "App\\Console\\Installer::postInstall",
        "post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
        "check": [
            "@test",
            "@cs-check"
        ],
        "cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests",
        "cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests",
        "test": "phpunit --colors=always"
    },
    "prefer-stable": true,
    "config": {
        "sort-packages": true
    }
}

Solution

  • It looks like your composer packages got out of sync.

    To force a refresh delete the vendor folder also delete composer.lock and then run

    composer install

    It will download everything again, rebuild your vendor and make sure Phinx and Symphony are in sync again.

    After you do this, you run your migrations again and see what happens.

    This statement of yours

    "I dropped all tables and hoped that it will just re-run the migrations as before."

    worries me a bit, because the Phinx migration manger keeps its log in the database in a table called phinxlog (sometimes prefixed with a plugin name if you're talking about a plugin). If you deleted that then phix does not know what migrations did you run already and which ones are new. To fix this you may need to mark some of the earlier migrations are migrated so phinx does not attempt to do things that were already done.