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

Call to undefined method Composer\XdebugHandler\XdebugHandler::isXdebugActive #1677

Closed
alfredbez opened this issue Mar 23, 2022 · 6 comments · Fixed by #1708
Closed

Call to undefined method Composer\XdebugHandler\XdebugHandler::isXdebugActive #1677

alfredbez opened this issue Mar 23, 2022 · 6 comments · Fixed by #1708
Assignees

Comments

@alfredbez
Copy link

Question Answer
Infection version 0.25.4+ (infection.phar --version)
Test Framework version PHPUnit 9.5.18
PHP version 7.4.28
Platform Docker on Ubuntu
Github Repo -

I originally posted this already as a comment on this PR, but I think it's better to have that as a separate issue, so here we go:
I'm getting an error since #1518 was merged and released (in 0.25.4):

Fatal error: Uncaught Error: Call to undefined method Composer\XdebugHandler\XdebugHandler::isXdebugActive() in phar:///usr/local/bin/infection/src/TestFramework/Coverage/CoverageChecker.php:99

My Dockerfile looks like this:

FROM php:7.4-alpine

RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} \
  && pecl install xdebug \
  && docker-php-ext-enable xdebug \
  && apk del pcre-dev ${PHPIZE_DEPS}

RUN wget https://github.com/infection/infection/releases/download/0.25.4/infection.phar \
    && wget https://github.com/infection/infection/releases/download/0.25.4/infection.phar.asc \
    && chmod +x infection.phar \
    && mv infection.phar /usr/local/bin/infection

The same behavior occurs in all future releases after 0.25.4.


I've extracted the phar and checked how that looks inside:

/tmp/usr/local/bin/infection $ php -r '$v = require_once("vendor/composer/installed.php"); echo $v["versions"]["composer/xdebug-handler"]["version"] . PHP_EOL;'
2.0.0.0
/tmp/usr/local/bin/infection $ grep isXdebugActive vendor/composer/xdebug-handler/src/XdebugHandler.php
    public static function isXdebugActive()
/tmp/usr/local/bin/infection $

Am I doing something wrong?

phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   bootstrap="phpunit-bootstrap.php"
   executionOrder="depends,defects"
   forceCoversAnnotation="false"
   beStrictAboutCoversAnnotation="false"
   beStrictAboutOutputDuringTests="true"
   beStrictAboutTodoAnnotatedTests="true"
   colors="true"
   verbose="true">
 <coverage processUncoveredFiles="true">
   <include>
     <directory suffix=".php">src</directory>
   </include>
   <exclude>
     <directory suffix=".php">src/Orm</directory>
     <directory suffix=".php">src/Generated</directory>
   </exclude>
 </coverage>
 <testsuites>
   <testsuite name="default">
     <directory suffix="Test.php">tests/PyzUnitTest</directory>
   </testsuite>
 </testsuites>
</phpunit>
Output with issue
Infection - PHP Mutation Testing Framework version 0.25.4.0


Fatal error: Uncaught Error: Call to undefined method Composer\XdebugHandler\XdebugHandler::isXdebugActive() in phar:///usr/local/bin/infection/src/TestFramework/Coverage/CoverageChecker.php:99
Stack trace:
#0 phar:///usr/local/bin/infection/src/TestFramework/Coverage/CoverageChecker.php(47): _HumbugBox75a5b98e45f1\Infection\TestFramework\Coverage\CoverageChecker->hasCoverageGeneratorEnabled()
#1 phar:///usr/local/bin/infection/src/Command/RunCommand.php(140): _HumbugBox75a5b98e45f1\Infection\TestFramework\Coverage\CoverageChecker->checkCoverageRequirements()
#2 phar:///usr/local/bin/infection/src/Command/RunCommand.php(72): _HumbugBox75a5b98e45f1\Infection\Command\RunCommand->startUp(Object(_HumbugBox75a5b98e45f1\Infection\Container), Object(_HumbugBox75a5b98e45f1\Infection\Console\ConsoleOutput), Object(_HumbugBox75a5b98e45f1\Infection\Logger\ConsoleLogger), Object(_HumbugBox75a5b98e45f1\Infection\Console\IO))
#3 phar:///usr/local/bin/infection/src/Command/BaseCommand.php(28): _HumbugBox75a5b98e45f1\Infection\Command\Ru in phar:///usr/local/bin/infection/src/TestFramework/Coverage/CoverageChecker.php on line 99
How I execute infection

