Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infection gets stuck in the first execution after configuration file is created #576

Closed
y-uti opened this issue Nov 20, 2018 · 3 comments
Closed

Comments

@y-uti
Copy link

y-uti commented Nov 20, 2018

Question Answer
Infection version 0.11.2 and also master branch
Test Framework version PHPUnit 7.4.4
PHP version 7.2.12
Platform CentOS 7.5
Github Repo -

At the first execution of Infection, it creates infection.json.dist and then it runs testcases. In this time, the configuration is not loaded properly and the execution goes wrong.

Output with issue

In the following output, Infection is executed with phpdbg and breakpoint is set on

$this->includeUserBootstrap($config);
. Here configuration should be loaded properly IMO.

At the first execution (I don't have infection.json.dist)

$ phpdbg vendor/bin/infection
[Welcome to phpdbg, the interactive PHP debugger, v0.5.0]
To get help using phpdbg type "help" and press enter
[Please report bugs to <http://bugs.php.net/report.php>]
[Successful compilation of /tmp/sandbox/vendor/infection/infection/bin/infection]
prompt> break vendor/infection/infection/src/Command/InfectionCommand.php:207
[Breakpoint #0 added at /tmp/sandbox/vendor/infection/infection/src/Command/InfectionCommand.php:207]
prompt> run
You are running Infection with phpdbg enabled.
     ____      ____          __  _
    /  _/___  / __/__  _____/ /_(_)___  ____
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/



  Welcome to the Infection config generator



We did not find a configuration file. The following questions will help us to generate it for you.


Which source directories do you want to include (comma separated)? [src]:
  [0] .
  [1] src
  [2] src.bak
  [3] tests
  [4] tests.bak
  [5] vendor
 >

There can be situations when you want to exclude some folders from generating mutants.
You can use glob pattern (*Bundle/**/*/Tests) for them or just regular dir path.
It should be relative to the source directory.
You should not mutate test suite files.
Press <return> to stop/skip adding dirs.

Any directories to exclude from within your source directories?:

Single test suite timeout in seconds [10]:

Where do you want to store the text log file? [infection.log]:

Configuration file "infection.json.dist" was created.

[Breakpoint #0 at /tmp/sandbox/vendor/infection/infection/src/Command/InfectionCommand.php:207, hits: 1]
>00207:         $this->includeUserBootstrap($config);
 00208:
 00209:         $testFrameworkKey = $input->getOption('test-framework') ?: $config->getTestFramework();
prompt> ev $config
Infection\Config\InfectionConfig Object
(
    [config:Infection\Config\InfectionConfig:private] => stdClass Object
        (
        )

    [filesystem:Infection\Config\InfectionConfig:private] => Symfony\Component\Filesystem\Filesystem Object
        (
        )

    [configLocation:Infection\Config\InfectionConfig:private] => /tmp/sandbox
)

You can see InfectionConfig is empty here, and after this the execution gets stuck.

Second run (infection.json.dist is already created)

$ phpdbg vendor/bin/infection
[Welcome to phpdbg, the interactive PHP debugger, v0.5.0]
To get help using phpdbg type "help" and press enter
[Please report bugs to <http://bugs.php.net/report.php>]
[Successful compilation of /tmp/sandbox/vendor/infection/infection/bin/infection]
prompt> break vendor/infection/infection/src/Command/InfectionCommand.php:207
[Breakpoint #0 added at /tmp/sandbox/vendor/infection/infection/src/Command/InfectionCommand.php:207]
prompt> run
You are running Infection with phpdbg enabled.
     ____      ____          __  _
    /  _/___  / __/__  _____/ /_(_)___  ____
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/

[Breakpoint #0 at /tmp/sandbox/vendor/infection/infection/src/Command/InfectionCommand.php:207, hits: 1]
>00207:         $this->includeUserBootstrap($config);
 00208:
 00209:         $testFrameworkKey = $input->getOption('test-framework') ?: $config->getTestFramework();
prompt> ev $config
Infection\Config\InfectionConfig Object
(
    [config:Infection\Config\InfectionConfig:private] => stdClass Object
        (
            [timeout] => 10
            [source] => stdClass Object
                (
                    [directories] => Array
                        (
                            [0] => src
                        )

                )

            [logs] => stdClass Object
                (
                    [text] => infection.log
                )

            [mutators] => stdClass Object
                (
                    [@default] => 1
                )

        )

    [filesystem:Infection\Config\InfectionConfig:private] => Symfony\Component\Filesystem\Filesystem Object
        (
        )

    [configLocation:Infection\Config\InfectionConfig:private] => /tmp/sandbox
)

In this time, configuration is loaded properly and the execution is successfully finished.

@sidz sidz added the Bug label Nov 20, 2018
@sidz
Copy link
Member

sidz commented Nov 20, 2018

Good catch 👍

@maks-rafalko
Copy link
Member

maks-rafalko commented Nov 20, 2018

I can reproduce it for infection itself. When I remove infection.json.dist, I get:

PHP Fatal error:  Uncaught Error: Call to a member function getMethod() on null in src/Visitor/CodeCoverageMethodIgnoreVisitor.php:58

Seems like it tries to travers files from the test folder while I choose src only during configuration process.

@sidz
Copy link
Member

sidz commented Nov 20, 2018

@borNfreee looks like you found a different issue :) but I can't confirm it.

Output
You are running Infection with Xdebug enabled.
     ____      ____          __  _
    /  _/___  / __/__  _____/ /_(_)___  ____
    / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
  _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
 /___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/


                                             
  Welcome to the Infection config generator  
                                             


We did not find a configuration file. The following questions will help us to generate it for you.


Which source directories do you want to include (comma separated)? [src]: 
  [0] .
  [1] bin
  [2] build
  [3] devTools
  [4] resources
  [5] src
  [6] tests
  [7] vendor
  5

There can be situations when you want to exclude some folders from generating mutants.
You can use glob pattern (*Bundle/**/*/Tests) for them or just regular dir path.
It should be relative to the source directory.
You should not mutate test suite files.
Press <return> to stop/skip adding dirs.

Any directories to exclude from within your source directories?: 

Single test suite timeout in seconds [10]: 25

Where do you want to store the text log file? [infection.log]: 

Configuration file "infection.json.dist" was created.

As you can see I selected fifth option in the first question and changed the default timeout to 25

But the $config object will have default values:

Proof

image

it happens due to this line

$config = $this->getContainer()->get('infection.config');

as it will initialize the config class with default values

and on

$config = $container->get('infection.config');
we will use existing object with default values as it won't reinitialize the object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants