added files

This commit is contained in:
Fabien Potencier 2010-10-28 14:41:03 +02:00
commit d2b2a18237
12 changed files with 936 additions and 0 deletions

70
Command/BuildCommand.php Normal file
View file

@ -0,0 +1,70 @@
<?php
namespace Symfony\Bundle\PropelBundle\Command;
use Symfony\Bundle\PropelBundle\Command\PhingCommand;
use Symfony\Bundle\PropelBundle\Command\BuildModelCommand;
use Symfony\Bundle\PropelBundle\Command\BuildSqlCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* BuildCommand.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class BuildCommand extends PhingCommand
{
protected $additionalPhingArgs = array();
/**
* @see Command
*/
protected function configure()
{
$this
->setDescription('Hub for Propel build commands (model, sql)')
->setDefinition(array(
new InputOption('--classes', '', InputOption::PARAMETER_NONE, 'Build only classes'),
new InputOption('--sql', '', InputOption::PARAMETER_NONE, 'Build only code'),
))
->setName('propel:build')
;
}
/**
* @see Command
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$input->getOption('sql')) {
$output->writeln('<info>Building model classes</info>');
$modelCommand = new BuildModelCommand();
$modelCommand->setApplication($this->application);
$modelCommand->execute($input, $output);
}
if (!$input->getOption('classes')) {
$output->writeln('<info>Building model sql</info>');
$sqlCommand = new BuildSQLCommand();
$sqlCommand->setApplication($this->application);
$sqlCommand->execute($input, $output);
}
}
}

View file

@ -0,0 +1,55 @@
<?php
namespace Symfony\Bundle\PropelBundle\Command;
use Symfony\Bundle\PropelBundle\Command\PhingCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* BuildCommand.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class BuildModelCommand extends PhingCommand
{
/**
* @see Command
*/
protected function configure()
{
$this
->setDescription('Build the Propel Object Model classes based on XML schemas')
->setHelp(<<<EOT
The <info>propel:build-model</info> command builds the Propel runtime model classes (ActiveRecord, Query, Peer, and TableMap classes) based on the XML schemas defined in all Bundles:
<info>./symfony propel:build-model</info>
EOT
)
->setName('propel:build-model')
;
}
/**
* @see Command
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->callPhing('om');
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Symfony\Bundle\PropelBundle\Command;
use Symfony\Bundle\PropelBundle\Command\PhingCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* BuildCommand.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class BuildSqlCommand extends PhingCommand
{
/**
* @see Command
*/
protected function configure()
{
$this
->setDescription('Build the SQL generation code for all tables based on Propel XML schemas')
->setHelp(<<<EOT
The <info>propel:build-sql</info> command builds the SQL table generation code based on the XML schemas defined in all Bundles:
<info>./symfony propel:build-sql</info>
EOT
)
->setName('propel:build-sql')
;
}
/**
* @see Command
*
* @throws \InvalidArgumentException When the target directory does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->callPhing('sql', array('propel.packageObjectModel' => false));
$filesystem = new Filesystem();
$basePath = $this->application->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql';
$sqlMap = file_get_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map');
foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
$sqlFile = str_replace('.xml', '.sql', $schemaFile);
$targetSqlFile = $schemaDetails['bundle'] . '-' . str_replace('.xml', '.sql', $schemaDetails['basename']);
$targetSqlFilePath = $basePath . DIRECTORY_SEPARATOR . $targetSqlFile;
$sqlMap = str_replace($sqlFile, $targetSqlFile, $sqlMap);
$filesystem->remove($targetSqlFilePath);
$filesystem->rename($basePath . DIRECTORY_SEPARATOR . $sqlFile, $targetSqlFilePath);
$output->writeln(sprintf('Wrote SQL file for bundle "<info>%s</info>" in "<info>%s</info>"', $schemaDetails['bundle'], $targetSqlFilePath));
}
file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap);
}
}

31
Command/Phing.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace Symfony\Bundle\PropelBundle\Command;
require_once 'phing/Phing.php';
/**
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class Phing extends \Phing
{
static public function getPhingVersion()
{
return 'Phing/Symfony';
}
/**
* @see Phing
*/
public function runBuild()
{
// workaround for included phing 2.3 which by default loads many tasks
// that are not needed and incompatible (eg phing.tasks.ext.FtpDeployTask)
// by placing current directory on the include path our defaults will be loaded
// see ticket #5054
$includePath = get_include_path();
set_include_path(dirname(__FILE__).PATH_SEPARATOR.$includePath);
parent::runBuild();
set_include_path($includePath);
}
}

