ルーターでは、アプリケーションレベルにroutes.php
ファイルが存在する必要があります。そのため、このようなファイルを配置できるテストアプリケーション環境を構成する必要があります。
ファイルtests/bootstrap.php
ファイルで、テスト環境に必要な定数と構成を定義します。それだけでルータのためにどこ場合は、どこができた。これは、tests/TestApp/config/
に設定ディレクトリを設定します
define('CONFIG', dirname(__DIR__) . DS . 'tests' . DS . 'TestApp' . DS . 'config' . DS);
のように、\Cake\Routing\Router::_loadRoutes()
に使用されているか、それに応じてCONFIG
定数を定義したい場合、それはおそらく十分だろうroutes.php
ファイルを配置します。返事が遅れて申し訳ありません
use Cake\Core\Configure;
use Cake\Core\Plugin;
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
define('ROOT', dirname(__DIR__));
define('APP_DIR', 'src');
define('APP_ROOT', ROOT . DS . 'tests' . DS . 'TestApp' . DS);
define('APP', APP_ROOT . APP_DIR . DS);
define('CONFIG', APP_ROOT . DS . 'config' . DS);
define('WWW_ROOT', APP . DS . 'webroot' . DS);
define('TESTS', ROOT . DS . 'tests' . DS);
define('TMP', APP_ROOT . DS . 'tmp' . DS);
define('LOGS', APP_ROOT . DS . 'logs' . DS);
define('CACHE', TMP . 'cache' . DS);
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'vendor' . DS . 'cakephp' . DS . 'cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . 'src' . DS);
require_once ROOT . DS . 'vendor' . DS . 'autoload.php';
require_once CORE_PATH . 'config' . DS . 'bootstrap.php';
$config = [
'debug' => true,
'App' => [
'namespace' => 'App',
'encoding' => 'UTF-8',
'defaultLocale' => 'en_US',
'base' => false,
'baseUrl' => false,
'dir' => 'src',
'webroot' => 'webroot',
'wwwRoot' => WWW_ROOT,
'fullBaseUrl' => 'http://localhost',
'imageBaseUrl' => 'img/',
'cssBaseUrl' => 'css/',
'jsBaseUrl' => 'js/',
'paths' => [
'plugins' => [APP_ROOT . 'plugins' . DS],
'templates' => [APP . 'Template' . DS],
'locales' => [APP . 'Locale' . DS],
],
]
];
Configure::write($config);
date_default_timezone_set('UTC');
mb_internal_encoding(Configure::read('App.encoding'));
ini_set('intl.default_locale', Configure::read('App.defaultLocale'));
Plugin::load('MyPlugin', ['path' => ROOT]);
、そして詳細な回答をありがとうございました:
一般的に、私はセットアップにすべての定数をお勧めします、と、少なくとも基本的なアプリケーション構成、ここに私のプラグインの1から例です!私は 'CONFIG'定数を設定していましたが、' tests'ディレクトリの代わりにプロジェクトルートを使用していました。設定例は非常に便利です。 – Gus