Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

php - PHPUnit code coverage breaks when defining variables for the same class ($this->example)

As soon as I try to define a variable which will be accessible in the entire class ($this->variable, for example), this breaks PHPunit code coverage.

From that point on, PHPUnit claims the code isn't being executed (while it is in fact being executed, the test even passes).

Screenshot of Code Coverage suddenly stopping

........................                                          24 / 24 (100%)

Time: 01:07.127, Memory: 56.00 MB

OK (24 tests, 29 assertions)

Generating code coverage report in HTML format ... done [00:11.315]

Here's my phpunit config:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         beStrictAboutCoversAnnotation="false"
         colors="true"
>

    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>

    <coverage cacheDirectory=".phpunit.cache/code-coverage"
              processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./app</directory>
        </include>
        <exclude>
            <directory suffix=".php">./app/Classes/Theme</directory>
            <file>./app/Http/Controllers/Controller.php</file>
            <file>./app/Http/Middleware/VerifyCsrfToken.php</file>
            <file>./app/Providers/AppServiceProvider.php</file>
            <file>./app/Providers/BroadcastServiceProvider.php</file>
            <file>./app/Providers/MetronicServiceProvider.php</file>
        </exclude>
    </coverage>

    <php>
        <server name="APP_ENV" value=""/>
        <server name="TELESCOPE_ENABLED" value="false"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="DB_CONNECTION" value="mysql"/>
        <server name="MAIL_MAILER" value="array"/>
        <server name="QUEUE_CONNECTION" value="sync"/>
        <server name="SESSION_DRIVER" value="array"/>
    </php>
</phpunit>

question from:https://stackoverflow.com/questions/65845293/phpunit-code-coverage-breaks-when-defining-variables-for-the-same-class-this

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...