209
Command/PhingCommand.php Normal file
View file

@ -0,0 +1,209 @@
<?php
namespace Symfony\Bundle\PropelBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
use Symfony\Component\Finder\Finder;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Wrapper command for Phing tasks
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
abstract class PhingCommand extends Command
{
protected $additionalPhingArgs = array();
protected $tempSchemas = array();
protected function callPhing($taskName, $properties = array())
{
$kernel = $this->application->getKernel();
$tmpDir = sys_get_temp_dir().'/propel-gen';
$filesystem = new Filesystem();
$filesystem->remove($tmpDir);
$filesystem->mkdirs($tmpDir);
foreach ($kernel->getBundles() as $bundle) {
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
$finder = new Finder();
$schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);
$parts = explode(DIRECTORY_SEPARATOR, realpath($bundle->getPath()));
$prefix = implode('.', array_slice($parts, 1, -2));
foreach ($schemas as $schema) {
$tempSchema = md5($schema).'_'.$schema->getBaseName();
$this->tempSchemas[$tempSchema] = array('bundle' => $bundle->getName(), 'basename' => $schema->getBaseName(), 'path' =>$schema->getPathname());
$file = $tmpDir.DIRECTORY_SEPARATOR.$tempSchema;
$filesystem->copy((string) $schema, $file);
// the package needs to be set absolute
// besides, the automated namespace to package conversion has not taken place yet
// so it needs to be done manually
$database = simplexml_load_file($file);
if (isset($database['package'])) {
$database['package'] = $prefix . '.' . $database['package'];
} elseif (isset($database['namespace'])) {
$database['package'] = $prefix . '.' . str_replace('\\', '.', $database['namespace']);
}
foreach ($database->table as $table)
{
if (isset($table['package'])) {
$table['package'] = $prefix . '.' . $table['package'];
} elseif (isset($table['namespace'])) {
$table['package'] = $prefix . '.' . str_replace('\\', '.', $table['namespace']);
}
}
file_put_contents($file, $database->asXML());
}
}
}
$filesystem->touch($tmpDir.'/build.properties');
$args = array();
// $bufferPhingOutput = !$this->commandApplication->withTrace();
$properties = array_merge(array(
'propel.database' => 'mysql',
'project.dir' => $tmpDir,
'propel.output.dir' => $kernel->getRootDir().'/propel',
'propel.php.dir' => '/',
'propel.packageObjectModel' => true,
), $properties);
foreach ($properties as $key => $value) {
$args[] = "-D$key=$value";
}
// Build file
$args[] = '-f';
$args[] = realpath($kernel->getContainer()->getParameter('propel.path').'/generator/build.xml');
/*
// Logger
if (DIRECTORY_SEPARATOR != '\\' && (function_exists('posix_isatty') && @posix_isatty(STDOUT))) {
$args[] = '-logger';
$args[] = 'phing.listener.AnsiColorLogger';
}
// Add our listener to detect errors
$args[] = '-listener';
$args[] = 'sfPhingListener';
*/
// Add any arbitrary arguments last
foreach ($this->additionalPhingArgs as $arg) {
if (in_array($arg, array('verbose', 'debug'))) {
$bufferPhingOutput = false;
}
$args[] = '-'.$arg;
}
$args[] = $taskName;
// enable output buffering
Phing::setOutputStream(new \OutputStream(fopen('php://output', 'w')));
Phing::startup();
Phing::setProperty('phing.home', getenv('PHING_HOME'));
// $this->logSection('propel', 'Running "'.$taskName.'" phing task');
$bufferPhingOutput = false;
if ($bufferPhingOutput) {
ob_start();
}
$m = new Phing();
$m->execute($args);
$m->runBuild();
if ($bufferPhingOutput) {
ob_end_clean();
}
print $bufferPhingOutput;
chdir($kernel->getRootDir());
/*
// any errors?
$ret = true;
if (sfPhingListener::hasErrors())
{
$messages = array('Some problems occurred when executing the task:');
foreach (sfPhingListener::getExceptions() as $exception)
{
$messages[] = '';
$messages[] = preg_replace('/^.*build\-propel\.xml/', 'build-propel.xml', $exception->getMessage());
$messages[] = '';
}
if (count(sfPhingListener::getErrors()))
{
$messages[] = 'If the exception message is not clear enough, read the output of the task for';
$messages[] = 'more information';
}
$this->logBlock($messages, 'ERROR_LARGE');
$ret = false;
}
*/
$ret = true;
return $ret;
}
protected function getPhingPropertiesForConnection($databaseManager, $connection)
{
$database = $databaseManager->getDatabase($connection);
return array(
'propel.database' => $database->getParameter('phptype'),
'propel.database.driver' => $database->getParameter('phptype'),
'propel.database.url' => $database->getParameter('dsn'),
'propel.database.user' => $database->getParameter('username'),
'propel.database.password' => $database->getParameter('password'),
'propel.database.encoding' => $database->getParameter('encoding'),
);
}
protected function getProperties($file)
{
$properties = array();
if (false === $lines = @file($file)) {
throw new sfCommandException('Unable to parse contents of the "sqldb.map" file.');
}
foreach ($lines as $line) {
$line = trim($line);
if ('' == $line) {
continue;
}
if (in_array($line[0], array('#', ';'))) {
continue;
}
$pos = strpos($line, '=');
$properties[trim(substr($line, 0, $pos))] = trim(substr($line, $pos + 1));
}
return $properties;
}
}

