Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 5004fc5

Browse files
alextechweierophinney
authored andcommitted
Fix #69. Compatibility of legacy SM2 style in PHP 7.2.
No need to dynamically request service name, when its known that Navigation::class is one ultimately being requested in __invoke
1 parent 7762e60 commit 5004fc5

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

src/Service/AbstractNavigationFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
5353
* @param null|string $requestedName
5454
* @return Navigation
5555
*/
56-
public function createService(ServiceLocatorInterface $container, $name = null, $requestedName = null)
56+
public function createService(ServiceLocatorInterface $container)
5757
{
58-
$requestedName = $requestedName ?: Navigation::class;
59-
return $this($container, $requestedName);
58+
return $this($container, Navigation::class);
6059
}
6160

6261
/**

test/Service/AbstractNavigationFactoryTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99

1010
use PHPUnit\Framework\TestCase;
1111
use ReflectionMethod;
12+
use Zend\Mvc\Application;
13+
use Zend\Mvc\MvcEvent;
1214
use Zend\Mvc\Router as MvcRouter;
1315
use Zend\Navigation\Exception;
16+
use Zend\Navigation\Navigation;
17+
use Zend\Navigation\Service\AbstractNavigationFactory;
1418
use Zend\Router;
19+
use Zend\ServiceManager\Config;
20+
use Zend\ServiceManager\ServiceManager;
1521

1622
/**
1723
* @todo Write tests covering full functionality. Tests were introduced to
@@ -70,4 +76,58 @@ public function testCanInjectComponentsUsingZendMvcRouterClasses()
7076

7177
$this->assertSame([], $pages);
7278
}
79+
80+
public function testCanCreateNavigationInstanceV2()
81+
{
82+
$routerMatchClass = $this->getRouteMatchClass();
83+
$routerClass = $this->getRouterClass();
84+
$routeMatch = new $routerMatchClass([]);
85+
$router = new $routerClass();
86+
87+
$mvcEventStub = new MvcEvent();
88+
$mvcEventStub->setRouteMatch($routeMatch);
89+
$mvcEventStub->setRouter($router);
90+
91+
$applicationMock = $this->getMockBuilder(Application::class)
92+
->disableOriginalConstructor()
93+
->getMock();
94+
95+
$applicationMock->expects($this->any())
96+
->method('getMvcEvent')
97+
->willReturn($mvcEventStub);
98+
99+
$serviceManagerMock = $this->getMockBuilder(ServiceManager::class)
100+
->disableOriginalConstructor()
101+
->getMock();
102+
103+
$serviceManagerMock->expects($this->any())
104+
->method('get')
105+
->willReturnMap([
106+
['config', ['navigation' => ['testStubNavigation' => []]]],
107+
['Application', $applicationMock]
108+
]);
109+
110+
$navigationFactory
111+
= $this->getMockForAbstractClass(AbstractNavigationFactory::class);
112+
$navigationFactory->expects($this->any())
113+
->method('getName')
114+
->willReturn('testStubNavigation');
115+
$navigation = $navigationFactory->createService($serviceManagerMock);
116+
117+
$this->assertInstanceOf(Navigation::class, $navigation);
118+
}
119+
120+
public function getRouterClass()
121+
{
122+
return class_exists(MvcRouter\Http\TreeRouteStack::class)
123+
? MvcRouter\Http\TreeRouteStack::class
124+
: Router\Http\TreeRouteStack::class;
125+
}
126+
127+
public function getRouteMatchClass()
128+
{
129+
return class_exists(MvcRouter\RouteMatch::class)
130+
? MvcRouter\RouteMatch::class
131+
: Router\RouteMatch::class;
132+
}
73133
}

0 commit comments

Comments
 (0)