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

Commit 1ee31f0

Browse files
committed
All tests pass
1 parent 631894b commit 1ee31f0

File tree

8 files changed

+73
-32
lines changed

8 files changed

+73
-32
lines changed

AutoRoute/AutoRouteMaker.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ public function __construct(DocumentManager $dm)
1919

2020
public function createOrUpdateAutoRoute(AutoRouteStack $autoRouteStack)
2121
{
22-
$content = $autoRouteStack->getContext()->getContent();
22+
$context = $autoRouteStack->getContext();
23+
$content = $context->getContent();
2324

2425
$autoRoute = $this->getAutoRouteForDocument($content);
2526

2627
if (null === $autoRoute) {
2728
$autoRoute = new AutoRoute;
28-
$autoRoute->setParent($autoRouteStack->getContext()->getTopRoute());
29+
$autoRoute->setParent($context->getTopRoute());
2930
$autoRoute->setRouteContent($content);
3031
}
3132

AutoRoute/RouteStack/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function build(RouteStack $routeStack, BuilderUnitInterface $rsbu)
3333
$rsbu->notExistsAction($routeStack);
3434
}
3535

36-
// hmm ...
36+
// hmm ... this seems wierd. Needs some refactoring.
3737
$routeStack->close();
3838
$routeStack->getContext()->commitRouteStack();
3939
}

Tests/AutoRoute/AutoRouteMakerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function setUp()
4747

4848
protected function setupDocumentPersisted($isPersisted)
4949
{
50-
$this->dm->expects($this->once())
50+
$this->dm->expects($this->any())
5151
->method('getClassMetadata')
5252
->will($this->returnValue($this->metadata));
5353
$this->dm->expects($this->once())
@@ -93,10 +93,6 @@ public function testCreateOrUpdateAutoRouteForNew()
9393
$this->setupDocumentPersisted(false);
9494

9595
$testCase = $this;
96-
$this->dm->expects($this->once())
97-
->method('getReferrers')
98-
->will($this->returnValue(new ArrayCollection(array(
99-
))));
10096

10197
$this->autoRouteStack->expects($this->once())
10298
->method('getContext')

Tests/AutoRoute/FactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public function provideTestGetChain()
7979
'name' => 'fixed',
8080
'message' => 'barfoo'
8181
),
82-
'exists' => array(
82+
'exists_action' => array(
8383
'strategy' => 'create'
8484
),
85-
'not_exists' => array(
85+
'not_exists_action' => array(
8686
'strategy' => 'throw_excep',
8787
),
8888
),

Tests/AutoRoute/PathExists/AutoIncrementPathTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function testAutoIncrement()
4848
->with($this->routeStack);
4949

5050
$this->aiPath->execute($this->routeStack);
51-
5251
}
5352

5453
}

Tests/AutoRoute/PathExists/UsePathTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ public function setUp()
2020
$this->routeObject = new \stdClass;
2121
}
2222

