Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 52e329e

Browse files
committed
Refactrored GenericMaker
1 parent 4989bad commit 52e329e

File tree

4 files changed

+62
-47
lines changed

4 files changed

+62
-47
lines changed

AutoRoute/RouteMaker/GenericMaker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public function __construct(DocumentManager $dm)
2323
public function make(RouteStack $routeStack)
2424
{
2525
$paths = $routeStack->getFullPaths();
26+
$meta = $this->dm->getClassMetadata('Doctrine\ODM\PHPCR\Document\Generic');
2627

2728
foreach ($paths as $path) {
2829
$absPath = '/'.$path;
2930
$doc = $this->dm->find(null, $absPath);
3031

3132
if (null === $doc) {
3233
$doc = new Generic;
33-
$meta = $this->dm->getClassMetadata(get_class($doc));
3434
$meta->setIdentifierValue($doc, $absPath);
3535
}
3636

AutoRoute/RouteMakerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @author Daniel Leech <[email protected]>
1313
* @date 13/03/24
1414
*/
15-
class RouteMakerInterface
15+
interface RouteMakerInterface
1616
{
1717
public function make(RouteStack $routeStack);
1818
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute\RouteMaker;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteMaker\GenericMaker;
6+
7+
class GenericMakerTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->dm = $this->getMockBuilder(
12+
'Doctrine\ODM\PHPCR\DocumentManager'
13+
)->disableOriginalConstructor()->getMock();
14+
15+
$this->routeStack = $this->getMockBuilder(
16+
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack'
17+
)->disableOriginalConstructor()->getMock();
18+
19+
$this->classMetadata = $this->getMockBuilder(
20+
'Doctrine\ODM\PHPCR\Mapping\ClassMetadata'
21+
)->disableOriginalConstructor()->getMock();
22+
23+
$this->routeMaker = new GenericMaker($this->dm);
24+
}
25+
26+
// Note that this tests everything apart from ensuring
27+
// that the correct routes are added with addRoute, we
28+
// only assert that 2 routes are added.
29+
public function testMake()
30+
{
31+
$this->routeStack->expects($this->once())
32+
->method('getFullPaths')
33+
->will($this->returnValue(array(
34+
'test',
35+
'test/foo',
36+
)));
37+
38+
$this->dm->expects($this->once())
39+
->method('getClassMetadata')
40+
->with('Doctrine\ODM\PHPCR\Document\Generic')
41+
->will($this->returnValue($this->classMetadata));
42+
43+
$this->routeStack->expects($this->exactly(2))
44+
->method('addRoute');
45+
46+
// If anybody knows of a better way to do this ...
47+
$test = $this;
48+
$this->classMetadata->expects($this->exactly(2))
49+
->method('setIdentifierValue')
50+
->will($this->returnCallback(function ($doc, $id) use ($test) {
51+
static $i = 0;
52+
$expected = array('/test', '/test/foo');
53+
54+
$test->assertInstanceOf('Doctrine\ODM\PHPCR\Document\Generic', $doc);
55+
$test->assertEquals($expected[$i++], $id);
56+
}));
57+
58+
$this->routeMaker->make($this->routeStack);
59+
}
60+
}

Tests/AutoRoute/RouteMakerTest.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)