I build the docker image first in the directory where my Dockerfile is, like so:

docker build -t alfredbez/php-xdebug .

After that I run infection like this:

docker run --user 1000:1000 -it --rm -v $(pwd):$(pwd) -w $(pwd)/current alfredbez/php-xdebug sh -x -c 'infection'
@maks-rafalko
Copy link
Member

As I remember, we had different issues with generated PHAR and PHP 7.4, like this one #1573 (which hasn't been fixed and won't be).

  1. Is it possible for you to use PHP 8.0+ in your docker image?
  2. Is it possible for you to use infection/infection composer package instead of PHAR in your image?

@alfredbez
Copy link
Author

alfredbez commented Mar 23, 2022

Just tried to use that as a composer package, but that does not work, too:

Infection - PHP Mutation Testing Framework version 0.25.4.0


Fatal error: Uncaught Error: Call to undefined method Composer\XdebugHandler\XdebugHandler::isXdebugActive() in /root/.composer/vendor/infection/infection/src/TestFramework/Coverage/CoverageChecker.php:176
Stack trace:
#0 /root/.composer/vendor/infection/infection/src/TestFramework/Coverage/CoverageChecker.php(102): Infection\TestFramework\Coverage\CoverageChecker->hasCoverageGeneratorEnabled()
#1 /root/.composer/vendor/infection/infection/src/Command/RunCommand.php(520): Infection\TestFramework\Coverage\CoverageChecker->checkCoverageRequirements()
#2 /root/.composer/vendor/infection/infection/src/Command/RunCommand.php(334): Infection\Command\RunCommand->startUp(Object(Infection\Container), Object(Infection\Console\ConsoleOutput), Object(Infection\Logger\ConsoleLogger), Object(Infection\Console\IO))
#3 /root/.composer/vendor/infection/infection/src/Command/BaseCommand.php(75): Infection\Command\RunCommand->executeCommand(Object(Infection\Console\IO))
#4 /home/abez/projects/project/current/vendor/symfony/console/Comma in /root/.composer/vendor/infection/infection/src/TestFramework/Coverage/CoverageChecker.php on line 176

Using PHP 8.0 does also not work as expected:

