3

I'm upgrading a CakePHP 3 app to CakePHP 4, and following the Upgrade Guide.

However, the bin/cake upgrade rector --rules phpunit80 <path/to/app/tests> tool hangs.

A little background, my app was made mostly in CakePHP 3.6. I upgraded it to 3.7, then 3.8, then 3.9 and made sure everything as working (no deprecation warnings) before attempting the upgrade to 4.

I'm following the CakePHP 4.0 upgrade guide. All steps are successful up to "Applying Rector Refactorings".

When I run this:

PS C:\xampp\htdocs\my_app\upgrade> bin/cake upgrade rector --rules phpunit80 C:\xampp\htdocs\my_app\tests

I get this result:

Rector v0.7.26

Then,

0/189 [>---------------------------]   0%

And it just hangs there (about 1 hour already).

Is there any advice on how to solve this?

Thanks! D.

ndm
  • 59,784
  • 9
  • 71
  • 110
dividedbyzero
  • 181
  • 2
  • 13
  • Just an additional note... the same thing happens with the bin/cake upgrade rector --rules cakephp40 command. – dividedbyzero May 30 '20 at 06:51
  • "(no deprecation warnings)" are you sure? Did you try composer cs-check , composer cs-fix, phpstan before try to migrate to 4.x ? – Salines May 30 '20 at 09:37
  • Maybe there are errors that are being swallowed, check your CakePHP logs and your general PHP error logs. – ndm May 30 '20 at 10:10
  • Thanks for your replies. The only error in my CakePHP logs is: Error: [Cake\Routing\Exception\MissingControllerException] Controller class Fonts could not be found. (C:\xampp\htdocs\my_app\vendor\cakephp\cakephp\src\Http\ControllerFactory.php:105) composer cs-check yields: 'phpcs' is not recognized as an internal or external command, operable program or batch file. Script phpcs --colors --parallel=16 -p -s src/ tests/ handling the cs-check event returned with error code 1 – dividedbyzero May 30 '20 at 13:09
  • OK... running composer cs-check in my app directory yields several issues. The first is: Deprecation Notice: Array and string offset access syntax with curly braces is deprecated in C:\xampp\htdocs\my_app\vendor\cakephp\plugin-installer\src\Installer\PluginInstaller.php:170 > phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/ – dividedbyzero May 30 '20 at 13:17
  • Note that I have not do "update-with-dependencies" yet to upgrade to 4.... I'm following the upgrade guide. – dividedbyzero May 30 '20 at 13:18
  • Check your default PHP error logs too, Rector is being run in a separate PHP process! – ndm May 30 '20 at 13:42
  • I had some problems too in order to upgrade my tests. I finally started from brand new tests build with cake bake (4.0), and copy the functions from the 3.0 tests files. – dype May 30 '20 at 13:51
  • So when I run to update tests, the PHP error log shows: PHP Notice: Undefined property: PhpParser\Node\Expr\ArrayItem::$unpack in C:\xampp\htdocs\my_app\upgrade\vendor\nikic\php-parser\lib\PhpParser\PrettyPrinter\Standard.php on line 558 – dividedbyzero May 31 '20 at 02:21
  • When running upgrade rector --rules cakephp40, I get the same Notice on nikic, and also a new one: PHP Notice: Undefined property: PhpParser\Node\Expr\ArrayItem::$unpack in phar://C:/xampp/htdocs/my_app/upgrade/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php on line 846 – dividedbyzero May 31 '20 at 02:27
  • That might be some weird combination of PHP version and dependency version requirement. What version of `rector/rector`, `phpstan/phpstan`, and `nikic/php-parser` were being installed for the upgrade tool (you can check for example `composer show --installed`)? Also what's your local PHP version? – ndm May 31 '20 at 20:48
  • Hi ndm, `rector/rector` = v0.7.26, `phpstan/phpstan` = 0.12.25, `nikic/php-parser` = v4.4.0, and the PHP Version is 7.4.1. This is running `composer show --installed` in the upgrade folder. – dividedbyzero Jun 01 '20 at 00:14
  • Well that looks OK. I've just tried it, and it hangs for me too, can't even run `rector --version`. You may want to report an issue over at GitHub. – ndm Jun 01 '20 at 10:50
  • Thanks ndm. I'll report it over there. Meanwhile I'm trying the upgrade in a lower version of PHP (7.2) on a separate in installation of XAMPP. Once I figure it our I'll come back here with an answer. Thanks for looking in to it. – dividedbyzero Jun 01 '20 at 11:44
  • Just an FYI, I setup a new installation of XAMPP using PHP version 7.2.31, and the result is the same. One thing I noticed when I ran the step `composer install --no-dev` is a message reading `Class Cake\Composer\Installer\PluginInstaller is not autoloadable, can not call post-autoload-dump script`. I'm not sure if this is part of the problem or not... – dividedbyzero Jun 02 '20 at 11:29

1 Answers1

3

Well, I sort of figured out a solution to the problem. Here it how I got Rector to work.

  1. Downgraded my app's Cake version to 3.8.12 (was 3.9.0-RC2)
  2. Manually fixed curly braces deprecation notice in app\vendor\cakephp\plugin-installer\src\Installer\PluginInstaller.php:170
  3. To fix Class Cake\Composer\Installer\PluginInstaller is not autoloadable, can not call post-autoload-dump script, I deleted my app\vendor folder, then ran composer update, and that seemed to fix that. Did not get that error up to here.
  4. Made a backup of the well working app here and started the upgrade steps in 4.0 Upgrade Guide.
  5. In \upgrade, ran composer install --no-dev, again got the message Class Cake\Composer\Installer\PluginInstaller is not autoloadable, can not call post-autoload-dump script.
  6. Ran bin/cake upgrade file_rename locales <path/to/app>. No issues.
  7. Ran bin/cake upgrade file_rename templates <path/to/app>. OK, no issues.
  8. Changed my config/app.php to be App=> paths => templates from 'templates' => [APP . 'Template' . DS], to 'templates' => [ROOT . DS . 'Template' . DS], (also did locales).
  9. Ran bin/cake upgrade rector --rules phpunit80 <path/to/app/tests> and now got results. It seemed to do all the updates, and output some errors, but I decided to go forward.
  10. Ran bin/cake upgrade rector --rules cakephp40 <path/to/app/src>, and now it seems to work. It shows the number of files updated, lots of progress bars, etc. It started outputting changes made in my controllers (in alphabetical order) but then it hangs after the first several controllers. However, looking into my src folders, I can see that all the controllers, models, etc are updated (last modified date is just now).
  11. Ran composer require --update-with-dependencies "phpunit/phpunit:^8.0". Completes and looks OK.
  12. Ran composer require --update-with-dependencies "cakephp/cakephp:4.0. LOTS of dependancy issues here. I took some alternate steps and got everything updated (actually copied the composer.json from here). That seemed to fix the dependency problems, but there are still myriad issues with the upgraded app.

I'm not going further here as this info above addresses the original question, and I have yet to complete a clean upgrade. Ultimately, I am leaning towards starting a fresh, clean app installation and rebuilding my app, copying and fixing code from the refactored files (like dype mentioned above).

Anyway, thanks for your replies. Have a good one, D.

dividedbyzero
  • 181
  • 2
  • 13