Skip to content

Commit

Permalink
add test for paramconverter, fix issue with paramconverter findOneByXXX
Browse files Browse the repository at this point in the history
  • Loading branch information
jaugustin committed Sep 23, 2011
1 parent 537799b commit f53e233
Show file tree
Hide file tree
Showing 9 changed files with 2,029 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Request/ParamConverter/PropelParamConverter.php
Expand Up @@ -19,17 +19,15 @@ class PropelParamConverter implements ParamConverterInterface
public function apply(Request $request, ConfigurationInterface $configuration)
{
$classQuery = $configuration->getClass() . 'Query';
$options = $configuration->getOptions();

if (!class_exists($classQuery)) {
throw new \Exception(sprintf('The %s Query class does not exist', $classQuery));
}

// find by Pk
if (false === $object = $this->findPk($classQuery, $request)) {
throw new \LogicException('Unable to guess how to get a Propel object from the request information.');
// find by criteria
if (false === $object = $this->findOneBy($classQuery, $request, $options)) {
if (false === $object = $this->findOneBy($classQuery, $request)) {
throw new \LogicException('Unable to guess how to get a Propel object from the request information.');
}
}
Expand All @@ -50,7 +48,7 @@ protected function findPk($classQuery, Request $request)
return $classQuery::create()->findPk($request->attributes->get('id'));
}

protected function findOneBy($classQuery, Request $request, $options)
protected function findOneBy($classQuery, Request $request)
{
$query = $classQuery::create();
$hasCriteria = false;
Expand All @@ -73,7 +71,6 @@ public function supports(ConfigurationInterface $configuration)
if (null === ($classname = $configuration->getClass())) {
return false;
}
$options = $configuration->getOptions();
if (!class_exists($classname)) {
return false;
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/Fixtures/Model/Book.php
@@ -0,0 +1,20 @@
<?php

namespace Propel\PropelBundle\Tests\Fixtures\Model;

use Propel\PropelBundle\Tests\Fixtures\Model\om\BaseBook;


/**
* Skeleton subclass for representing a row from the 'book' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class Book extends BaseBook {

} // Book
20 changes: 20 additions & 0 deletions Tests/Fixtures/Model/BookPeer.php
@@ -0,0 +1,20 @@
<?php

namespace Propel\PropelBundle\Tests\Fixtures\Model;

use Propel\PropelBundle\Tests\Fixtures\Model\om\BaseBookPeer;


/**
* Skeleton subclass for performing query and update operations on the 'book' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class BookPeer extends BaseBookPeer {

} // BookPeer
59 changes: 59 additions & 0 deletions Tests/Fixtures/Model/BookQuery.php
@@ -0,0 +1,59 @@
<?php

namespace Propel\PropelBundle\Tests\Fixtures\Model;

use Propel\PropelBundle\Tests\Fixtures\Model\om\BaseBookQuery;


/**
* Skeleton subclass for performing query and update operations on the 'book' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class BookQuery extends BaseBookQuery {

private $bySlug = false;
/**
* fake for test
*/
public function findPk($key, $con = null)
{
if (1 === $key) {
$book = new Book();
$book->setId(1);
return $book;
}
return null;
}

/**
* fake for test
*/
public function filterBySlug($slug = null, $comparison = null)
{
if ('my-book' == $slug) {
$this->bySlug = true;
}
return $this;
}

/**
* fake for test
*/
public function findOne($con = null)
{
if ($this->bySlug) {
$book = new Book();
$book->setId(1);
$book->setName('My Book');
$book->setSlug('my-book');
return $book;
}
return null;
}
} // BookQuery
57 changes: 57 additions & 0 deletions Tests/Fixtures/Model/map/BookTableMap.php
@@ -0,0 +1,57 @@
<?php

namespace Propel\PropelBundle\Tests\Fixtures\Model\map;

use \RelationMap;
use \TableMap;


/**
* This class defines the structure of the 'book' table.
*
*
*
* This map class is used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
*/
class BookTableMap extends TableMap
{

/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'vendor/bundles/Propel/PropelBundle/Tests/Fixtures/Model.map.BookTableMap';

/**
* Initialize the table attributes, columns and validators
* Relations are not initialized by this method since they are lazy loaded
*
* @return void
* @throws PropelException
*/
public function initialize()
{
// attributes
$this->setName('book');
$this->setPhpName('Book');
$this->setClassname('Propel\\PropelBundle\\Tests\\Fixtures\\Model\\Book');
$this->setPackage('vendor/bundles/Propel/PropelBundle/Tests/Fixtures/Model');
$this->setUseIdGenerator(true);
// columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addColumn('NAME', 'Name', 'VARCHAR', false, 255, null);
$this->addColumn('SLUG', 'Slug', 'VARCHAR', false, 255, null);
// validators
} // initialize()

/**
* Build the RelationMap objects for this table relationships
*/
public function buildRelations()
{
} // buildRelations()

} // BookTableMap

0 comments on commit f53e233

Please sign in to comment.