cakephp / upgrade

Upgrade tools for CakePHP meant to facilitate migrating from one version of the framework to another
MIT License
110 stars 60 forks source link

`laminas/laminas-diactoros` vs `zendframework/zend-diactoros` #257

Closed mehov closed 11 months ago

mehov commented 11 months ago

Hi everyone!

Trying to upgrade a CakePHP 3 site to CakePHP 4.

Applying cakephp40 Rector rules
PHP Fatal error:  Cannot redeclare Zend\Diactoros\createUploadedFile() (previously declared in /var/www/upgrade/vendor/laminas/laminas-diactoros/src/functions/create_uploaded_file.legacy.php:15) in /var/www/site/vendor/zendframework/zend-diactoros/src/functions/create_uploaded_file.php on line 20
Fatal error: Cannot redeclare Zend\Diactoros\createUploadedFile() (previously declared in /var/www/upgrade/vendor/laminas/laminas-diactoros/src/functions/create_uploaded_file.legacy.php:15) in /var/www/site/vendor/zendframework/zend-diactoros/src/functions/create_uploaded_file.php on line 20

Rector applied successfully
Applying phpunit80 Rector rules
PHP Fatal error:  Cannot redeclare Zend\Diactoros\createUploadedFile() (previously declared in /var/www/upgrade/vendor/laminas/laminas-diactoros/src/functions/create_uploaded_file.legacy.php:15) in /var/www/site/vendor/zendframework/zend-diactoros/src/functions/create_uploaded_file.php on line 20
Fatal error: Cannot redeclare Zend\Diactoros\createUploadedFile() (previously declared in /var/www/upgrade/vendor/laminas/laminas-diactoros/src/functions/create_uploaded_file.legacy.php:15) in /var/www/site/vendor/zendframework/zend-diactoros/src/functions/create_uploaded_file.php on line 20

Rector applied successfully

This is because zend-diactoros and laminas-diactoros define the same function in the same namespace (https://github.com/laminas/laminas-diactoros/issues/42). The upgrade tool is built on newer CakePHP that uses laminas-diactoros, while my CakePHP 3 site still uses zend-diactoros.

/var/www/site# composer why zendframework/zend-diactoros
cakephp/cakephp 3.8.8 requires zendframework/zend-diactoros (^1.4.0) 
/var/www/site/composer.json ``` { "name": "cakephp/app", "description": "CakePHP skeleton app", "homepage": "http://cakephp.org", "type": "project", "license": "MIT", "require": { "php": ">=5.6", "cakephp/cakephp": "3.8.8", "mobiledetect/mobiledetectlib": "2.*", "cakephp/migrations": "~1.0", "cakephp/plugin-installer": "~1.0", "nixsolutions-fork/yandex-php-library": "^3.0", "dompdf/dompdf": "^0.8.2", "friendsofcake/bootstrap-ui": "^1.3", "aws/aws-sdk-php": "^3.67" }, "require-dev": { "psy/psysh": "@stable", "cakephp/debug_kit": "~3.2", "cakephp/bake": "~1.1", "phpunit/phpunit": "^5.7|^6.0" }, "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", "OpencartAPI\\": "plugins/OpencartAPI/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": { "allow-plugins": { "cakephp/plugin-installer": true } } } ```
/var/www/site/vendor/cakephp/cakephp/composer.json ``` { "name": "cakephp/cakephp", "description": "The CakePHP framework", "type": "library", "keywords": [ "framework", "mvc", "rapid-development", "conventions over configuration", "dry", "orm", "form", "validation", "psr-7" ], "homepage": "https://cakephp.org", "license": "MIT", "authors": [ { "name": "CakePHP Community", "homepage": "https://github.com/cakephp/cakephp/graphs/contributors" } ], "support": { "issues": "https://github.com/cakephp/cakephp/issues", "forum": "https://stackoverflow.com/tags/cakephp", "irc": "irc://irc.freenode.org/cakephp", "source": "https://github.com/cakephp/cakephp" }, "require": { "php": ">=5.6.0", "ext-intl": "*", "ext-mbstring": "*", "cakephp/chronos": "^1.0.1", "aura/intl": "^3.0.0", "psr/log": "^1.0.0", "psr/simple-cache": "^1.0.0", "zendframework/zend-diactoros": "^1.4.0" }, "suggest": { "ext-openssl": "To use Security::encrypt() or have secure CSRF token generation.", "ext-curl": "To enable more efficient network calls in Http\\Client.", "lib-ICU": "The intl PHP library, to use Text::transliterate() or Text::slug()" }, "require-dev": { "cakephp/cakephp-codesniffer": "^3.0", "cakephp/chronos": "^1.2.1", "phpunit/phpunit": "^5.7.14|^6.0" }, "autoload": { "psr-4": { "Cake\\": "src/" }, "files": [ "src/Core/functions.php", "src/Collection/functions.php", "src/I18n/functions.php", "src/Utility/bootstrap.php" ] }, "autoload-dev": { "psr-4": { "Cake\\PHPStan\\": "tests/PHPStan/", "Cake\\Test\\": "tests/", "TestApp\\": "tests/test_app/TestApp/", "TestPlugin\\": "tests/test_app/Plugin/TestPlugin/src/", "TestPlugin\\Test\\": "tests/test_app/Plugin/TestPlugin/tests/", "TestPluginTwo\\": "tests/test_app/Plugin/TestPluginTwo/src/", "Company\\TestPluginThree\\": "tests/test_app/Plugin/Company/TestPluginThree/src/", "Company\\TestPluginThree\\Test\\": "tests/test_app/Plugin/Company/TestPluginThree/tests/", "ParentPlugin\\": "tests/test_app/Plugin/ParentPlugin/src/", "PluginJs\\": "tests/test_app/Plugin/PluginJs/src/" } }, "replace": { "cakephp/cache": "self.version", "cakephp/collection": "self.version", "cakephp/core": "self.version", "cakephp/datasource": "self.version", "cakephp/database": "self.version", "cakephp/event": "self.version", "cakephp/filesystem": "self.version", "cakephp/form": "self.version", "cakephp/i18n": "self.version", "cakephp/log": "self.version", "cakephp/orm": "self.version", "cakephp/utility": "self.version", "cakephp/validation": "self.version" }, "conflict": { "phpunit/phpunit": "<5.7" }, "scripts": { "check": [ "@cs-check", "@test" ], "cs-check": "phpcs --colors --parallel=16 -p src/ tests/", "cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/", "test": "phpunit", "test-coverage": "phpunit --coverage-clover=clover.xml", "phpstan": "phpstan analyse -c phpstan.neon -l 2 src/", "phpstan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan-shim:^0.11 && mv composer.backup composer.json" } } ```
othercorey commented 11 months ago

This feels like a bug in the version of rector used by the cake4 upgrade tool.

LordSimal commented 11 months ago

@mehov before going to Cake4 please upgrade your Cake3 app to the latest 3.10.5 and fix all deprecations there.

It will (as you can see here) have the correct version of diactoros in the composer.json. Then you can go to Cake4.

This change was done in CakePHP 3.9 as you can see in https://github.com/cakephp/cakephp/pull/14508