避免执行外部插件的测试用例

Avoid executing external plugins' test cases

composer.json

    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/socialite": "^3.0",
        ...
        "chencha/share": "^5.2"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    ...
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },

phpunit.xml

<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="bootstrap/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>

当我 运行 phpunit 它给了我以下错误

PHP Fatal error: Class 'Orchestra\Testbench\TestCase' not found in /usr/lib/php5/voice/v1.5/vendor/chencha/share/tests/TestCase.php on line 3

我可以在我的 require-dev 下添加 "orchestra/testbench": "~3.0" 这将解决问题,但是有什么办法可以 运行 只有我的测试用例而没有插件的测试用例?

在标准配置中,供应商目录中没有测试 运行。您显示的 phpunit.xml 看起来很正常,因此您应该确保 运行 在有效目录中进行测试。当您进行 运行 测试时,您应该在主应用程序目录中(查看您的错误应该是 /usr/lib/php5/voice/v1.5/)。

发现问题。我没有添加命名空间 use Tests\TestCase; 因为它扩展了外部插件的 TestCase class。我的错,浪费了很多时间。