Frage

Hat jemand hier verwenden Zend Framework, ZFDoctrine und PHPUnit zusammen?

Wie die Datenbank auf jedem Testlauf wieder aufzubauen? Wie lokale / Produktion / Testumgebungen trennen?

Würden Sie teilen Sie Ihre Unit-Tests Setup?

Ich habe so etwas versuchen:

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

Aber diese Enden 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

Die Modelle werden nicht erzeugt.

Ich bekomme ähnliche Fehler ausgeführt wird:

$provider->createDatabase();

Aber in diesem Fall Datenbank wird erstellt.
Die anderen Anbieter Befehle nicht funktionieren.


Die Lösung:

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

Wenn jemand einen besseren Ansatz kennt, kann man mich korrigieren.

War es hilfreich?

Lösung

Ich habe nicht 1,2 ZFDoctrine, sondern einfach nur Lehre verwendet. Ich weiß nicht, ob meine Lösung besser ist, aber ich dachte, ich poste, wenn any1 interessiert ist, hier ist die bootstrap.php in meinen Tests Ordner:

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

Der Schlüssel hier ist eigentlich die letzte Zeile, die alle Datenbanken für jede Prüfung der Schaffung eine saubere Umgebung neu erstellt.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top