ZF、ZFDOCTRINEおよびPHPUNITセットアップ
-
29-09-2019 - |
質問
ここの誰かがZend Frameworkを使用していますか、 zfdoctrine そして一緒にphpunit?
各テスト実行でデータベースを再構築する方法は?ローカル/制作/テスト環境を分離する方法は?
ユニットテストのセットアップを共有しますか?
私はそのようなことをしています:
// /tests/bootstrap.php
// ... setup paths and constants here
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap('doctrine');
$provider = new ZFDoctrine_Tool_DoctrineProvider;
$provider->generateModelsFromYaml();
//$provider->buildProject(true);
しかし、これは次のとおりです。
Notice: Constant APPLICATION_PATH already defined in /home/user/www/library/ZendFramework/1.10.7/library/Zend/Tool/Project/Context/Zf/BootstrapFile.php on line 106
Fatal error: Call to a member function getResponse() on a non-object in /home/user/www/library/zf-doctrine/library/ZFDoctrine/Tool/DoctrineProvider.php on line 271
モデルは生成されません。
同様のエラーが実行されます:
$provider->createDatabase();
ただし、この場合、データベースが作成されます。
他のプロバイダーコマンドは機能しません。
ソリューション:
$provider = new ZFDoctrine_Tool_DoctrineProvider;
$registry = new Zend_Tool_Framework_Registry;
$provider->setRegistry($registry);
@$provider->buildProject(true);
誰かがより良いアプローチを知っているなら、私を修正してください。
解決
私はzfdoctrineを使用していませんが、単純な教義1.2を使用しました。私の解決策が良いかどうかはわかりませんが、any1が興味があるかどうかを投稿したと考えました。これは私のテストフォルダーのbootstrap.phpです:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
// Define application environment
/**
* In the application.ini:
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
doctrine.dsn = "mysql://my_user:passwd@localhost/my_phpunit_test_db"
*/
define('APPLICATION_ENV', 'testing');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path()
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/../configs/application.ini'
);
$application->getBootstrap()->bootstrap();
// Can run out if too small
ini_set('memory_limit', '512M');
// Get the doctrine settings
$config = $application->getOption('doctrine');
$cli = new Doctrine_Cli($config);
$cli->run(array("doctrine", "build-all-reload","force"));
ここで重要なのは、実際には、すべてのデータベースを再構築する最後の行です。各テストのクリーンな環境を作成します。
所属していません StackOverflow