2017-11-07 3 views
0

私が作成した方法を積極的にテストするには、phpunitという問題が発生しています。私はzendアプリケーションとApplicationTestを使用してうまく動作します。ここに私の現在のコマンドライン出力だ:phpunitが完了して正常に終了していることを示すテスト

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 

あなたが見ることができるように、私のArrayUtilsテスト内部にはXはありません。私は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" 
    } 
}, 
+0

'$ this-> setApplicationConfig()'を呼び出すには、 'PHPUnit \ Framework \ TestCase'の代わりに' Zend \ Test \ PHPUnit \ Controller \ AbstractControllerTestCase'を拡張する必要があります。 – gsc

答えて

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 
+0

ありがとう!今素晴らしいです – jkushner

+0

あなたはいつも歓迎です! – unclexo

関連する問題