phpunit没有将测试标记为已完成且成功

时间:2017-11-07 01:24:23

标签: zend-framework2 phpunit zend-framework3

我在让phpunit积极测试我创建的方法时遇到问题。即时通讯使用zend应用程序,ApplicationTest工作正常。这是我当前的命令行输出:

ApplicationTest\Controller\IndexController
 [x] Sample not active
 [x] Index action can be accessed
 [x] Index action view model template rendered within layout
 [x] Invalid route does not crash

PlutoTest\Stdlib\ArrayUtils
 [ ] Sample not active

如您所见,X测试中没有ArrayUtils。我甚至将方法放在ApplicationTest中,你可以看到它正确执行。

这是phpunit类:

namespace PlutoTest\Stdlib;

use Pluto\Stdlib\ArrayUtils;
use Pluto\pluto;
use PHPUnit\Framework\TestCase;

class ArrayUtilsTest extends TestCase
{
    public function setUp()
    {
        $configOverrides = [];
        $phpunitConfigFile=$this->getNormalizedPhpunitConfigFile();
        $this->setApplicationConfig(ArrayUtils::merge(
            include $phpunitConfigFile,
            $configOverrides
            ));
        parent::setUp();
    }

    private function getNormalizedPhpunitConfigFile()
    {
        $file = sprintf('%s/application.phpunit.php',pluto::path('zfconfig'));
        return $file;
    }    

    public function testSampleNotActive()
    {
        $stack = [];
        $this->assertEquals(0, count($stack));

        array_push($stack, 'foo');
        $this->assertEquals('foo', $stack[count($stack)-1]);
        $this->assertEquals(1, count($stack));

        $this->assertEquals('foo', array_pop($stack));
        $this->assertEquals(0, count($stack));
    }
}

这是我的phpunit.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <phpunit 
        colors="true"
        bootstrap="bootstrap.phpunit.php" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
        backupGlobals="true"
        backupStaticAttributes="false"
        cacheTokens="false"    
        convertErrorsToExceptions="true"
        convertNoticesToExceptions="true"
        convertWarningsToExceptions="true"
        forceCoversAnnotation="true"        
        processIsolation="false"
        stopOnError="false"
        stopOnFailure="false"
        stopOnIncomplete="false"
        stopOnSkipped="false"
        timeoutForSmallTests="1"
        timeoutForMediumTests="10"
        timeoutForLargeTests="60"
        beStrictAboutTestsThatDoNotTestAnything="true"
        beStrictAboutOutputDuringTests="true"
        beStrictAboutTestSize="true"
        verbose="true">
            <testsuites>
                <testsuite name="Application Module Test Suite">
                    <directory phpVersion="7.0.0" phpVersionOperator=">=">./module/Application/test</directory>
                    <directory phpVersion="7.0.0" phpVersionOperator=">=">./test/pluto/src</directory>
                </testsuite>
            </testsuites>
            <php>
              <env name="APPLICATION_ENV" value="development"/>
              <ini name="display_errors" value="1"/>
              <ini name="display_startup_errors" value="1"/>
              <ini name="error_reporting" value="32767"/>
              <ini name="report_memleaks" value="1"/>
           </php>
    </phpunit>

这是我的作曲家:

"autoload-dev" : {
    "psr-4" : {
        "ApplicationTest\\" : "module/Application/test/",
        "PlutoTest\\" : "test/pluto/src"
    }
},

1 个答案:

答案 0 :(得分:0)

尝试更改如下:

"autoload-dev": {
    "psr-4": {
        ...
        "YourModuleNameTest\\": "module/YourModuleName/test/"
    }
},

如果完成,请不要忘记在终端中通过作曲家运行dump-autoload

如果以这种方式修改phpunit.xml会怎样:

<testsuites>
    <testsuite name="Application Module Test Suite">
        <directory phpVersion="7.0.0" phpVersionOperator=">=">./module/Application/test</directory>
    </testsuite>
    <testsuite name="YourModuleName">
        <directory phpVersion="7.0.0" phpVersionOperator=">=">./module/YourModuleName/test</directory>
    </testsuite>        
</testsuites>

接下来,运行以下命令:

./vendor/bin/phpunit --testsuite YourModuleName

要列出所有可用套件,请运行以下命令:

./vendor/bin/phpunit --list-suites

要列出所有可用的测试,请运行以下命令:

./vendor/bin/phpunit --list-tests