2015-06-05 22 views
2

我是使用這個框架的新手,並且在測試插件時發現了一個問題。CakePHP3插件測試類'Cake TestSuite IntegrationTestCase'找不到

PHP Fatal error: Class 'Cake\TestSuite\IntegrationTestCase' not found in /var/www/MyApp/plugins/MyPlugin/tests/TestCase/Controller/UsersControllerTest.php on line 11 

運行主應用程序工作正常,但我對插件的所有測試類都有同樣的問題。

測試的類的頭是類似於:

<?php 
namespace MyPlugin\Test\TestCase\Controller; 

use Cake\TestSuite\IntegrationTestCase; 
use MyPlugin\Controller\UsersController; 

class UsersControllerTest extends IntegrationTestCase 
{ 

插件的phpunit.xml.dist:

<?xml version="1.0" encoding="UTF-8"?><phpunit 
colors="true" 
processIsolation="false" 
stopOnFailure="false" 
syntaxCheck="false" 
bootstrap="./tests/bootstrap.php" 
> 
<php> 
    <ini name="memory_limit" value="-1"/> 
    <ini name="apc.enable_cli" value="1"/> 
</php> 

<!-- Add any additional test suites you want to run here --> 
<testsuites> 
    <testsuite name="MyPlugin Test Suite"> 
     <directory>./tests/TestCase</directory> 
    </testsuite> 
</testsuites> 

<!-- Setup a listener for fixtures --> 
<listeners> 
    <listener 
    class="\Cake\TestSuite\Fixture\FixtureInjector" 
    file="../../vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php"> 
     <arguments> 
      <object class="\Cake\TestSuite\Fixture\FixtureManager" /> 
     </arguments> 
    </listener> 
</listeners> 

<!-- Prevent coverage reports from looking in tests and vendors --> 
<filter> 
    <blacklist> 
     <directory suffix=".php">./vendor/</directory> 
     <directory suffix=".ctp">./vendor/</directory> 

     <directory suffix=".php">./tests/</directory> 
     <directory suffix=".ctp">./tests/</directory> 
    </blacklist> 
</filter></phpunit> 

而且composer.json:

{ 
"name": "your-name-here/MyPlugin", 
"description": "MyPlugin plugin for CakePHP", 
"type": "cakephp-plugin", 
"require": { 
    "php": ">=5.4.16", 
    "cakephp/cakephp": "~3.0" 
}, 
"require-dev": { 
    "phpunit/phpunit": "*" 
}, 
"autoload": { 
    "psr-4": { 
     "MyPlugin\\": "src" 
    } 
}, 
"autoload-dev": { 
    "psr-4": { 
     "MyPlugin\\Test\\": "tests", 
     "Cake\\Test\\": "/var/www/MyApp/vendor/cakephp/cakephp/tests", 
    } 
} 
} 

在此先感謝! ;)

回答

0

你需要在你的插件文件夾中運行composer install使CakePHP的LIB下<your-plugin>/vendor/cakephp/cakephp

+0

謝謝,但我試過了,它似乎沒有工作。另外,我想在每個想要測試的插件中獲取所有cakephp核心庫是相當多餘的,我無法弄清楚解決方案。 –

1

安裝最後我得到它固定。在插件的phpunit.xml.dist文件,我做了自舉點到主應用程序的一個:

<?xml version="1.0" encoding="UTF-8"?><phpunit 
colors="true" 
processIsolation="false" 
stopOnFailure="false" 
syntaxCheck="false" 
bootstrap="../../config/bootstrap.php" 
> 

此外,在同一文件中,不要忘了讓聽者在同一個文件指向主應用程序的供應商,這樣你就不會在你的插件重新安裝整個CakePHP的套件:

<!-- Setup a listener for fixtures --> 
<listeners> 
    <listener 
    class="\Cake\TestSuite\Fixture\FixtureInjector" 
    file="../../vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php"> 
     <arguments> 
      <object class="\Cake\TestSuite\Fixture\FixtureManager" /> 
     </arguments> 
    </listener> 
</listeners> 

看來,在默認情況下,烘烤插件時,這兩個要素是沒有設置正確的方式。