View file

@ -0,0 +1,146 @@
<?php
namespace Symfony\Bundle\PropelBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
class PropelExtension extends Extension
{
/**
* Loads the Propel configuration.
*
* @param array $config An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function configLoad($config, ContainerBuilder $container)
{
if (!$container->hasDefinition('propel')) {
$loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
$loader->load('propel.xml');
}
if (!$container->hasParameter('propel.path')) {
if (!isset($config['path'])) {
throw new \InvalidArgumentException('The "path" parameter is mandatory.');
}
$container->setParameter('propel.path', $config['path']);
}
if (isset($config['path'])) {
$container->setParameter('propel.path', $config['path']);
}
if (isset($config['phing_path'])) {
$container->setParameter('propel.phing_path', $config['phing_path']);
}
}
/**
* Loads the DBAL configuration.
*
* @param array $config An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function dbalLoad($config, ContainerBuilder $container)
{
if (!$container->hasDefinition('propel')) {
$loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
$loader->load('propel.xml');
}
$defaultConnection = array(
'driver' => 'mysql',
'user' => 'root',
'password' => null,
'dsn' => null,
// FIXME: should be automatically changed based on %kernel.debug%
'classname' => 'DebugPDO', //'PropelPDO',
'options' => array(),
'attributes' => array(),
// FIXME: Mysql wants UTF8, not UTF-8 (%kernel.charset%)
'settings' => array('charset' => array('value' => 'UTF8')),
);
$defaultConnectionName = isset($config['default_connection']) ? $config['default_connection'] : $container->getParameter('propel.dbal.default_connection');
$container->setParameter('propel.dbal.default_connection', $defaultConnectionName);
$connections = array();
if (isset($config['connections'])) {
foreach ($config['connections'] as $name => $connection) {
$connections[isset($connection['id']) ? $connection['id'] : $name] = $connection;
}
} else {
$connections = array($defaultConnectionName => $config);
}
$arguments = $container->getDefinition('propel.configuration')->getArguments();
if (count($arguments)) {
$c = $arguments[0];
} else {
$c = array(
// FIXME: should be the same value as %zend.logger.priority%
'log' => array('level' => 7),
'datasources' => array(),
);
}
foreach ($connections as $name => $connection) {
if (isset($c['datasources'][$name])) {
} else {
$connection = array_replace($defaultConnection, $connection);
$c['datasources'][$name] = array(
'connection' => array(),
);
}
if (isset($connection['driver'])) {
$c['datasources'][$name]['adapter'] = $connection['driver'];
}
foreach (array('dsn', 'user', 'password', 'classname', 'options', 'attributes', 'settings') as $att) {
if (isset($connection[$att])) {
$c['datasources'][$name]['connection'][$att] = $connection[$att];
}
}
}
$container->getDefinition('propel.configuration')->setArguments(array($c));
}
/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
*/
public function getXsdValidationBasePath()
{
return __DIR__.'/../Resources/config/schema';
}
/**
* Returns the namespace to be used for this extension (XML namespace).
*
* @return string The XML namespace
*/
public function getNamespace()
{
return 'http://www.symfony-project.org/schema/dic/propel';
}
/**
* Returns the recommended alias to use in XML.
*
* This alias is also the mandatory prefix to use when using YAML.
*
* @return string The alias
*/
public function getAlias()
{
return 'propel';
}
}

