Domanda

C'è qualcuno qui usa Zend Framework, ZFDoctrine e PHPUnit insieme?

Come ricostruire il database su ogni prova? Come separare locale / produzione / ambienti di test?

Vuoi che condividere la configurazione test di unità?

Ho cercato qualcosa di simile:

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

Ma questo finisce 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

I modelli non vengono generati.

ricevo errori simili in esecuzione:

$provider->createDatabase();

Ma in questo caso si crea database.
Gli altri comandi provider non funzionano.


La soluzione:

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

Se qualcuno conosce un approccio migliore, per favore correggetemi.

È stato utile?

Soluzione

Non ho usato ZFDoctrine, ma semplicemente Doctrine 1.2. Non so se la mia soluzione è meglio, ma ho pensato che se inserisco any1 è interessato, ecco la bootstrap.php nel mio test cartella:

<?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"));

La chiave qui è in realtà l'ultima riga che consente di ricostruire tutti i database creando un ambiente pulito per ogni test.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top