23-
public function testAutoIncrement()
23+
public function testUse()
2424
{
2525
$this->routeStack->expects($this->once())
26-
->method('getFullPath')
27-
->will($this->returnValue('foobar'));
26+
->method('getFullPaths')
27+
->will($this->returnValue(array(
28+
'foobar'
29+
)));
2830

2931
$this->routeStack->expects($this->once())
3032
->method('addRoute')

Tests/AutoRoute/PathProvider/FromObjectMethodProviderTest.php

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute;
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\AutoRoute\PathProvider;
44

55
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathExists\PathProvider;
66
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\PathProvider\FromObjectMethodProvider;
@@ -9,14 +9,18 @@ class FromObjectMethodProviderTest extends \PHPUnit_Framework_TestCase
99
{
1010
public function setUp()
1111
{
12-
$this->provider = new FromObjectMethodProvider;
1312
$this->builderContext = $this->getMock(
1413
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\BuilderContext'
1514
);
1615
$this->routeStack = $this->getMockBuilder(
1716
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\RouteStack'
1817
)->disableOriginalConstructor()->getMock();
19-
$this->object = new FromObjectMethodTestClass;
18+
$this->slugifier = $this->getMock(
19+
'Symfony\Cmf\Bundle\CoreBundle\Slugifier\SlugifierInterface'
20+
);
21+
22+
$this->provider = new FromObjectMethodProvider($this->slugifier);
23+
$this->object = new FromObjectMethodTestClass();
2024
}
2125

2226
/**
@@ -42,35 +46,60 @@ public function testProvideMethod_invalidMethod()
4246
$this->provider->providePath($this->routeStack);
4347
}
4448

45-
public function testProvideMethod()
49+
public function setupTest($slugify = true)
4650
{
47-
$this->routeStack->expects($this->once())
48-
->method('addPathElements')
49-
->with(array('this', 'is', 'path'));
5051
$this->routeStack->expects($this->once())
5152
->method('getContext')
5253
->will($this->returnValue($this->builderContext));
5354
$this->builderContext->expects($this->once())
5455
->method('getContent')
5556
->will($this->returnValue($this->object));
5657

58+
if ($slugify) {
59+
$this->slugifier->expects($this->any())
60+
->method('slugify')
61+
->will($this->returnCallback(function ($el) { return $el; }));
62+
}
63+
}
64+
65+
public function testProvideMethod()
66+
{
67+
$this->setupTest();
68+
$this->routeStack->expects($this->once())
69+
->method('addPathElements')
70+
->with(array('this', 'is', 'path'));
71+
5772
$this->provider->init(array('method' => 'getSlug'));
5873
$this->provider->providePath($this->routeStack);
5974
}
6075

76+
public function testProvideMethodNoSlugify()
77+
{
78+
$this->setupTest(false);
79+
$this->routeStack->expects($this->once())
80+
->method('addPathElements')
81+
->with(array('this', 'is', 'path'));
82+
83+
$this->provider->init(array('method' => 'getSlug', 'slugify' => false));
84+
$this->provider->providePath($this->routeStack);
85+
}
86+
87+
public function testProvideMethodWithString()
88+
{
89+
$this->setupTest();
90+
91+
$this->provider->init(array('method' => 'getStringSlug'));
92+
$this->provider->providePath($this->routeStack);
93+
}
94+
6195
/**
6296
* @expectedException \RuntimeException
6397
*/
64-
public function testProvideMethodWithInvalidReturnValue()
98+
public function testProvideMethodWithAbsolute()
6599
{
66-
$this->routeStack->expects($this->once())
67-
->method('getContext')
68-
->will($this->returnValue($this->builderContext));
69-
$this->builderContext->expects($this->once())
70-
->method('getContent')
71-
->will($this->returnValue($this->object));
100+
$this->setupTest();
72101

73-
$this->provider->init(array('method' => 'getBadSlug'));
102+
$this->provider->init(array('method' => 'getAbsoluteSlug'));
74103
$this->provider->providePath($this->routeStack);
75104
}
76105
}
@@ -82,8 +111,14 @@ public function getSlug()
82111
return array('this', 'is', 'path');
83112
}
84113

85-
public function getBadSlug()
114+
public function getStringSlug()
86115
{
87116
return 'this/is/a/path';
88117
}
118+
119+
public function getAbsoluteSlug()
120+
{
121+
return '/this/is/absolute';
122+
}
123+
89124
}

Tests/AutoRoute/RouteStack/BuilderTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testNotExists()
3232
->with($this->routeStack);
3333
$this->routeStack->expects($this->once())
3434
->method('getFullPath')
35-
->will($this->returnValue('/test/path'));
35+
->will($this->returnValue('test/path'));
3636

3737
$this->phpcrSession->expects($this->once())
3838
->method('nodeExists')
@@ -42,6 +42,10 @@ public function testNotExists()
4242
$this->routeStackBuilderUnit->expects($this->once())
4343
->method('notExistsAction')
4444
->with($this->routeStack);
45+
46+
$this->routeStack->expects($this->once())
47+
->method('getContext')
48+
->will($this->returnValue($this->builderContext));
4549

4650
$this->routeStack->expects($this->once())
4751
->method('close');
@@ -57,7 +61,11 @@ public function testExists()
5761

5862
$this->routeStack->expects($this->once())
5963
->method('getFullPath')
60-
->will($this->returnValue('/test/path'));
64+
->will($this->returnValue('test/path'));
65+
66+
$this->routeStack->expects($this->once())
67+
->method('getContext')
68+
->will($this->returnValue($this->builderContext));
6169

6270
$this->routeStackBuilderUnit->expects($this->exactly(1))
6371
->method('existsAction')

0 commit comments

Comments
 (0)