117
Logger/PropelLogger.php Normal file
View file

@ -0,0 +1,117 @@
<?php
namespace Symfony\Bundle\PropelBundle\Logger;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* PropelLogger.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class PropelLogger implements \BasicLogger
{
protected $logger;
/**
* Constructor.
*
* @param LoggerInterface $logger A LoggerInterface instance
*/
public function __construct(LoggerInterface $logger = null)
{
$this->logger = $logger;
}
/**
* Log message.
*
* @param string $message The message to log
* @param int $severity The numeric severity
*/
public function log($message, $severity = 6)
{
if (null !== $this->logger) {
$this->logger->log($message, $severity);
}
}
/**
* A convenience function for logging an alert event.
*
* @param mixed $message the message to log.
*/
public function alert($message)
{
$this->log($message, 1);
}
/**
* A convenience function for logging a critical event.
*
* @param mixed $message the message to log.
*/
public function crit($message)
{
$this->log($message, 2);
}
/**
* A convenience function for logging an error event.
*
* @param mixed $message the message to log.
*/
public function err($message)
{
$this->log($message, 3);
}
/**
* A convenience function for logging a warning event.
*
* @param mixed $message the message to log.
*/
public function warning($message)
{
$this->log($message, 4);
}
/**
* A convenience function for logging an critical event.
*
* @param mixed $message the message to log.
*/
public function notice($message)
{
$this->log($message, 5);
}
/**
* A convenience function for logging an critical event.
*
* @param mixed $message the message to log.
*/
public function info($message)
{
$this->log($message, 6);
}
/**
* A convenience function for logging a debug event.
*
* @param mixed $message the message to log.
*/
public function debug($message)
{
$this->log($message, 7);
}
}

19
PropelBundle.php Normal file
View file

@ -0,0 +1,19 @@
<?php
namespace Symfony\Bundle\PropelBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class PropelBundle extends Bundle
{
public function boot()
{
require_once $this->container->getParameter('propel.path').'/runtime/lib/Propel.php';
if (0 === strncasecmp(PHP_SAPI, 'cli', 3)) {
set_include_path($this->container->getParameter('propel.phing_path').'/classes'.PATH_SEPARATOR.get_include_path());
}
$this->container->getPropelService();
}
}

97
README Normal file
View file

@ -0,0 +1,97 @@
Propel Bundle
=============
This is a (work in progress) implementation of Propel in Symfony 2.
Currently supports:
* Generation of model classes based on an XML schema (not YAML) placed under `BundleName/Resources/*schema.xml`.
* Runtime autoloading of Propel and generated classes
* Propel runtime initialization through the XML configuration.
Installation
------------
* Checkout Propel and Phing in the src/vendor/ directory
> cd sandbox/src/vendor
> svn checkout http://svn.propelorm.org/branches/1.5 propel
> svn checkout http://phing.mirror.svn.symfony-project.com/tags/2.3.3/classes/phing phing
Sample Configuration
--------------------
### Project configuration
# in sandbox/hello/config/config.yml
propel.config:
path: %kernel.root_dir%/../src/vendor/propel
phing_path: %kernel.root_dir%/../src/vendor/phing
propel.dbal:
driver: mysql
user: root
password: null
dsn: mysql:host=localhost;dbname=test
options: {}
# default_connection: default
# connections:
# default:
# driver: mysql
# user: root
# password: null
# dsn: mysql:host=localhost;dbname=test
# options: {}
### Sample Schema
Place the following schema in src/Application/HelloBundle/Resources/config/schema.xml:
<?xml version="1.0" encoding="UTF-8"?>
<database name="default" namespace="Application\HelloBundle\Model" defaultIdMethod="native">
<table name="book">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="title" type="varchar" primaryString="1" size="100" />
<column name="ISBN" type="varchar" size="20" />
<column name="author_id" type="integer" />
<foreign-key foreignTable="author">
<reference local="author_id" foreign="id" />
</foreign-key>
</table>
<table name="author">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="first_name" type="varchar" size="100" />
<column name="last_name" type="varchar" size="100" />
</table>
</database>
### Build Process
Call the application console with the `propel:build` task:
> ./hello/console propel:build --classes
### Use The Model Classes
Use the Model classes as any other class in Symfony. Just use the correct namespace, and Symfony will autoload them:
class HelloController extends Controller
{
public function indexAction($name)
{
$author = new \Application\HelloBundle\Model\Author();
$author->setFirstName($name);
$author->save();
return $this->render('HelloBundle:Hello:index', array('name' => $name, 'author' => $author));
}
}
Known Problems
--------------
Your application must not be in a path including dots in directory names (i.e. '/Users/me/symfony/2.0/sandbox/' fails).

