1

I'm having a problem while trying to perform a test in my ZF application:

My test case has the following set up function:

$this->bootstrap = new Zend_Application(
        'testing',
        APPLICATION_PATH . '/configs/application.ini'
    );

My testing environment would extend development, so my slite database file should be loaded the same way, am I right? But when I try to perform any db operation in the test I obtain the following error:

SQLSTATE[HY000]: General error: 11 malformed database schema - near "NO": syntax error

My database works just fine in development environment, so I guess it's not a database problem... thanks!

Here's the content of my application.ini:

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] = 

resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = ""
resources.db.params.charset = "utf8"

phpSettings.date.timezone = "America/Argentina/Cordoba"
phpSettings.upload_max_filesize = "10M"
phpSettings.post_max_size = "10M"

logger.path = "/logs"

[staging : production]

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

resources.db.adapter = "pdo_sqlite"
resources.db.params.dbname = APPLICATION_PATH "/../database/mydb.db"

[testing : development]

1 Answer 1

1

My configuration:

application/Bootstrap.php

protected function _initAutoload()
{
    $autoloader = new Zend_Application_Module_Autoloader(array('namespace' => '', 'basePath' => APPLICATION_PATH));
    return $autoloader;
}

/**
 * initialize doctrine library
 */
protected function _initDoctrine()
{
    // retrieve options
    $doctrine = $this->getOption('doctrine');
    // push doctrine model autoloader
    $this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine_Core', 'autoload'));
    // push doctrine model autoloader
    $this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine_Core', 'modelsAutoload'));
    // setup doctrine attributes
    $manager = Doctrine_Manager::getInstance();
    $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
    $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
    $manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
    $manager->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
    $manager->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
    // set default encoding
    $manager->setCharset('utf8');
    $manager->setCollate('utf8_unicode_ci');
    // autoloading models
    Doctrine_Core::loadModels(APPLICATION_PATH . '/models');
    // creating connection
    $conn = Doctrine_Manager::connection($doctrine['dsn'], 'doctrine');
    return $conn;
}

/tests/application/bootstrap.php

// Define path to application directory
if (!defined('APPLICATION_PATH')) {
    define('APPLICATION_PATH',
            realpath(dirname(__FILE__) . '/../../application'));
}

// Define application environment
define('APPLICATION_ENV', 'testing');

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV,
        APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap();

$cli = new Doctrine_Cli($application->getOption('doctrine'));

$cli->run(array("doctrine","create-db","force"));
$cli->run(array("doctrine","create-tables","force"));
$cli->run(array("doctrine","load-data","force"));

/application/configs/application.ini

[production]
; doctrine settings
doctrine.dsn                = "mysql://root:root@localhost/dbname"
doctrine.data_fixtures_path = APPLICATION_PATH "/../doctrine/data/fixtures/data.yml"
doctrine.sql_path           = APPLICATION_PATH "/../doctrine/data/sql"
doctrine.migrations_path    = APPLICATION_PATH "/../doctrine/migrations"
doctrine.yaml_schema_path   = APPLICATION_PATH "/../doctrine/schema"
doctrine.models_path        = APPLICATION_PATH "/models"
doctrine.generate_models_options.generateTableClasses = true
doctrine.generate_models_options.phpDocName = "Name Firstname"
doctrine.generate_models_options.phpDocEmail = "[email protected]"

[development : production]
; doctrine settings
doctrine.dsn                = "mysql://root:root@localhost/dbname"
doctrine.data_fixtures_path = APPLICATION_PATH "/../doctrine/data/fixtures/data.development.yml"

[testing : development]
; uses sqlite for testing
doctrine.dsn                = "sqlite::memory:"
doctrine.data_fixtures_path = APPLICATION_PATH "/../doctrine/data/fixtures/data.testing.yml"

tests/phpunit.xml

<phpunit bootstrap="./application/bootstrap.php" colors="true">
    <testsuites>
        <testsuite name="Forms">
            <directory>application/forms/</directory>
        </testsuite><testsuite name="Models">
            <directory>application/models/</directory>
        </testsuite>
        <testsuite name="Acls">
            <directory>application/acls/</directory>
        </testsuite>
        <testsuite name="Library">
            <directory>library/</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist>
            <directory suffix=".php">../application</directory>
            <directory suffix=".php">../library</directory>
            <exclude>
                <directory suffix=".php">../library</directory>
                <directory suffix=".phtml">../application</directory>
                <file>../application/Bootstrap.php</file>
                <file>../doctrine/doctrine.php</file>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

I hope to check out a help!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer @JellyBelly, using a bootstrap.php file as yours I would obtain "Fatal error: Class 'Zend_Application_Bootstrap_Bootstrap' not found" in my Bootstrap class file, why autoload isn't working here?
added other configurations inherent in doctrine! Try please!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.