|
| 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 | +} |
0 commit comments