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

expects parameter 1 to be string, integer given #671

Closed
ThHareau opened this issue Feb 25, 2019 · 2 comments
Closed

expects parameter 1 to be string, integer given #671

ThHareau opened this issue Feb 25, 2019 · 2 comments

Comments

@ThHareau
Copy link

Q A
php-code-coverage version 7.0.2
PHP version 7.2.14
Driver Xdebug
Xdebug version (if used) 2.6.1
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 8.0.4

Hello,
Running the code coverage with phpunit , the coverage generation failed with this error:

Fatal error: Uncaught TypeError: substr() expects parameter 1 to be string, integer given in /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php on line 38

Using a debugger, I could see that $key was 1149 and value was referring the file Issue1149.php.

I added a cast ($key = (string) $key; before the line 38, it fixed the issue.

Here is the full logs.

PHPUnit 8.0.4 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.14 with Xdebug 2.6.1
Configuration: /var/www/api/phpunit.xml

..                                                                  2 / 2 (100%)

Time: 27.26 seconds, Memory: 84.25MB

OK (2 tests, 17 assertions)

Generating code coverage report in HTML format ...
Fatal error: Uncaught TypeError: substr() expects parameter 1 to be string, integer given in /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php on line 38

TypeError: substr() expects parameter 1 to be string, integer given in /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php on line 38

Call Stack:
    0.0006     465072   1. {main}() /var/www/api/quark:0
    0.0417    8476616   2. {closure:/var/www/api/app/Commands/Core/wrappers.php:14-16}() /var/www/api/quark:25
    0.0425    8632728   3. PHPUnit\TextUI\Command::main() /var/www/api/app/Commands/Core/wrappers.php:15
    0.0425    8632840   4. PHPUnit\TextUI\Command->run() /var/www/api/vendor/phpunit/phpunit/src/TextUI/Command.php:164
    1.0684   47834032   5. PHPUnit\TextUI\TestRunner->doRun() /var/www/api/vendor/phpunit/phpunit/src/TextUI/Command.php:208
   27.2655   70238968   6. SebastianBergmann\CodeCoverage\Report\Html\Facade->process() /var/www/api/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:698
   27.2655   70239048   7. SebastianBergmann\CodeCoverage\CodeCoverage->getReport() /var/www/api/vendor/phpunit/php-code-coverage/src/Report/Html/Facade.php:57
   27.2657   70258960   8. SebastianBergmann\CodeCoverage\Node\Builder->build() /var/www/api/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:164
   63.8582  107077616   9. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:29
   75.1928  156252664  10. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   75.5525  157347688  11. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   75.5525  157348912  12. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   84.7075  205719456  13. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   87.1402  211368904  14. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   90.6801  222331848  15. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   90.9827  225331336  16. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   91.0042  225959064  17. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   91.0043  225960288  18. SebastianBergmann\CodeCoverage\Node\Builder->addItems() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:46
   91.0043  225960288  19. substr() /var/www/api/vendor/phpunit/php-code-coverage/src/Node/Builder.php:38

@sebastianbergmann
Copy link
Owner

I do not understand why Issue1149.php from this component's test suite's fixture would interfere with the execution of your test suite.

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue and find the root cause for this. I am afraid that that justing adding the cast you mentioned will hide the real problem.

@ThHareau
Copy link
Author

It's apparently a repository issue. If the name of a repository is a number, it fails.

I created a project with this structure:

.
├── composer.json
├── phpunit.xml
└── src
    ├── 1234
    │   └── File.php
    └── File.php

Both File.php and 1234/File.php are empty.

composer.json

{
    "name": "thareau/testcoverage",
    "require": {
        "phpunit/phpunit": "^8.0",
        "phpunit/php-code-coverage": "^7.0"
    }
}

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>

<phpunit>
    <filter>
        <whitelist>
            <directory suffix=".php">./src</directory>
        </whitelist>
    </filter>

    <logging>
          <log type="coverage-html" target="./reports/html" lowUpperBound="50" highLowerBound="80"/>
    </logging>
</phpunit>

Then run ./vendor/bin/phpunit

Issue1149.php is not related to this issue (I had a subproject inside the whitelist scope, with a vendor repository and where phpunit was also installed).

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

No branches or pull requests

2 participants