rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.72k stars 687 forks source link

[ERROR] Could not process "..." file, due to: "System error: ... #6932

Closed kenjis closed 2 years ago

kenjis commented 2 years ago

How to reproduce:

$ git clone git@github.com:kenjis/CodeIgniter4.git --branch=rector-system-error --depth=1
$ composer update
$ vendor/bin/rector process tests/system/Validation/StrictRules/ValidationTest.php --debug
<span class="help-block">

 [ERROR] Could not process "tests/system/Validation/StrictRules/ValidationTest.php" file, due to:   
         "System error: "Error (Call to undefined function esc()) thrown while looking for class    
         CodeIgniter\Validation\Views\single."                                                      
         Run Rector with "--debug" option and post the report here:                                 
         https://github.com/rectorphp/rector/issues/new". On line: 193                              

Environment:

kenjis commented 2 years ago

The file could be fixed with non PARALLEL mode.

1) tests/system/Validation/StrictRules/ValidationTest.php:26

    ---------- begin diff ----------
@@ @@
  */
 final class ValidationTest extends CIUnitTestCase
 {
-    /**
-     * @var Validation
-     */
-    private $validation;
+    private Validation $validation;

-    private $config = [
+    private array $config = [
         'ruleSets' => [
             Rules::class,
             FormatRules::class,
    ----------- end diff -----------

Applied rules:
 * TypedPropertyRector (https://wiki.php.net/rfc/typed_properties_v2#proposal)
samsonasik commented 2 years ago

@kenjis thank you, the TypedPropertyRector seems somehow try load esc() function when autoload is lost during parallel process.

It possibly need update on TypedPropertyRector to not call actual result of file_get_contents() on render view on Validation::listErrors()

samsonasik commented 2 years ago

@kenjis it seems somehow when read the array:

'single' => 'CodeIgniter\Validation\Views\single',

https://github.com/kenjis/CodeIgniter4/blob/e35b6074dc88ec42745772f760ff428e3f2e192f/tests/system/Validation/StrictRules/ValidationTest.php#L70

it marked as class on parallel.

samsonasik commented 2 years ago

@kenjis the solution I found right now for your parallel use case is to move the config to tests/_support/Config/Validation.php to be included, eg:

<?php

namespace Tests\Support\Config;

class Validation
{
    public const CONFIG = [
            'ruleSets' => [
                Rules::class,
                FormatRules::class,
                FileRules::class,
                CreditCardRules::class,
                TestRules::class,
            ],
            'groupA' => [
                'foo' => 'required|min_length[5]',
            ],
            'login' => [
                'username' => [
                    'label'  => 'Username',
                    'rules'  => 'required',
                    'errors' => [
                        'required' => 'custom username required error msg.',
                    ],
                ],
                'password' => [
                    'label'  => 'Password',
                    'rules'  => 'required',
                    'errors' => [
                        'required' => 'custom password required error msg.',
                    ],
                ],
            ],
            'groupA_errors' => [
                'foo' => [
                    'min_length' => 'Shame, shame. Too short.',
                ],
            ],
            'groupX'    => 'Not an array, so not a real group',
            'templates' => [
                'list'   => 'CodeIgniter\Validation\Views\list',
                'single' => 'CodeIgniter\Validation\Views\single',
            ],
        ];
}

So in your ValidationTest.php, you can use:

    private array $config = \Tests\Support\Config\Validation::CONFIG;
TomasVotruba commented 2 years ago

Closing as answered. We're narrowing issues to keep focus on active and engaging contributor to keep project growing. Thank you for understanding.

worldpodcastnetwork commented 11 months ago

@TomasVotruba If you could help me and just let know where to add the parallel code, I would appreciate it. I am not sure why my last post was deleted.