Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature camel cased params #155

Merged
merged 1 commit into from May 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Request/ParamConverter/PropelParamConverter.php
Expand Up @@ -2,6 +2,7 @@

namespace Propel\PropelBundle\Request\ParamConverter;

use Propel\PropelBundle\Util\PropelInflector;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand Down Expand Up @@ -57,7 +58,7 @@ protected function findOneBy($classQuery, Request $request, $exclude)
foreach ($request->attributes->all() as $key => $value) {
if (!in_array($key, $exclude)) {
try {
$query->{'filterBy' . ucfirst($key)}($value);
$query->{'filterBy' . PropelInflector::camelize($key)}($value);
$hasCriteria = true;
} catch (\PropelException $e) { }
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/Fixtures/Model/BookQuery.php
Expand Up @@ -18,6 +18,7 @@
class BookQuery extends BaseBookQuery {

private $bySlug = false;
private $byAuthorSlug = false;

/**
* fake for test
Expand All @@ -34,6 +35,18 @@ public function findPk($key, $con = null)
return null;
}

/**
* fake for test
*/
public function filterByAuthorSlug($slug = null, $comparison = null)
{
if ('my-author' === $slug) {
$this->byAuthorSlug = true;
}

return $this;
}

/**
* fake for test
*/
Expand Down Expand Up @@ -65,6 +78,13 @@ public function findOne($con = null)
$book->setName('My Book');
$book->setSlug('my-book');

return $book;
} else if (true === $this->byAuthorSlug) {
$book = new Book();
$book->setId(2);
$book->setName('My Kewl Book');
$book->setSlug('my-kewl-book');

return $book;
}

Expand Down
11 changes: 11 additions & 0 deletions Tests/Request/ParamConverter/PropelParamConverterTest.php
Expand Up @@ -65,6 +65,17 @@ public function testParamConverterFindSlug()
'param "book" should be an instance of "Propel\PropelBundle\Tests\Fixtures\Model\Book"');
}

public function testParamConverterFindCamelCasedSlug()
{
$paramConverter = new PropelParamConverter();
$request = new Request(array(), array(), array('author_slug' => 'my-author', 'slug' => 'my-kewl-book', 'book' => null));
$configuration = new ParamConverter(array('class' => 'Propel\PropelBundle\Tests\Fixtures\Model\Book', 'name' => 'book'));

$paramConverter->apply($request, $configuration);
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\Model\Book',$request->attributes->get('book'),
'param "book" should be an instance of "Propel\PropelBundle\Tests\Fixtures\Model\Book"');
}

/**
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
Expand Down