PHP 8.0.15 (cli) (built: Jan 20 2022 21:14:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.15, Copyright (c) Zend Technologies
    with Xdebug v3.1.3, Copyright (c) 2002-2022, by Derick Rethans
Infection - PHP Mutation Testing Framework version 0.25.4.0


Fatal error: Uncaught Error: Call to undefined method Composer\XdebugHandler\XdebugHandler::isXdebugActive() in phar:///usr/local/bin/infection/src/TestFramework/Coverage/CoverageChecker.php:99
Stack trace:
#0 phar:///usr/local/bin/infection/src/TestFramework/Coverage/CoverageChecker.php(47): _HumbugBox75a5b98e45f1\Infection\TestFramework\Coverage\CoverageChecker->hasCoverageGeneratorEnabled()
#1 phar:///usr/local/bin/infection/src/Command/RunCommand.php(140): _HumbugBox75a5b98e45f1\Infection\TestFramework\Coverage\CoverageChecker->checkCoverageRequirements()
#2 phar:///usr/local/bin/infection/src/Command/RunCommand.php(72): _HumbugBox75a5b98e45f1\Infection\Command\RunCommand->startUp(Object(_HumbugBox75a5b98e45f1\Infection\Container), Object(_HumbugBox75a5b98e45f1\Infection\Console\ConsoleOutput), Object(_HumbugBox75a5b98e45f1\Infection\Logger\ConsoleLogger), Object(_HumbugBox75a5b98e45f1\Infection\Console\IO))
#3 phar:///usr/local/bin/infection/src/Command/BaseCommand.php(28): _HumbugBox75a5b98e45f1\Infection\Command\RunCommand->executeCommand(Object(_HumbugBox75a5b98e45f1\Infection\Console\IO))
#4 phar:///usr/local/bin/infection/vendor/symfony/console/Command/Command.php(153): _HumbugBox75a5b98e45f1\Infection\Command\BaseCommand->execute(Object(_HumbugBox75a5b98e45f1\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox75a5b98e45f1\Symfony\Component\Console\Output\ConsoleOutput))
#5 phar:///usr/local/bin/infection/vendor/symfony/console/Application.php(642): _HumbugBox75a5b98e45f1\Symfony\Component\Console\Command\Command->run(Object(_HumbugBox75a5b98e45f1\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox75a5b98e45f1\Symfony\Component\Console\Output\ConsoleOutput))
#6 phar:///usr/local/bin/infection/vendor/symfony/console/Application.php(212): _HumbugBox75a5b98e45f1\Symfony\Component\Console\Application->doRunCommand(Object(_HumbugBox75a5b98e45f1\Infection\Command\RunCommand), Object(_HumbugBox75a5b98e45f1\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox75a5b98e45f1\Symfony\Component\Console\Output\ConsoleOutput))
#7 phar:///usr/local/bin/infection/vendor/symfony/console/Application.php(120): _HumbugBox75a5b98e45f1\Symfony\Component\Console\Application->doRun(Object(_HumbugBox75a5b98e45f1\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox75a5b98e45f1\Symfony\Component\Console\Output\ConsoleOutput))
#8 phar:///usr/local/bin/infection/bin/infection(71): _HumbugBox75a5b98e45f1\Symfony\Component\Console\Application->run()
#9 /usr/local/bin/infection(14): require('phar:///usr/loc...')
#10 {main}
  thrown in phar:///usr/local/bin/infection/src/TestFramework/Coverage/CoverageChecker.php on line 99

I also tried to use a PHP 8.0 image and install infection as a composer package, but the result is very similar.

@deviantintegral
Copy link

I am seeing this on the latest release with PHP 8.1 as well:

wget https://github.com/infection/infection/releases/download/0.26.13/infection.phar
--2022-07-21 20:47:12--  https://github.com/infection/infection/releases/download/0.26.13/infection.phar
Resolving github.com (github.com)... 140.82.114.4
Connecting to github.com (github.com)|140.82.114.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/95741878/8b599230-1adb-4cea-a989-1d5aced71999?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220722%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220722T004712Z&X-Amz-Expires=300&X-Amz-Signature=ac007345016e9d602733335d7bcfb8aead50db6c71207c31c37c7dc5a6115a2b&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=95741878&response-content-disposition=attachment%3B%20filename%3Dinfection.phar&response-content-type=application%2Foctet-stream [following]
--2022-07-21 20:47:12--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/95741878/8b599230-1adb-4cea-a989-1d5aced71999?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220722%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220722T004712Z&X-Amz-Expires=300&X-Amz-Signature=ac007345016e9d602733335d7bcfb8aead50db6c71207c31c37c7dc5a6115a2b&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=95741878&response-content-disposition=attachment%3B%20filename%3Dinfection.phar&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.109.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1021389 (997K) [application/octet-stream]
Saving to: ‘infection.phar’

infection.phar                                                  100%[=====================================================================================================================================================>] 997.45K  4.96MB/s    in 0.2s

2022-07-21 20:47:13 (4.96 MB/s) - ‘infection.phar’ saved [1021389/1021389]

❯ chmod +x infection.phar
❯ ./infection.phar


  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] split
  [4] src
  [5] tests
  [6] vendor
 > 4

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? []:


Infection may save execution results in a text log for a future review.
This can be "infection.log" but we recommend leaving it out for performance reasons.
Press <return> to skip additional logging.

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

Configuration file "infection.json" was created.


    ____      ____          __  _
   /  _/___  / __/__  _____/ /_(_)___  ____
   / // __ \/ /_/ _ \/ ___/ __/ / __ \/ __ \
 _/ // / / / __/  __/ /__/ /_/ / /_/ / / / /
/___/_/ /_/_/  \___/\___/\__/_/\____/_/ /_/

#StandWithUkraine

Infection - PHP Mutation Testing Framework version 0.26.13

