Phpunit 单元测试期间未构建Cake3固定装置
我有一个CakePHP3.7插件作为它自己的独立项目。但在运行单元测试时,我遇到了以下失败。似乎在将其移到父项目之外之后,不再构建固定装置。不知道如何指导蛋糕制作它们 Cake\Database\Exception:无法描述团队。它有0列 这是我的Phpunit 单元测试期间未构建Cake3固定装置,phpunit,cakephp-3.0,Phpunit,Cakephp 3.0,我有一个CakePHP3.7插件作为它自己的独立项目。但在运行单元测试时,我遇到了以下失败。似乎在将其移到父项目之外之后,不再构建固定装置。不知道如何指导蛋糕制作它们 Cake\Database\Exception:无法描述团队。它有0列 这是我的测试/引导文件。在我决定将这个插件从父项目中移出之前,这些测试一直在工作 <?php $findRoot = function ($root) { do { $lastRoot = $root; $root
测试/引导文件
。在我决定将这个插件从父项目中移出之前,这些测试一直在工作
<?php
$findRoot = function ($root) {
do {
$lastRoot = $root;
$root = dirname($root);
if (is_dir($root . '/vendor/cakephp/cakephp')) {
return $root;
}
} while ($root !== $lastRoot);
throw new Exception("Cannot find the root of the application, unable to run tests");
};
$root = $findRoot(__FILE__);
unset($findRoot);
chdir($root);
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
define('ROOT', $root);
define('APP_DIR', 'App');
define('WEBROOT_DIR', 'webroot');
define('APP', ROOT . '/tests/');
define('CONFIG', ROOT . '/tests/config/');
define('WWW_ROOT', ROOT . DS . WEBROOT_DIR . DS);
define('TESTS', ROOT . DS . 'tests' . DS);
define('TMP', ROOT . DS . 'tmp' . DS);
define('LOGS', TMP . 'logs' . DS);
define('CACHE', TMP . 'cache' . DS);
define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . 'src' . DS);
require_once ROOT . '/vendor/cakephp/cakephp/src/basics.php';
require ROOT . '/vendor/autoload.php';
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
try {
Configure::config('default', new PhpConfig());
Configure::load('app', 'default', false);
} catch (\Exception $e) {
exit($e->getMessage() . "\n");
}
$TMP = new \Cake\Filesystem\Folder(TMP);
$TMP->create(TMP . 'cache/models', 0777);
$TMP->create(TMP . 'cache/persistent', 0777);
$TMP->create(TMP . 'cache/views', 0777);
$cache = [
'default' => [
'engine' => 'File',
],
'_cake_core_' => [
'className' => 'File',
'prefix' => '_cake_core_',
'path' => CACHE . 'persistent/',
'serialize' => true,
'duration' => '+10 seconds',
],
'_cake_model_' => [
'className' => 'File',
'prefix' => '_cake_model_',
'path' => CACHE . 'models/',
'serialize' => 'File',
'duration' => '+10 seconds',
],
'_cake_method_' => [
'className' => 'File',
'prefix' => '_cake_method_',
'path' => CACHE . 'models/',
'serialize' => 'File',
'duration' => '+10 seconds',
],
];
Cake\Cache\Cache::setConfig($cache);
if (file_exists($root . '/config/bootstrap.php')) {
require $root . '/config/bootstrap.php';
}
if (!getenv('db_dsn')) {
putenv('db_dsn=sqlite:///:memory:');
}
Cake\Datasource\ConnectionManager::setConfig('test', [
'url' => getenv('db_dsn'),
'timezone' => 'UTC'
]);
/测试/测试用例
/src/
您的phpunit.xml
文件是什么样子的,您是如何调用phpunit的?@ndm将phpunit.xml添加到问题中,以及您是如何从何处调用phpunit的?呃。。。您的测试用例根本没有配置任何装置?如果没有,则在任何测试中都没有定义$fixtures
属性。
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
stopOnFailure="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="YummySearch Test Suite">
<directory>./tests/TestCase</directory>
</testsuite>
</testsuites>
<!-- configure code coverage -->
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>
</phpunit>