views:

54

answers:

0

Hi,

Does anyone here use Zend Framework, ZFDoctrine and PHPUnit together?

How to rebuild the database on each test run? How to separate local/production/testing environments?

Would you share your unit testing setup?

I have been trying something like that:

// /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);

Bug this ends in:

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

Models are not generated.

I get similar errors running:

$provider->createDatabase();

But in this case database is created.
The other provider commands do not work.


The solution:

$provider = new ZFDoctrine_Tool_DoctrineProvider;
$registry = new Zend_Tool_Framework_Registry;
$provider->setRegistry($registry);
@$provider->buildProject(true);

If anybody knows a better approach, please correct me.