PHP Fatal error:  Uncaught Error: Call to undefined method Composer\XdebugHandler\XdebugHandler::isXdebugActive() in phar:///Users/andrew/workspace/php/har/infection.phar/src/TestFramework/Coverage/CoverageChecker.php:85
Stack trace:
#0 phar:///Users/andrew/workspace/php/har/infection.phar/src/TestFramework/Coverage/CoverageChecker.php(33): _HumbugBox861466a67237\Infection\TestFramework\Coverage\CoverageChecker->hasCoverageGeneratorEnabled()
#1 phar:///Users/andrew/workspace/php/har/infection.phar/src/Command/RunCommand.php(150): _HumbugBox861466a67237\Infection\TestFramework\Coverage\CoverageChecker->checkCoverageRequirements()
#2 phar:///Users/andrew/workspace/php/har/infection.phar/src/Command/RunCommand.php(77): _HumbugBox861466a67237\Infection\Command\RunCommand->startUp(Object(_HumbugBox861466a67237\Infection\Container), Object(_HumbugBox861466a67237\Infection\Console\ConsoleOutput), Object(_HumbugBox861466a67237\Infection\Logger\ConsoleLogger), Object(_HumbugBox861466a67237\Infection\Console\IO))
#3 phar:///Users/andrew/workspace/php/har/infection.phar/src/Command/BaseCommand.php(28): _HumbugBox861466a67237\Infection\Command\RunCommand->executeCommand(Object(_HumbugBox861466a67237\Infection\Console\IO))
#4 phar:///Users/andrew/workspace/php/har/infection.phar/vendor/symfony/console/Command/Command.php(155): _HumbugBox861466a67237\Infection\Command\BaseCommand->execute(Object(_HumbugBox861466a67237\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox861466a67237\Symfony\Component\Console\Output\ConsoleOutput))
#5 phar:///Users/andrew/workspace/php/har/infection.phar/vendor/symfony/console/Application.php(675): _HumbugBox861466a67237\Symfony\Component\Console\Command\Command->run(Object(_HumbugBox861466a67237\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox861466a67237\Symfony\Component\Console\Output\ConsoleOutput))
#6 phar:///Users/andrew/workspace/php/har/infection.phar/vendor/symfony/console/Application.php(216): _HumbugBox861466a67237\Symfony\Component\Console\Application->doRunCommand(Object(_HumbugBox861466a67237\Infection\Command\RunCommand), Object(_HumbugBox861466a67237\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox861466a67237\Symfony\Component\Console\Output\ConsoleOutput))
#7 phar:///Users/andrew/workspace/php/har/infection.phar/vendor/symfony/console/Application.php(124): _HumbugBox861466a67237\Symfony\Component\Console\Application->doRun(Object(_HumbugBox861466a67237\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox861466a67237\Symfony\Component\Console\Output\ConsoleOutput))
#8 phar:///Users/andrew/workspace/php/har/infection.phar/bin/infection(71): _HumbugBox861466a67237\Symfony\Component\Console\Application->run()
#9 /Users/andrew/workspace/php/har/infection.phar(14): require('phar:///Users/a...')
#10 {main}
  thrown in phar:///Users/andrew/workspace/php/har/infection.phar/src/TestFramework/Coverage/CoverageChecker.php on line 85

