Author: sergiovier
Date: 2010-04-07 00:09:14 +0200 (Wed, 07 Apr 2010)
New Revision: 29024
Added:
plugins/sfAlyssaDoctrineObjectPathPlugin/tags/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/LICENSE
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/sfAlyssaDoctrineObjectPathPluginConfiguration.class.php
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/sfAlyssaDoctrineQuery.class.php
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bin/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bin/prove.php
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bootstrap/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bootstrap/unit.php
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Author.class.php
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Book.class.php
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Review.class.php
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/data.yml
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/sfAlyssaDoctrineQueryTest.class.php
Log:
initial import
Added: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/LICENSE
===================================================================
--- plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/LICENSE
(rev 0)
+++ plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/LICENSE 2010-04-06
22:09:14 UTC (rev 29024)
@@ -0,0 +1,19 @@
+Copyright (c) 2010 - Cooperativa de Trabajo Alyssa Limitada
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
Property changes on: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/LICENSE
___________________________________________________________________
Added: svn:executable
+ *
Added: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README
===================================================================
--- plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README
(rev 0)
+++ plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README 2010-04-06
22:09:14 UTC (rev 29024)
@@ -0,0 +1,57 @@
+# sfAlyssaDoctrineObjectPathPlugin plugin #
+
+## Introduction ##
+
+This plugin adds ObjectPath support to Doctrine.
+
+This syntax makes it very easy to do sorting and filtering on foreign fields.
ObjectPaths are dot-seperated relation-names that relate from one object to
another and this behavior translates the objectPaths to table-aliasses.
+
+This plugin is based on the work of Leon van der Ree and your plugin
+
[sfPropelObjectPathBehaviorPlugin](http://www.symfony-project.org/plugins/sfPropelObjectPathBehaviorPlugin).
+
+
+## Installation
+
+1.Download and install the plugin
+
+ ./symfony plugin:install sfAlyssaSmsPlugin
+
+2.Clear the cache
+
+ ./symfony cc
+
+
+## Example ##
+
+
+So a very simple ObjectPath from City to Country is simply "Country" and from
Country to City it would be "City":
+In other words the relation-name.
+
+However ObjectPaths support dots to 'jump' from object to object. So for
example from Review to Book to Author would be "Book.Author".
+
+In Php-code this shows up as:
+
+ [php]
+ $query = Doctrine_Query::create();
+ $reviews = $query->
+ joinByObjectPath('Book.Author')->
+ orderByObjectPath('Book.Author.FirstName asc')->
+ excecute();
+
+to find all reviews, joined with their Books, joined with their Authors.
+
+## Note ##
+
+The sfAlyssaDoctrineObjectPathPlugin is used in the sfDataSourcePlugin, but
not required.
+
+
+
+## Todo ##
+
+* Improve the documentation with more examples
+
+
+## Changelog ##
+
+### 2010-04-06 | 1.0.0 ###
+* Initial import
Property changes on: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/README
___________________________________________________________________
Added: svn:executable
+ *
Added:
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/sfAlyssaDoctrineObjectPathPluginConfiguration.class.php
===================================================================
---
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/sfAlyssaDoctrineObjectPathPluginConfiguration.class.php
(rev 0)
+++
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/config/sfAlyssaDoctrineObjectPathPluginConfiguration.class.php
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,64 @@
+<?php
+/*
+ * (c) 2010 - Cooperativa de Trabajo Alyssa Limitada
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Plugin configuration.
+ *
+ * Adds the custom Doctrine_Query class for Doctrine
+ *
+ * @package sfAlyssaDoctrineObjectPathBehaviorPlugin
+ * @subpackage config
+ * @author Sergio Fabian Vier <[email protected]>
+ * @version SVN: $Id$
+ */
+class sfAlyssaDoctrineObjectPathPluginConfiguration extends
sfPluginConfiguration
+{
+
+ /**
+ * @see sfPluginConfiguration
+ */
+ public function configure()
+ {
+ $a = array_search('sfAlyssaDoctrineObjectPathPluginConfiguration',
$this->configuration->getPlugins());
+ $b = array_search('sfDoctrinePlugin', $this->configuration->getPlugins());
+
+ if ($a > $b)
+ {
+ throw new LogicException('The
sfAlyssaDoctrineObjectPathPluginConfiguration plugin must be enabled before
sfDoctrinePlugin');
+ }
+ }
+
+ /**
+ * @see sfPluginConfiguration
+ */
+ public function initialize()
+ {
+
+ $this->dispatcher->connect('doctrine.configure', array($this,
'configureDoctrine'));
+
+ }
+
+ /**
+ * Configures Doctrine.
+ *
+ * Adds custom query and collection classes if none are setup already.
+ *
+ * @param sfEvent $event A symfony event
+ */
+ public function configureDoctrine(sfEvent $event)
+ {
+ $manager = $event->getSubject();
+
+ if ('Doctrine_Query' ==
$manager->getAttribute(Doctrine_Core::ATTR_QUERY_CLASS))
+ {
+ $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CLASS,
'sfAlyssaDoctrineQuery');
+ }
+
+ }
+
+}
Added:
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/sfAlyssaDoctrineQuery.class.php
===================================================================
---
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/sfAlyssaDoctrineQuery.class.php
(rev 0)
+++
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/lib/query/sfAlyssaDoctrineQuery.class.php
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,241 @@
+<?php
+/*
+ * (c) 2010 - Cooperativa de Trabajo Alyssa Limitada
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * sfAlyssaDoctrineQuery
+ *
+ * Adds to the custom Doctrine_Query class support for ObjectPath.
+ * An ObjectPath is a chain of relationNames, seperated by a dot, resulting in
+ * a joined object
+ *
+ * @package lib
+ * @subpackage query
+ * @author Sergio Fabian Vier <[email protected]>
+ * @version SVN: $Id$
+ */
+class sfAlyssaDoctrineQuery extends Doctrine_Query{
+ const ALIAS_DELIMITER = '___';
+
+ /**
+ * Recursively performs join on the provided ObjectPaths
+ *
+ * @param mixed $objectPath one or more strings with objectPaths
+ * @param string $rootAlias optional, base alias for recursive generation
+ * @return sfAlyssaDoctrineQuery
+ */
+ public function joinByObjectPath($objectPath, $rootAlias = null)
+ {
+ $objectPaths = is_array($objectPath) ? $objectPath : array($objectPath);
+
+ // process all objectPaths
+ foreach ($objectPaths as $objectPath)
+ {
+ // brake up the objectPath into an array of relationsNames
+ $relationsNames = explode('.', $objectPath, 2);
+
+ // resolve current object and the (first) relationName
+ if (count($relationsNames)<1)
+ {
+ throw new Doctrine_Query_Exception('no relation provided');
+ }
+
+ // take an root alias if not defined
+ if ($rootAlias === null){
+ $rootAlias = $this->getRootAlias();
+ }
+
+ $relationName = $relationsNames[0];
+ $alias = $this->translateObjectPathToAlias($relationName, $rootAlias);
+
+ //$newJoin = !$this->hasAliasDeclaration($alias);
+ $newJoin = !isset($this->join[$alias]);
+ if ($newJoin)
+ {
+ $this->join[$alias] = true;
+ //TODO: only leftjoin is supported
+ $this->leftJoin($rootAlias.'.'.$relationName.' '.$alias);
+ }
+
+ // if more relations are provided, continue (recursively) parsing the
objectPath
+ if (isset($relationsNames[1]))
+ {
+ $this->joinByObjectPath($relationsNames[1], $alias);
+ }
+ }
+
+ //fluid interface
+ return $this;
+ }
+
+ /**
+ * Resolves the database alias for an objectPath
+ *
+ * Basically this comes down to replacing all dots with an underscore
+ * and preceeding it with the queryModel-alias
+ *
+ * so $reviewQuery->translateObjectPathToAlias('Book.Author')
+ * becomes Review_Book_Author as the table-alias for Book-Author
+ *
+ * @param string $objectPath
+ * @param string $rootAlias optional, base alias for recursive generation
+ * @return string the constructed alias
+ */
+ public function translateObjectPathToAlias($objectPath, $rootAlias = null)
+ {
+ // brake up the objectPath into an array of relationsNames
+ $relationsNames = explode('.', $objectPath, 2);
+
+ // resolve current object and the (first) relationName
+ if (count($relationsNames)<1)
+ {
+ throw new Doctrine_Query_Exception('no relation provided');
+ }
+
+ // take an root alias if not defined
+ if ($rootAlias === null)
+ {
+ $rootAlias = $this->getRootAlias();
+ }
+ $relationName = $relationsNames[0];
+ $alias = $rootAlias.self::ALIAS_DELIMITER.$relationName;
+
+ // if more relations are provided, continue (recursively) parsing the
objectPath
+ if (isset($relationsNames[1]))
+ {
+ $alias = $this->translateObjectPathToAlias($relationsNames[1], $alias);
+ }
+
+ return $alias;
+ }
+
+ /**
+ * Resolves the column name alias for an PropertyPath
+ *
+ * PropertyPaths are an optional ObjectPaths plus a PhpColumnName. So
[Relation.]*PhpColumnName
+ * @see translateObjectPathToAlias()
+ *
+ * @param string $columnName
+ * @return string the constructed alias
+ */
+ protected function propertyPathToColumn($columnName){
+
+ // check if an objectPath has been given
+ $lastDot = strrpos($columnName, '.');
+ if ($lastDot !== false)
+ {
+ // get the objectPath
+ $objectPath = substr($columnName, 0, $lastDot);
+
+ // and get Related Query Class
+ $strRelated = $this->translateObjectPathToAlias($objectPath);
+ $columnName = $strRelated.'.'.substr($columnName, $lastDot + 1);
+
+ }
+
+ return $columnName;
+
+ }
+
+ /**
+ * Adds ProperyPaths to the WHERE part of the query.
+ *
+ * @param string $join Query WHERE part
+ * @param mixed $params an array of parameters or a simple scalar
+ * @return sfAlyssaDoctrineQuery
+ */
+ public function whereProperyPath($where, $params = array())
+ {
+ $expr = $this->propertyPathToColumn($where);
+
+ return $this->where($expr, $params);
+ }
+
+ /**
+ * Adds ProperyPaths to the WHERE part of the query.
+ * <code>
+ * $q->andWhere('u.birthDate > ?', '1975-01-01');
+ * $q->andWhere('Book.Author.birthDate > ?', '1975-01-01');
+ * </code>
+ *
+ * @param string $where Query WHERE part
+ * @param mixed $params An array of parameters or a simple scalar
+ * @return sfAlyssaDoctrineQuery
+ */
+ public function addWhereProperyPath($where, $params = array())
+ {
+ $expr = $this->propertyPathToColumn($where);
+
+ return $this->addWhere($expr, $params);
+ }
+
+ /**
+ * Adds ProperyPaths to the GROUP BY part of the query.
+ * <code>
+ * $q->groupBy('Relation.id');
+ * </code>
+ *
+ * @param string $groupby Query GROUP BY part
+ * @return sfAlyssaDoctrineQuery
+ */
+ public function groupByProperyPath($groupby)
+ {
+ $columnName = $this->propertyPathToColumn($groupby);
+
+ return $this->groupBy($columnName);
+ }
+
+ /**
+ * Adds ProperyPaths to the GROUP BY part of the query.
+ * <code>
+ * $q->addGroupBy('Relation.id');
+ * </code>
+ *
+ * @param string $groupby Query GROUP BY part
+ * @return sfAlyssaDoctrineQuery
+ */
+ public function addGroupByProperyPath($groupby)
+ {
+ $columnName = $this->propertyPathToColumn($groupby);
+
+ return $this->addGroupBy($columnName);
+ }
+
+ /**
+ * Adds ProperyPaths to the ORDER BY part of the query
+ *
+ * <code>
+ * $query->orderBy('Relation.age');
+ * $query->orderBy('Relation.birthDate DESC');
+ * </code>
+ *
+ *
+ * @param string $orderby Query ORDER BY part
+ * @return sfAlyssaDoctrineQuery
+ */
+ public function orderByProperyPath($orderby)
+ {
+ $columnName = $this->propertyPathToColumn($orderby);
+
+ return $this->orderBy($columnName);
+ }
+
+ /**
+ * Adds ProperyPaths to the ORDER BY part of the query
+ *
+ * @param string $orderby Query ORDER BY part
+ * @return sfAlyssaDoctrineQuery
+ */
+ public function addOrderByProperyPath($orderby)
+ {
+ $columnName = $this->propertyPathToColumn($orderby);
+
+ return $this->addOrderBy($columnName);
+ }
+
+}
+
Added: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bin/prove.php
===================================================================
--- plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bin/prove.php
(rev 0)
+++ plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bin/prove.php
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,18 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Bernhard Schussek <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+include dirname(__FILE__).'/../bootstrap/unit.php';
+
+// create test harness
+$h = new lime_harness(new lime_output_color());
+$h->register(sfFinder::type('file')->name('*Test.php')->in(dirname(__FILE__).'/..'));
+
+// run and exit
+exit($h->run() ? 0 : 1);
\ No newline at end of file
Added: plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bootstrap/unit.php
===================================================================
--- plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bootstrap/unit.php
(rev 0)
+++ plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/bootstrap/unit.php
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Bernhard Schussek <[email protected]>
+ * (c) Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+$_test_dir = realpath(dirname(__FILE__).'/..');
+
+if (!isset($_SERVER['SYMFONY']))
+{
+ $_SERVER['SYMFONY'] = $_test_dir.'/../../../lib/vendor/symfony';
+}
+
+require_once $_SERVER['SYMFONY'] . '/test/bootstrap/unit.php';
+
+require_once $_SERVER['SYMFONY'] . '/lib/autoload/sfSimpleAutoload.class.php';
+
+
+$autoload =
sfSimpleAutoload::getInstance(sys_get_temp_dir().DIRECTORY_SEPARATOR.sprintf('sf_autoload_unit_propel_%s.data',
md5(__FILE__)));
+$autoload->addDirectory(realpath(dirname(__FILE__).'/../../lib'));
+$autoload->register();
+
+$_test_dir = realpath(dirname(__FILE__).'/..');
Added:
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Author.class.php
===================================================================
---
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Author.class.php
(rev 0)
+++
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Author.class.php
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,15 @@
+<?php
+
+class Author extends Doctrine_Record
+{
+ public function setTableDefinition()
+ {
+ $this->setTableName('author');
+ $this->hasColumn('id', 'integer', 10, array('primary' => true,
'autoincrement' => true));
+ $this->hasColumn('name', 'string', 255);
+ }
+
+ public function setUp()
+ {
+ }
+}
\ No newline at end of file
Added:
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Book.class.php
===================================================================
---
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Book.class.php
(rev 0)
+++
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Book.class.php
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,21 @@
+<?php
+
+class Book extends Doctrine_Record
+{
+ public function setTableDefinition()
+ {
+ $this->setTableName('book');
+ $this->hasColumn('id', 'integer', 10, array('primary' => true,
'autoincrement' => true));
+ $this->hasColumn('name', 'string', 255);
+ $this->hasColumn('author_id', 'string', 255);
+ }
+
+ public function setUp()
+ {
+ $this->hasOne('Author', array(
+ 'local' => 'author_id',
+ 'foreign' => 'id'
+ )
+ );
+ }
+}
Added:
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Review.class.php
===================================================================
---
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Review.class.php
(rev 0)
+++
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/Review.class.php
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,21 @@
+<?php
+
+class Review extends Doctrine_Record
+{
+ public function setTableDefinition()
+ {
+ $this->setTableName('review');
+ $this->hasColumn('id', 'integer', 10, array('primary' => true,
'autoincrement' => true));
+ $this->hasColumn('name', 'string', 255);
+ $this->hasColumn('book_id', 'string', 255);
+ }
+
+ public function setUp()
+ {
+ $this->hasOne('Book', array(
+ 'local' => 'book_id',
+ 'foreign' => 'id'
+ )
+ );
+ }
+}
\ No newline at end of file
Added:
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/data.yml
===================================================================
---
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/data.yml
(rev 0)
+++
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/fixtures/data.yml
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,30 @@
+Review:
+ Review_1:
+ name: Symfony comunity review
+ Book: Book_1
+ Review_2:
+ name: Zend comunity review
+ Book: Book_2
+ Review_3:
+ name: Php comunity review
+ Book: Book_3
+
+
+Book:
+ Book_1:
+ name: Practical Symfony
+ Author: Author_1
+ Book_2:
+ name: The Symfony Reference
+ Author: Author_1
+ Book_3:
+ name: Doctrine ORM for PHP
+ Author: Author_2
+
+Author:
+ Author_1:
+ name: Fabien Potencier
+ Author_2:
+ name: Jonathan Wage
+
+
Added:
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/sfAlyssaDoctrineQueryTest.class.php
===================================================================
---
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/sfAlyssaDoctrineQueryTest.class.php
(rev 0)
+++
plugins/sfAlyssaDoctrineObjectPathPlugin/trunk/test/unit/query/sfAlyssaDoctrineQueryTest.class.php
2010-04-06 22:09:14 UTC (rev 29024)
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ * (c) 2010 - Cooperativa de Trabajo Alyssa Limitada
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
+
+// initialize Doctrine
+$autoload =
sfSimpleAutoload::getInstance(sys_get_temp_dir().DIRECTORY_SEPARATOR.sprintf('sf_autoload_unit_doctrine_%s.data',
md5(__FILE__)));
+$autoload->addDirectory(realpath($_SERVER['SYMFONY'].'/plugins/sfDoctrinePlugin/lib'));
+$autoload->register();
+
+class MyProjectConfiguration extends sfProjectConfiguration {
+ public function setup()
+ {
+ $this->setPluginPath('sfAlyssaDoctrineObjectPathPlugin',
dirname(__FILE__).'/../../../../sfAlyssaDoctrineObjectPathPlugin');
+
+ $this->enablePlugins('sfAlyssaDoctrineObjectPathPlugin',
'sfDoctrinePlugin') ;
+ }
+}
+
+$configuration = new MyProjectConfiguration(dirname(__FILE__).'/../../lib',
new sfEventDispatcher());
+$database = new sfDoctrineDatabase(array('name' => 'doctrine', 'dsn' =>
'sqlite::memory:'));
+
+Doctrine_Core::createTablesFromModels(dirname(__FILE__).'/fixtures');
+
+// initialize data
+//Doctrine_Core::loadData(dirname(__FILE__).'/fixtures/data.yml');
+
+
+$t = new lime_test(5);
+
+$q = Doctrine_Query::create();
+
+// load correct class query
+$t->diag('sfAlyssaDoctrineQuery');
+$t->isa_ok($q, 'sfAlyssaDoctrineQuery', 'Doctrine is set up with correct query
class \'sfAlyssaDoctrineQuery\'');
+
+// join
+$t->diag('->joinByObjectPath()');
+
+$q->from('Review')->joinByObjectPath('Book.Author');
+$expectated = ' FROM Review LEFT JOIN Review.Book Review___Book LEFT JOIN
Review___Book.Author Review___Book___Author';
+$t->is($q->getDql(), $expectated, '->joinByObjectPath() generate correct DQL
query');
+
+// where
+$t->diag('->whereProperyPath()');
+$q = Doctrine_Query::create()
+ ->from('Review')
+ ->joinByObjectPath('Book.Author')
+ ->whereProperyPath('Book.Author.name = ?', 'Fabien Potencier');
+$expectated = ' FROM Review LEFT JOIN Review.Book Review___Book LEFT JOIN
Review___Book.Author Review___Book___Author WHERE Review___Book___Author.name =
?';
+$t->is($q->getDql(), $expectated, '->whereProperyPath() generate correct DQL
query');
+
+// orderBy
+$t->diag('->orderByProperyPath()');
+$q = Doctrine_Query::create()
+ ->from('Review')
+ ->joinByObjectPath('Book.Author')
+ ->orderByProperyPath('Book.Author.name');
+$expectated = ' FROM Review LEFT JOIN Review.Book Review___Book LEFT JOIN
Review___Book.Author Review___Book___Author ORDER BY
Review___Book___Author.name';
+$t->is($q->getDql(), $expectated, '->orderByProperyPath() generate correct DQL
query');
+
+// test with data
+$t->todo('->execute()');
+
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.