Skip to content

Commit 4f47128

Browse files
committed
Added Functional ORM tests
1 parent 0feba27 commit 4f47128

File tree

5 files changed

+104
-1
lines changed

5 files changed

+104
-1
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Orm;
4+
5+
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase as ComponentBaseTestCase;
6+
use Symfony\Cmf\Component\Testing\Document\Content;
7+
8+
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route;
9+
10+
class OrmTestCase extends ComponentBaseTestCase
11+
{
12+
protected function getKernelConfiguration()
13+
{
14+
return array(
15+
'environment' => 'orm',
16+
);
17+
}
18+
19+
protected function clearDb($model)
20+
{
21+
if (is_array($model)) {
22+
foreach ($model as $singleModel) {
23+
$this->clearDb($singleModel);
24+
}
25+
}
26+
27+
$items = $this->getDm()->getRepository($model)->findAll();
28+
29+
foreach ($items as $item) {
30+
$this->getDm()->remove($item);
31+
}
32+
33+
$this->getDm()->flush();
34+
}
35+
36+
protected function getDm()
37+
{
38+
return $this->db('ORM')->getOm();
39+
}
40+
41+
protected function createRoute($name, $path)
42+
{
43+
// split path in static and variable part
44+
preg_match('{^(.*?)(/[^/]*\{.*)?$}', $path, $paths);
45+
46+
$route = new Route();
47+
$route->setName($name);
48+
$route->setStaticPrefix($paths[1]);
49+
if (isset($paths[2])) {
50+
$route->setVariablePattern($paths[2]);
51+
}
52+
53+
$this->getDm()->persist($route);
54+
$this->getDm()->flush();
55+
56+
return $route;
57+
}
58+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Orm;
4+
5+
use Symfony\Component\HttpFoundation\Request;
6+
7+
class RouteProviderTest extends OrmTestCase
8+
{
9+
private $repository;
10+
11+
public function setUp()
12+
{
13+
parent::setUp();
14+
$this->clearDb('CmfRoutingBundle:Route');
15+
16+
$this->repository = $this->getContainer()->get('cmf_routing.route_provider');
17+
}
18+
19+
public function testGetRouteCollectionForRequest()
20+
{
21+
$this->createRoute('route1', '/test');
22+
$this->createRoute('route2', '/test/child');
23+
$this->createRoute('route3', '/test/child/testroutechild');
24+
25+
$this->getDm()->clear();
26+
27+
$routes = $this->repository->getRouteCollectionForRequest(Request::create('/test/child/testroutechild'));
28+
$this->assertCount(3, $routes);
29+
$this->assertContainsOnlyInstancesOf('Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route', $routes);
30+
}
31+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmf_routing:
2+
dynamic:
3+
persistence:
4+
orm:
5+
enabled: true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$loader->import(CMF_TEST_CONFIG_DIR.'/default.php');
4+
$loader->import(CMF_TEST_CONFIG_DIR.'/phpcr_odm.php');
5+
$loader->import(CMF_TEST_CONFIG_DIR.'/sonata_admin.php');
6+
$loader->import(__DIR__.'/cmf_routing.yml');
7+
$loader->import(__DIR__.'/cmf_routing.orm.yml');
8+
//$loader->import(__DIR__.'/doctrine_orm.yml');

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"require-dev": {
2222
"symfony-cmf/testing": "1.0.*",
2323
"sonata-project/doctrine-phpcr-admin-bundle": "1.0.*",
24-
"symfony/monolog-bundle": "2.2.*"
24+
"symfony/monolog-bundle": "2.2.*",
25+
"doctrine/orm": "2.3.*"
2526
},
2627
"suggest": {
2728
"doctrine/phpcr-odm": "To enable support for the PHPCR ODM documents",

0 commit comments

Comments
 (0)