View file

@ -0,0 +1,32 @@
<?xml version="1.0" ?>
<container xmlns="http://www.symfony-project.org/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="propel.class">Propel</parameter>
<parameter key="propel.configuration.class">PropelConfiguration</parameter>
<parameter key="propel.logger.class">Symfony\Bundle\PropelBundle\Logger\PropelLogger</parameter>
<parameter key="propel.dbal.default_connection">default</parameter>
</parameters>
<services>
<service id="propel" class="%propel.class%">
<call method="setConfiguration">
<argument type="service" id="propel.configuration" />
</call>
<call method="setLogger">
<argument type="service" id="propel.logger" />
</call>
<call method="initialize" />
</service>
<service id="propel.configuration" class="%propel.configuration.class%" />
<service id="propel.logger" class="%propel.logger.class%">
<argument type="service" id="logger" on-invalid="null" />
</service>
</services>
</container>

View file

@ -0,0 +1,67 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\PropelBundle\Tests\DependencyInjection;
use Symfony\Bundle\PropelBundle\Tests\TestCase;
use Symfony\Bundle\PropelBundle\DependencyInjection\PropelExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class PropelExtensionTest extends TestCase
{
public function testConfigLoad()
{
$container = new ContainerBuilder();
$loader = new PropelExtension();
try {
$loader->configLoad(array(), $container);
$this->fail();
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '->configLoad() throws an \InvalidArgumentException if the Propel path is not set.');
}
$loader->configLoad(array('path' => '/propel'), $container);
$this->assertEquals('/propel', $container->getParameter('propel.path'), '->configLoad() sets the Propel path');
$loader->configLoad(array(), $container);
$this->assertEquals('/propel', $container->getParameter('propel.path'), '->configLoad() sets the Propel path');
}
public function testDbalLoad()
{
$container = new ContainerBuilder();
$loader = new PropelExtension();
$loader->dbalLoad(array(), $container);
$this->assertEquals('Propel', $container->getParameter('propel.class'), '->dbalLoad() loads the propel.xml file if not already loaded');
// propel.dbal.default_connection
$this->assertEquals('default', $container->getParameter('propel.dbal.default_connection'), '->dbalLoad() overrides existing configuration options');
$loader->dbalLoad(array('default_connection' => 'foo'), $container);
$this->assertEquals('foo', $container->getParameter('propel.dbal.default_connection'), '->dbalLoad() overrides existing configuration options');
$loader->dbalLoad(array(), $container);
$this->assertEquals('foo', $container->getParameter('propel.dbal.default_connection'), '->dbalLoad() overrides existing configuration options');
$container = new ContainerBuilder();
$loader = new PropelExtension();
$loader->dbalLoad(array('password' => 'foo'), $container);
$arguments = $container->getDefinition('propel.configuration')->getArguments();
$config = $arguments[0];
$this->assertEquals('foo', $config['datasources']['default']['connection']['password']);
$this->assertEquals('root', $config['datasources']['default']['connection']['user']);
$loader->dbalLoad(array('user' => 'foo'), $container);
$this->assertEquals('foo', $config['datasources']['default']['connection']['password']);
$this->assertEquals('root', $config['datasources']['default']['connection']['user']);
}
}

24
Tests/TestCase.php Normal file
View file

@ -0,0 +1,24 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\PropelBundle\Tests;
class TestCase extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!file_exists($file = __DIR__.'/../../../../../vendor/propel/runtime/lib/Propel.php')) {
$this->markTestSkipped('Propel is not available.');
}
require_once $file;
}
}