Fatal error: Uncaught Error: Call to undefined method Composer\XdebugHandler\XdebugHandler::isXdebugActive() in phar:///Users/andrew/workspace/php/har/infection.phar/src/TestFramework/Coverage/CoverageChecker.php:85
Stack trace:
#0 phar:///Users/andrew/workspace/php/har/infection.phar/src/TestFramework/Coverage/CoverageChecker.php(33): _HumbugBox861466a67237\Infection\TestFramework\Coverage\CoverageChecker->hasCoverageGeneratorEnabled()
#1 phar:///Users/andrew/workspace/php/har/infection.phar/src/Command/RunCommand.php(150): _HumbugBox861466a67237\Infection\TestFramework\Coverage\CoverageChecker->checkCoverageRequirements()
#2 phar:///Users/andrew/workspace/php/har/infection.phar/src/Command/RunCommand.php(77): _HumbugBox861466a67237\Infection\Command\RunCommand->startUp(Object(_HumbugBox861466a67237\Infection\Container), Object(_HumbugBox861466a67237\Infection\Console\ConsoleOutput), Object(_HumbugBox861466a67237\Infection\Logger\ConsoleLogger), Object(_HumbugBox861466a67237\Infection\Console\IO))
#3 phar:///Users/andrew/workspace/php/har/infection.phar/src/Command/BaseCommand.php(28): _HumbugBox861466a67237\Infection\Command\RunCommand->executeCommand(Object(_HumbugBox861466a67237\Infection\Console\IO))
#4 phar:///Users/andrew/workspace/php/har/infection.phar/vendor/symfony/console/Command/Command.php(155): _HumbugBox861466a67237\Infection\Command\BaseCommand->execute(Object(_HumbugBox861466a67237\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox861466a67237\Symfony\Component\Console\Output\ConsoleOutput))
#5 phar:///Users/andrew/workspace/php/har/infection.phar/vendor/symfony/console/Application.php(675): _HumbugBox861466a67237\Symfony\Component\Console\Command\Command->run(Object(_HumbugBox861466a67237\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox861466a67237\Symfony\Component\Console\Output\ConsoleOutput))
#6 phar:///Users/andrew/workspace/php/har/infection.phar/vendor/symfony/console/Application.php(216): _HumbugBox861466a67237\Symfony\Component\Console\Application->doRunCommand(Object(_HumbugBox861466a67237\Infection\Command\RunCommand), Object(_HumbugBox861466a67237\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox861466a67237\Symfony\Component\Console\Output\ConsoleOutput))
#7 phar:///Users/andrew/workspace/php/har/infection.phar/vendor/symfony/console/Application.php(124): _HumbugBox861466a67237\Symfony\Component\Console\Application->doRun(Object(_HumbugBox861466a67237\Symfony\Component\Console\Input\ArgvInput), Object(_HumbugBox861466a67237\Symfony\Component\Console\Output\ConsoleOutput))
#8 phar:///Users/andrew/workspace/php/har/infection.phar/bin/infection(71): _HumbugBox861466a67237\Symfony\Component\Console\Application->run()
#9 /Users/andrew/workspace/php/har/infection.phar(14): require('phar:///Users/a...')
#10 {main}
  thrown in phar:///Users/andrew/workspace/php/har/infection.phar/src/TestFramework/Coverage/CoverageChecker.php on line 85
❯ php -v
PHP 8.1.8 (cli) (built: Jul  8 2022 10:58:31) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.8, Copyright (c) Zend Technologies
    with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans
    with Zend OPcache v8.1.8, Copyright (c), by Zend Technologies

@maks-rafalko
Copy link
Member

@deviantintegral I've just created an empty repository with only phpunit/phpunit composer dependency and I can't reproduce this bug.

Could you please create a minimal reproducible repository? Thank you.

@deviantintegral
Copy link

deviantintegral commented Jul 27, 2022

It looks like this is caused by projects having composer/xdebug-handler already installed at an older version.

composer why composer/xdebug-handler
friendsofphp/php-cs-fixer  v2.18.2  requires  composer/xdebug-handler (^1.2)

I'm surprised by this, because I thought the point of the phar version was to avoid such dependency issues.

I figured this out because I've since upgraded friendsofphp/php-cs-fixer and infection started working again. Here's a script that shows the process, the error, and fixing it.

#!/bin/bash

git clone https://github.com/deviantintegral/har.git
cd har
git checkout c839755e # Last commit before php-cs-fixer was upgraded.
composer install
echo "================"
echo "Show that phpunit tests work with coverage..."
echo "================"
XDEBUG_MODE=coverage vendor/bin/phpunit

echo "================"
echo "Run with infection..."
echo "================"
wget https://github.com/infection/infection/releases/download/0.26.13/infection.phar
chmod +x infection.phar

cat >infection.json <<EOD
{
    "\$schema": "https://raw.githubusercontent.com/infection/infection/0.26.13/resources/schema.json",
    "source": {
        "directories": [
            "src"
        ]
    },
    "mutators": {
        "@default": true
    }
}
EOD

./infection.phar

echo "================"
echo "Show current xdebug-handler dependency..."
echo "================"
composer why composer/xdebug-handler

echo "================"
echo "Upgrade php-cs-fixer..."
echo "================"
composer require -W --dev friendsofphp/php-cs-fixer:^3

echo "================"
echo "Rerun infection..."
echo "================"
./infection.phar -j8

@maks-rafalko
Copy link
Member

Thank you for all the details @deviantintegral, fixed in master

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