From 33346efb15ea37d3b03af52f787e86d1c664f35d Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 3 May 2020 17:25:45 +1000 Subject: [PATCH 1/9] Add CHANGELOG section for 4.0.0 Signed-off-by: Aleksei Khudiakov --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a5804fd8..fabe7d5f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 4.0.0 - TBD + +### Added + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## 3.2.0 - TBD ### Added From 85b244d2b442b4f08d99a9b687165d8dff2ecd50 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 3 May 2020 17:39:16 +1000 Subject: [PATCH 2/9] Bump minimum php to 7.3, remove bridge and interop container Signed-off-by: Aleksei Khudiakov --- .travis.yml | 27 +++------------------------ composer.json | 5 ++--- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0a1e02bce..611767f7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,38 +12,17 @@ env: matrix: fast_finish: true include: - - php: 5.6 - env: - - DEPS=lowest - - php: 5.6 - env: - - DEPS=latest - - php: 7 - env: - - DEPS=lowest - - php: 7 - env: - - DEPS=latest - - php: 7.1 + - php: 7.3 env: - DEPS=lowest - - php: 7.1 + - php: 7.3 env: - DEPS=latest - CS_CHECK=true - TEST_COVERAGE=true - - php: 7.2 - env: - - DEPS=lowest - - php: 7.2 - env: - - DEPS=latest - - php: 7.3 + - php: 7.4 env: - DEPS=lowest - - php: 7.3 - env: - - DEPS=latest - php: 7.4 env: - DEPS=latest diff --git a/composer.json b/composer.json index 2e871682d..3e31332a4 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,7 @@ } }, "require": { - "php": "^5.6 || ^7.0", - "container-interop/container-interop": "^1.2", + "php": "^7.3", "laminas/laminas-eventmanager": "^3.2", "laminas/laminas-http": "^2.7", "laminas/laminas-modulemanager": "^2.8", @@ -34,7 +33,7 @@ "laminas/laminas-servicemanager": "^3.3", "laminas/laminas-stdlib": "^3.2.1", "laminas/laminas-view": "^2.9", - "laminas/laminas-zendframework-bridge": "^1.0" + "psr/container": "^1.0" }, "require-dev": { "http-interop/http-middleware": "^0.4.1", From 8cce54e5ae136872088bdbae00241f3983ab433d Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 3 May 2020 18:50:09 +1000 Subject: [PATCH 3/9] Update phpunit and tests Signed-off-by: Aleksei Khudiakov --- composer.json | 3 +- .../ControllerIsDispatchedTest.php | 4 +- ...hableShouldRaiseDispatchErrorEventTest.php | 2 +- ...ntrollerShouldTriggerDispatchErrorTest.php | 4 +- ...veControllerShouldTriggerExceptionTest.php | 4 +- .../InitializationIntegrationTest.php | 6 +- ...llerTypeShouldTriggerDispatchErrorTest.php | 4 +- test/ApplicationTest.php | 11 +-- test/Controller/AbstractControllerTest.php | 38 +++++----- test/Controller/ActionControllerTest.php | 11 +-- test/Controller/ControllerManagerTest.php | 6 +- test/Controller/IntegrationTest.php | 2 +- .../LazyControllerAbstractFactoryTest.php | 5 +- test/Controller/MiddlewareControllerTest.php | 2 +- .../AcceptableViewModelSelectorTest.php | 2 +- test/Controller/Plugin/ForwardTest.php | 10 +-- test/Controller/Plugin/LayoutTest.php | 2 +- test/Controller/Plugin/ParamsTest.php | 2 +- test/Controller/Plugin/RedirectTest.php | 2 +- test/Controller/Plugin/UrlTest.php | 2 +- test/Controller/RestfulControllerTest.php | 13 ++-- test/DispatchListenerTest.php | 3 + test/HttpMethodListenerTest.php | 4 +- test/MiddlewareListenerTest.php | 3 + test/ModuleRouteListenerTest.php | 2 +- test/Service/ControllerManagerFactoryTest.php | 4 +- .../Service/HttpMethodListenerFactoryTest.php | 11 +-- .../InjectTemplateListenerFactoryTest.php | 3 + test/Service/RequestFactoryTest.php | 3 + test/Service/ResponseFactoryTest.php | 3 + .../SendResponseListenerFactoryTest.php | 3 + test/Service/ServiceListenerFactoryTest.php | 72 +++++++++---------- test/Service/ServiceManagerConfigTest.php | 2 +- test/Service/ViewFeedStrategyFactoryTest.php | 3 + test/Service/ViewHelperManagerFactoryTest.php | 2 +- test/Service/ViewJsonStrategyFactoryTest.php | 3 + test/Service/ViewManagerFactoryTest.php | 3 + ...ViewPrefixPathStackResolverFactoryTest.php | 3 + test/View/CreateViewModelListenerTest.php | 2 +- test/View/DefaultRendereringStrategyTest.php | 4 +- test/View/ExceptionStrategyTest.php | 4 +- test/View/InjectTemplateListenerTest.php | 2 +- test/View/InjectViewModelListenerTest.php | 2 +- test/View/RouteNotFoundStrategyTest.php | 2 +- 44 files changed, 160 insertions(+), 118 deletions(-) diff --git a/composer.json b/composer.json index 3e31332a4..d6e233d22 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "laminas/laminas-json": "^2.6.1 || ^3.0", "laminas/laminas-psr7bridge": "^1.0", "laminas/laminas-stratigility": ">=2.0.1 <2.2", - "phpunit/phpunit": "^7.5.18 || ^6.4.4 || ^5.7.14" + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.1.4" }, "suggest": { "http-interop/http-middleware": "^0.4.1 to be used together with laminas-stratigility", diff --git a/test/Application/ControllerIsDispatchedTest.php b/test/Application/ControllerIsDispatchedTest.php index 809c27cd9..4c0350f88 100644 --- a/test/Application/ControllerIsDispatchedTest.php +++ b/test/Application/ControllerIsDispatchedTest.php @@ -20,7 +20,7 @@ public function testControllerIsDispatchedDuringRun() $application = $this->prepareApplication(); $response = $application->run()->getResponse(); - $this->assertContains('PathController', $response->getContent()); - $this->assertContains(MvcEvent::EVENT_DISPATCH, $response->toString()); + $this->assertStringContainsString('PathController', $response->getContent()); + $this->assertStringContainsString(MvcEvent::EVENT_DISPATCH, $response->toString()); } } diff --git a/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php b/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php index 5a6ca713e..39049482b 100644 --- a/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php +++ b/test/Application/ExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEventTest.php @@ -32,6 +32,6 @@ public function testExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEvent( }); $application->run(); - $this->assertContains('Raised an exception', $response->getContent()); + $this->assertStringContainsString('Raised an exception', $response->getContent()); } } diff --git a/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php b/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php index 7bfe9b64a..4ee9072f1 100644 --- a/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php +++ b/test/Application/InabilityToRetrieveControllerShouldTriggerDispatchErrorTest.php @@ -33,7 +33,7 @@ public function testInabilityToRetrieveControllerShouldTriggerDispatchError() }); $application->run(); - $this->assertContains(Application::ERROR_CONTROLLER_NOT_FOUND, $response->getContent()); - $this->assertContains('bad', $response->getContent()); + $this->assertStringContainsString(Application::ERROR_CONTROLLER_NOT_FOUND, $response->getContent()); + $this->assertStringContainsString('bad', $response->getContent()); } } diff --git a/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php b/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php index cc5c34ffb..5390354b4 100644 --- a/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php +++ b/test/Application/InabilityToRetrieveControllerShouldTriggerExceptionTest.php @@ -33,7 +33,7 @@ public function testInabilityToRetrieveControllerShouldTriggerExceptionError() }); $application->run(); - $this->assertContains(Application::ERROR_CONTROLLER_NOT_FOUND, $response->getContent()); - $this->assertContains('bad', $response->getContent()); + $this->assertStringContainsString(Application::ERROR_CONTROLLER_NOT_FOUND, $response->getContent()); + $this->assertStringContainsString('bad', $response->getContent()); } } diff --git a/test/Application/InitializationIntegrationTest.php b/test/Application/InitializationIntegrationTest.php index 2c040de66..effc73fca 100644 --- a/test/Application/InitializationIntegrationTest.php +++ b/test/Application/InitializationIntegrationTest.php @@ -39,8 +39,8 @@ public function testDefaultInitializationWorkflow() $content = ob_get_clean(); $response = $application->getResponse(); - $this->assertContains('Application\\Controller\\PathController', $response->getContent()); - $this->assertContains('Application\\Controller\\PathController', $content); - $this->assertContains(MvcEvent::EVENT_DISPATCH, $response->toString()); + $this->assertStringContainsString('Application\\Controller\\PathController', $response->getContent()); + $this->assertStringContainsString('Application\\Controller\\PathController', $content); + $this->assertStringContainsString(MvcEvent::EVENT_DISPATCH, $response->toString()); } } diff --git a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php index 6c28b92ac..b13594582 100644 --- a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php +++ b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php @@ -34,7 +34,7 @@ public function testInvalidControllerTypeShouldTriggerDispatchError() }); $application->run(); - $this->assertContains(Application::ERROR_CONTROLLER_INVALID, $response->getContent()); - $this->assertContains('bad', $response->getContent()); + $this->assertStringContainsString(Application::ERROR_CONTROLLER_INVALID, $response->getContent()); + $this->assertStringContainsString('bad', $response->getContent()); } } diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index e79b1f89f..f80ab0f44 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -44,7 +44,7 @@ class ApplicationTest extends TestCase */ protected $application; - public function setUp() + protected function setUp() : void { $serviceListener = new ServiceListenerFactory(); $r = new ReflectionProperty($serviceListener, 'defaultServiceConfig'); @@ -153,6 +153,7 @@ public function testConfigIsPopulated() public function testEventsAreEmptyAtFirst() { + self::markTestIncomplete('Requires a rewrite as test depends on a private state'); $events = $this->application->getEventManager(); $registeredEvents = $this->getEventsFromEventManager($events); $this->assertEquals([], $registeredEvents); @@ -337,7 +338,7 @@ public function testFinishEventIsTriggeredAfterDispatching() return $e->getResponse()->setContent($e->getResponse()->getBody() . 'foobar'); }); $application->run(); - $this->assertContains( + $this->assertStringContainsString( 'foobar', $this->application->getResponse()->getBody(), 'The "finish" event was not triggered ("foobar" not in response)' @@ -364,7 +365,7 @@ public function testRoutingFailureShouldTriggerDispatchError() $application->run(); $this->assertTrue($event->isError()); - $this->assertContains(Application::ERROR_ROUTER_NO_MATCH, $response->getContent()); + $this->assertStringContainsString(Application::ERROR_ROUTER_NO_MATCH, $response->getContent()); } /** @@ -400,7 +401,7 @@ public function testPhp7ErrorRaisedInDispatchableShouldRaiseDispatchErrorEvent() }); $this->application->run(); - $this->assertContains('Raised an error', $response->getContent()); + $this->assertStringContainsString('Raised an error', $response->getContent()); } /** @@ -483,7 +484,7 @@ public function testApplicationShouldBeEventTargetAtFinishEvent() }); $application->run(); - $this->assertContains(Application::class, $response->getContent()); + $this->assertStringContainsString(Application::class, $response->getContent()); } public function testOnDispatchErrorEventPassedToTriggersShouldBeTheOriginalOne() diff --git a/test/Controller/AbstractControllerTest.php b/test/Controller/AbstractControllerTest.php index 5c489f25a..8ac0fcac5 100644 --- a/test/Controller/AbstractControllerTest.php +++ b/test/Controller/AbstractControllerTest.php @@ -14,6 +14,7 @@ use Laminas\Mvc\InjectApplicationEventInterface; use Laminas\Stdlib\DispatchableInterface; use LaminasTest\Mvc\Controller\TestAsset\AbstractControllerStub; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -30,7 +31,7 @@ class AbstractControllerTest extends TestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { $this->controller = new AbstractControllerStub(); } @@ -40,13 +41,13 @@ protected function setUp() */ public function testSetEventManagerWithDefaultIdentifiers() { - /* @var $eventManager EventManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ + /* @var $eventManager EventManagerInterface&MockObject */ $eventManager = $this->createMock(EventManagerInterface::class); $eventManager ->expects($this->once()) ->method('setIdentifiers') - ->with($this->logicalNot($this->contains('customEventIdentifier'))); + ->with($this->logicalNot($this->containsIdentical('customEventIdentifier'))); $this->controller->setEventManager($eventManager); } @@ -56,10 +57,13 @@ public function testSetEventManagerWithDefaultIdentifiers() */ public function testSetEventManagerWithCustomStringIdentifier() { - /* @var $eventManager EventManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ + /* @var $eventManager EventManagerInterface&MockObject */ $eventManager = $this->createMock(EventManagerInterface::class); - $eventManager->expects($this->once())->method('setIdentifiers')->with($this->contains('customEventIdentifier')); + $eventManager + ->expects($this->once()) + ->method('setIdentifiers') + ->with($this->containsIdentical('customEventIdentifier')); $reflection = new ReflectionProperty($this->controller, 'eventIdentifier'); @@ -74,12 +78,12 @@ public function testSetEventManagerWithCustomStringIdentifier() */ public function testSetEventManagerWithMultipleCustomStringIdentifier() { - /* @var $eventManager EventManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ + /* @var $eventManager EventManagerInterface&MockObject */ $eventManager = $this->createMock(EventManagerInterface::class); $eventManager->expects($this->once())->method('setIdentifiers')->with($this->logicalAnd( - $this->contains('customEventIdentifier1'), - $this->contains('customEventIdentifier2') + $this->containsIdentical('customEventIdentifier1'), + $this->containsIdentical('customEventIdentifier2') )); $reflection = new ReflectionProperty($this->controller, 'eventIdentifier'); @@ -95,16 +99,16 @@ public function testSetEventManagerWithMultipleCustomStringIdentifier() */ public function testSetEventManagerWithDefaultIdentifiersIncludesImplementedInterfaces() { - /* @var $eventManager EventManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ + /* @var $eventManager EventManagerInterface&MockObject */ $eventManager = $this->createMock(EventManagerInterface::class); $eventManager ->expects($this->once()) ->method('setIdentifiers') ->with($this->logicalAnd( - $this->contains(EventManagerAwareInterface::class), - $this->contains(DispatchableInterface::class), - $this->contains(InjectApplicationEventInterface::class) + $this->containsIdentical(EventManagerAwareInterface::class), + $this->containsIdentical(DispatchableInterface::class), + $this->containsIdentical(InjectApplicationEventInterface::class) )); $this->controller->setEventManager($eventManager); @@ -112,17 +116,17 @@ public function testSetEventManagerWithDefaultIdentifiersIncludesImplementedInte public function testSetEventManagerWithDefaultIdentifiersIncludesExtendingClassNameAndNamespace() { - /* @var $eventManager EventManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ + /* @var $eventManager EventManagerInterface&MockObject */ $eventManager = $this->createMock(EventManagerInterface::class); $eventManager ->expects($this->once()) ->method('setIdentifiers') ->with($this->logicalAnd( - $this->contains(AbstractController::class), - $this->contains(AbstractControllerStub::class), - $this->contains('LaminasTest'), - $this->contains('LaminasTest\\Mvc\\Controller\\TestAsset') + $this->containsIdentical(AbstractController::class), + $this->containsIdentical(AbstractControllerStub::class), + $this->containsIdentical('LaminasTest'), + $this->containsIdentical('LaminasTest\\Mvc\\Controller\\TestAsset') )); $this->controller->setEventManager($eventManager); diff --git a/test/Controller/ActionControllerTest.php b/test/Controller/ActionControllerTest.php index 9e8cf68db..e7ec1c9f2 100644 --- a/test/Controller/ActionControllerTest.php +++ b/test/Controller/ActionControllerTest.php @@ -32,8 +32,9 @@ class ActionControllerTest extends TestCase public $event; public $request; public $response; + private $routeMatch; - public function setUp() + protected function setUp() : void { $this->controller = new SampleController(); $this->request = new Request(); @@ -66,7 +67,7 @@ public function testDispatchInvokesNotFoundActionWhenNoActionPresentInRouteMatch $this->assertEquals('content', $result->captureTo()); $vars = $result->getVariables(); $this->assertArrayHasKey('content', $vars, var_export($vars, 1)); - $this->assertContains('Page not found', $vars['content']); + $this->assertStringContainsString('Page not found', $vars['content']); } public function testDispatchInvokesNotFoundActionWhenInvalidActionPresentInRouteMatch() @@ -79,7 +80,7 @@ public function testDispatchInvokesNotFoundActionWhenInvalidActionPresentInRoute $this->assertEquals('content', $result->captureTo()); $vars = $result->getVariables(); $this->assertArrayHasKey('content', $vars, var_export($vars, 1)); - $this->assertContains('Page not found', $vars['content']); + $this->assertStringContainsString('Page not found', $vars['content']); } public function testDispatchInvokesProvidedActionWhenMethodExists() @@ -87,7 +88,7 @@ public function testDispatchInvokesProvidedActionWhenMethodExists() $this->routeMatch->setParam('action', 'test'); $result = $this->controller->dispatch($this->request, $this->response); $this->assertTrue(isset($result['content'])); - $this->assertContains('test', $result['content']); + $this->assertStringContainsString('test', $result['content']); } public function testDispatchCallsActionMethodBasedOnNormalizingAction() @@ -95,7 +96,7 @@ public function testDispatchCallsActionMethodBasedOnNormalizingAction() $this->routeMatch->setParam('action', 'test.some-strangely_separated.words'); $result = $this->controller->dispatch($this->request, $this->response); $this->assertTrue(isset($result['content'])); - $this->assertContains('Test Some Strangely Separated Words', $result['content']); + $this->assertStringContainsString('Test Some Strangely Separated Words', $result['content']); } public function testShortCircuitsBeforeActionIfPreDispatchReturnsAResponse() diff --git a/test/Controller/ControllerManagerTest.php b/test/Controller/ControllerManagerTest.php index 72f48263a..f4edd4922 100644 --- a/test/Controller/ControllerManagerTest.php +++ b/test/Controller/ControllerManagerTest.php @@ -22,7 +22,7 @@ class ControllerManagerTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->sharedEvents = new SharedEventManager; $this->events = $this->createEventManager($this->sharedEvents); @@ -88,8 +88,8 @@ public function testInjectEventManagerWillNotOverwriteExistingEventManagerIfItAl } /** - * @covers Laminas\ServiceManager\ServiceManager::has - * @covers Laminas\ServiceManager\AbstractPluginManager::get + * @covers \Laminas\ServiceManager\ServiceManager::has + * @covers \Laminas\ServiceManager\AbstractPluginManager::get */ public function testDoNotUsePeeringServiceManagers() { diff --git a/test/Controller/IntegrationTest.php b/test/Controller/IntegrationTest.php index cb0121074..adf5d0700 100644 --- a/test/Controller/IntegrationTest.php +++ b/test/Controller/IntegrationTest.php @@ -18,7 +18,7 @@ class IntegrationTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->sharedEvents = new SharedEventManager(); diff --git a/test/Controller/LazyControllerAbstractFactoryTest.php b/test/Controller/LazyControllerAbstractFactoryTest.php index b8e2b1a45..012fd6b1b 100644 --- a/test/Controller/LazyControllerAbstractFactoryTest.php +++ b/test/Controller/LazyControllerAbstractFactoryTest.php @@ -13,10 +13,13 @@ use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Laminas\Validator\ValidatorPluginManager; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class LazyControllerAbstractFactoryTest extends TestCase { - public function setUp() + use ProphecyTrait; + + protected function setUp() : void { $this->container = $this->prophesize(ContainerInterface::class); } diff --git a/test/Controller/MiddlewareControllerTest.php b/test/Controller/MiddlewareControllerTest.php index 726dafbed..b81eec574 100644 --- a/test/Controller/MiddlewareControllerTest.php +++ b/test/Controller/MiddlewareControllerTest.php @@ -55,7 +55,7 @@ class MiddlewareControllerTest extends TestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { $this->pipe = $this->createMock(MiddlewarePipe::class); $this->responsePrototype = $this->createMock(ResponseInterface::class); diff --git a/test/Controller/Plugin/AcceptableViewModelSelectorTest.php b/test/Controller/Plugin/AcceptableViewModelSelectorTest.php index ed39e60b2..dd4f45147 100644 --- a/test/Controller/Plugin/AcceptableViewModelSelectorTest.php +++ b/test/Controller/Plugin/AcceptableViewModelSelectorTest.php @@ -19,7 +19,7 @@ class AcceptableViewModelSelectorTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->request = new Request(); diff --git a/test/Controller/Plugin/ForwardTest.php b/test/Controller/Plugin/ForwardTest.php index 84008d910..566679853 100644 --- a/test/Controller/Plugin/ForwardTest.php +++ b/test/Controller/Plugin/ForwardTest.php @@ -54,7 +54,7 @@ class ForwardTest extends TestCase */ private $plugin; - public function setUp() + protected function setUp() : void { $eventManager = $this->createEventManager(new SharedEventManager()); $mockApplication = $this->createMock(ApplicationInterface::class); @@ -207,7 +207,7 @@ public function testDispatchRaisesDomainExceptionIfCircular() public function testPluginDispatchsRequestedControllerWhenFound() { $result = $this->plugin->dispatch('forward'); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals( ['content' => 'LaminasTest\Mvc\Controller\TestAsset\ForwardController::testAction'], $result @@ -234,7 +234,7 @@ function ($e) {} $event->setApplication($application); $result = $this->plugin->dispatch('forward'); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals( ['content' => 'LaminasTest\Mvc\Controller\TestAsset\ForwardController::testAction'], $result @@ -313,7 +313,7 @@ public function testDispatchWillSeedRouteMatchWithPassedParameters() 'action' => 'test-matches', 'param1' => 'foobar', ]); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertTrue(isset($result['action'])); $this->assertEquals('test-matches', $result['action']); $this->assertTrue(isset($result['param1'])); @@ -341,7 +341,7 @@ public function testRouteMatchObjectRemainsSameFollowingForwardDispatch() public function testAllowsPassingEmptyArrayOfRouteParams() { $result = $this->plugin->dispatch('forward', []); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertTrue(isset($result['status'])); $this->assertEquals('not-found', $result['status']); $this->assertTrue(isset($result['params'])); diff --git a/test/Controller/Plugin/LayoutTest.php b/test/Controller/Plugin/LayoutTest.php index 5a3a51492..a4215886b 100644 --- a/test/Controller/Plugin/LayoutTest.php +++ b/test/Controller/Plugin/LayoutTest.php @@ -17,7 +17,7 @@ class LayoutTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->event = $event = new MvcEvent(); $this->controller = new SampleController(); diff --git a/test/Controller/Plugin/ParamsTest.php b/test/Controller/Plugin/ParamsTest.php index c174bc775..901545e9f 100644 --- a/test/Controller/Plugin/ParamsTest.php +++ b/test/Controller/Plugin/ParamsTest.php @@ -18,7 +18,7 @@ class ParamsTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->request = new Request; $event = new MvcEvent; diff --git a/test/Controller/Plugin/RedirectTest.php b/test/Controller/Plugin/RedirectTest.php index d53a98787..6b7902b14 100644 --- a/test/Controller/Plugin/RedirectTest.php +++ b/test/Controller/Plugin/RedirectTest.php @@ -22,7 +22,7 @@ class RedirectTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->response = new Response(); diff --git a/test/Controller/Plugin/UrlTest.php b/test/Controller/Plugin/UrlTest.php index ffbbb3870..4248c8a55 100644 --- a/test/Controller/Plugin/UrlTest.php +++ b/test/Controller/Plugin/UrlTest.php @@ -25,7 +25,7 @@ class UrlTest extends TestCase { - public function setUp() + protected function setUp() : void { $router = new SimpleRouteStack; $router->addRoute('home', LiteralRoute::factory([ diff --git a/test/Controller/RestfulControllerTest.php b/test/Controller/RestfulControllerTest.php index 7dea4710e..06b6ef121 100644 --- a/test/Controller/RestfulControllerTest.php +++ b/test/Controller/RestfulControllerTest.php @@ -23,11 +23,14 @@ use LaminasTest\Mvc\Controller\TestAsset\RestfulMethodNotAllowedTestController; use LaminasTest\Mvc\Controller\TestAsset\RestfulTestController; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use ReflectionObject; use stdClass; class RestfulControllerTest extends TestCase { + use ProphecyTrait; + public $controller; public $emptyController; public $request; @@ -35,7 +38,7 @@ class RestfulControllerTest extends TestCase public $routeMatch; public $event; - public function setUp() + protected function setUp() : void { $this->controller = new RestfulTestController(); $this->emptyController = new RestfulMethodNotAllowedTestController(); @@ -290,7 +293,7 @@ public function testAllowsRegisteringCustomHttpMethodsWithHandlers() $this->request->setMethod('DESCRIBE'); $result = $this->controller->dispatch($this->request, $this->response); $this->assertArrayHasKey('description', $result); - $this->assertContains('::describe', $result['description']); + $this->assertStringContainsString('::describe', $result['description']); } public function testDispatchCallsActionMethodBasedOnNormalizingAction() @@ -298,7 +301,7 @@ public function testDispatchCallsActionMethodBasedOnNormalizingAction() $this->routeMatch->setParam('action', 'test.some-strangely_separated.words'); $result = $this->controller->dispatch($this->request, $this->response); $this->assertArrayHasKey('content', $result); - $this->assertContains('Test Some Strangely Separated Words', $result['content']); + $this->assertStringContainsString('Test Some Strangely Separated Words', $result['content']); } public function testDispatchCallsNotFoundActionWhenActionPassedThatCannotBeMatched() @@ -308,7 +311,7 @@ public function testDispatchCallsNotFoundActionWhenActionPassedThatCannotBeMatch $response = $this->controller->getResponse(); $this->assertEquals(404, $response->getStatusCode()); $this->assertArrayHasKey('content', $result); - $this->assertContains('Page not found', $result['content']); + $this->assertStringContainsString('Page not found', $result['content']); } public function testShortCircuitsBeforeActionIfPreDispatchReturnsAResponse() @@ -419,7 +422,7 @@ public function testParsingDataAsJsonWillReturnAsArray() $this->request->setContent('{"foo":"bar"}'); $result = $this->controller->dispatch($this->request, $this->response); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals(['entity' => ['foo' => 'bar']], $result); } diff --git a/test/DispatchListenerTest.php b/test/DispatchListenerTest.php index f2f5861da..4d18d0f03 100644 --- a/test/DispatchListenerTest.php +++ b/test/DispatchListenerTest.php @@ -20,9 +20,12 @@ use Laminas\Stdlib\ResponseInterface; use Laminas\View\Model\ModelInterface; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class DispatchListenerTest extends TestCase { + use ProphecyTrait; + public function createMvcEvent($controllerMatched) { $response = new Response(); diff --git a/test/HttpMethodListenerTest.php b/test/HttpMethodListenerTest.php index 6d19100e4..a98be992f 100644 --- a/test/HttpMethodListenerTest.php +++ b/test/HttpMethodListenerTest.php @@ -18,7 +18,7 @@ use PHPUnit\Framework\TestCase; /** - * @covers Laminas\Mvc\HttpMethodListener + * @covers \Laminas\Mvc\HttpMethodListener */ class HttpMethodListenerTest extends TestCase { @@ -27,7 +27,7 @@ class HttpMethodListenerTest extends TestCase */ protected $listener; - public function setUp() + protected function setUp() : void { $this->listener = new HttpMethodListener(); } diff --git a/test/MiddlewareListenerTest.php b/test/MiddlewareListenerTest.php index 26a4aeaa3..c0121094a 100644 --- a/test/MiddlewareListenerTest.php +++ b/test/MiddlewareListenerTest.php @@ -26,11 +26,14 @@ use Laminas\Stdlib\DispatchableInterface; use Laminas\View\Model\ModelInterface; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; class MiddlewareListenerTest extends TestCase { + use ProphecyTrait; + /** * @var \Prophecy\Prophecy\ObjectProphecy */ diff --git a/test/ModuleRouteListenerTest.php b/test/ModuleRouteListenerTest.php index fbba46c8d..07934abdf 100644 --- a/test/ModuleRouteListenerTest.php +++ b/test/ModuleRouteListenerTest.php @@ -19,7 +19,7 @@ class ModuleRouteListenerTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->request = new Request(); $this->events = new EventManager(); diff --git a/test/Service/ControllerManagerFactoryTest.php b/test/Service/ControllerManagerFactoryTest.php index a646cf94b..cc84c0568 100644 --- a/test/Service/ControllerManagerFactoryTest.php +++ b/test/Service/ControllerManagerFactoryTest.php @@ -33,7 +33,7 @@ class ControllerManagerFactoryTest extends TestCase */ protected $loader; - public function setUp() + protected function setUp() : void { $loaderFactory = new ControllerManagerFactory(); $this->defaultServiceConfig = [ @@ -66,7 +66,7 @@ public function testCannotLoadInvalidDispatchable() $this->fail('Retrieving the invalid dispatchable should fail'); } catch (\Exception $e) { do { - $this->assertNotContains('Should not instantiate this', $e->getMessage()); + $this->assertStringNotContainsString('Should not instantiate this', $e->getMessage()); } while ($e = $e->getPrevious()); } } diff --git a/test/Service/HttpMethodListenerFactoryTest.php b/test/Service/HttpMethodListenerFactoryTest.php index 2d20fab85..d1656924d 100644 --- a/test/Service/HttpMethodListenerFactoryTest.php +++ b/test/Service/HttpMethodListenerFactoryTest.php @@ -11,20 +11,23 @@ use Interop\Container\ContainerInterface; use Laminas\Mvc\Service\HttpMethodListenerFactory; use Laminas\ServiceManager\ServiceLocatorInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject as MockObject; +use Prophecy\PhpUnit\ProphecyTrait; /** - * @covers Laminas\Mvc\Service\HttpMethodListenerFactory + * @covers \Laminas\Mvc\Service\HttpMethodListenerFactory */ class HttpMethodListenerFactoryTest extends TestCase { + use ProphecyTrait; + /** - * @var ServiceLocatorInterface|MockObject + * @var ServiceLocatorInterface&MockObject */ protected $serviceLocator; - public function setUp() + protected function setUp() : void { $this->serviceLocator = $this->prophesize(ServiceLocatorInterface::class); $this->serviceLocator->willImplement(ContainerInterface::class); diff --git a/test/Service/InjectTemplateListenerFactoryTest.php b/test/Service/InjectTemplateListenerFactoryTest.php index 11c56628f..3f6487d61 100644 --- a/test/Service/InjectTemplateListenerFactoryTest.php +++ b/test/Service/InjectTemplateListenerFactoryTest.php @@ -14,6 +14,7 @@ use Laminas\Mvc\View\Http\InjectTemplateListener; use Laminas\ServiceManager\ServiceLocatorInterface; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; /** * Tests for {@see \Laminas\Mvc\Service\InjectTemplateListenerFactory} @@ -22,6 +23,8 @@ */ class InjectTemplateListenerFactoryTest extends TestCase { + use ProphecyTrait; + public function testFactoryCanCreateInjectTemplateListener() { $this->buildInjectTemplateListenerWithConfig([]); diff --git a/test/Service/RequestFactoryTest.php b/test/Service/RequestFactoryTest.php index 4b13b7573..0869d3471 100644 --- a/test/Service/RequestFactoryTest.php +++ b/test/Service/RequestFactoryTest.php @@ -12,9 +12,12 @@ use Laminas\Http\Request as HttpRequest; use Laminas\Mvc\Service\RequestFactory; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class RequestFactoryTest extends TestCase { + use ProphecyTrait; + public function testFactoryCreatesHttpRequest() { $factory = new RequestFactory(); diff --git a/test/Service/ResponseFactoryTest.php b/test/Service/ResponseFactoryTest.php index 11523ecae..9ad004758 100644 --- a/test/Service/ResponseFactoryTest.php +++ b/test/Service/ResponseFactoryTest.php @@ -12,9 +12,12 @@ use Laminas\Http\Response as HttpResponse; use Laminas\Mvc\Service\ResponseFactory; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class ResponseFactoryTest extends TestCase { + use ProphecyTrait; + public function testFactoryCreatesHttpResponse() { $factory = new ResponseFactory(); diff --git a/test/Service/SendResponseListenerFactoryTest.php b/test/Service/SendResponseListenerFactoryTest.php index c0c48a7d0..82591b77a 100644 --- a/test/Service/SendResponseListenerFactoryTest.php +++ b/test/Service/SendResponseListenerFactoryTest.php @@ -19,9 +19,12 @@ use Laminas\Mvc\Service\SendResponseListenerFactory; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; class SendResponseListenerFactoryTest extends TestCase { + use ProphecyTrait; + public function testFactoryReturnsListenerWithEventManagerFromContainer() { $sharedEvents = $this->prophesize(SharedEventManagerInterface::class); diff --git a/test/Service/ServiceListenerFactoryTest.php b/test/Service/ServiceListenerFactoryTest.php index 9184e720c..a87f510b4 100644 --- a/test/Service/ServiceListenerFactoryTest.php +++ b/test/Service/ServiceListenerFactoryTest.php @@ -9,12 +9,13 @@ namespace LaminasTest\Mvc\Service; use Laminas\Mvc\Service\ServiceListenerFactory; +use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\ServiceManager; use PHPUnit\Framework\TestCase; class ServiceListenerFactoryTest extends TestCase { - public function setUp() + protected function setUp() : void { $sm = $this->sm = $this->getMockBuilder(ServiceManager::class) ->setMethods(['get']) @@ -23,12 +24,10 @@ public function setUp() $this->factory = new ServiceListenerFactory(); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage The value of service_listener_options must be an array, string given. - */ public function testInvalidOptionType() { + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage('The value of service_listener_options must be an array, string given.'); $this->sm->expects($this->once()) ->method('get') ->will($this->returnValue(['service_listener_options' => 'string'])); @@ -36,12 +35,12 @@ public function testInvalidOptionType() $this->factory->__invoke($this->sm, 'ServiceListener'); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, 0 array must contain service_manager key. - */ public function testMissingServiceManager() { + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, 0 array must contain service_manager key.' + ); $config['service_listener_options'][0]['service_manager'] = null; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 'test'; @@ -54,13 +53,14 @@ public function testMissingServiceManager() $this->factory->__invoke($this->sm, 'ServiceListener'); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, service_manager must be a string, - * integer given. - */ public function testInvalidTypeServiceManager() { + $this->expectException( + ServiceNotCreatedException::class + ); + $this->expectExceptionMessage( + 'Invalid service listener options detected, service_manager must be a string, integer given.' + ); $config['service_listener_options'][0]['service_manager'] = 1; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 'test'; @@ -73,12 +73,12 @@ public function testInvalidTypeServiceManager() $this->factory->__invoke($this->sm, 'ServiceListener'); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, 0 array must contain config_key key. - */ public function testMissingConfigKey() { + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, 0 array must contain config_key key.' + ); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = null; $config['service_listener_options'][0]['interface'] = 'test'; @@ -91,12 +91,12 @@ public function testMissingConfigKey() $this->factory->__invoke($this->sm, 'ServiceListener'); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, config_key must be a string, integer given. - */ public function testInvalidTypeConfigKey() { + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, config_key must be a string, integer given.' + ); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 1; $config['service_listener_options'][0]['interface'] = 'test'; @@ -109,12 +109,10 @@ public function testInvalidTypeConfigKey() $this->factory->__invoke($this->sm, 'ServiceListener'); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, 0 array must contain interface key. - */ public function testMissingInterface() { + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage('Invalid service listener options detected, 0 array must contain interface key.'); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = null; @@ -127,12 +125,12 @@ public function testMissingInterface() $this->factory->__invoke($this->sm, 'ServiceListener'); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, interface must be a string, integer given. - */ public function testInvalidTypeInterface() { + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, interface must be a string, integer given.' + ); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 1; @@ -145,12 +143,10 @@ public function testInvalidTypeInterface() $this->factory->__invoke($this->sm, 'ServiceListener'); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, 0 array must contain method key. - */ public function testMissingMethod() { + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage('Invalid service listener options detected, 0 array must contain method key.'); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 'test'; @@ -163,12 +159,12 @@ public function testMissingMethod() $this->factory->__invoke($this->sm, 'ServiceListener'); } - /** - * @expectedException Laminas\ServiceManager\Exception\ServiceNotCreatedException - * @expectedExceptionMessage Invalid service listener options detected, method must be a string, integer given. - */ public function testInvalidTypeMethod() { + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, method must be a string, integer given.' + ); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 'test'; diff --git a/test/Service/ServiceManagerConfigTest.php b/test/Service/ServiceManagerConfigTest.php index d2f92234b..9b62b829e 100644 --- a/test/Service/ServiceManagerConfigTest.php +++ b/test/Service/ServiceManagerConfigTest.php @@ -36,7 +36,7 @@ class ServiceManagerConfigTest extends TestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { $this->config = new ServiceManagerConfig(); $this->services = new ServiceManager(); diff --git a/test/Service/ViewFeedStrategyFactoryTest.php b/test/Service/ViewFeedStrategyFactoryTest.php index c2ec6fce2..ec5df0185 100644 --- a/test/Service/ViewFeedStrategyFactoryTest.php +++ b/test/Service/ViewFeedStrategyFactoryTest.php @@ -13,9 +13,12 @@ use Laminas\View\Renderer\FeedRenderer; use Laminas\View\Strategy\FeedStrategy; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class ViewFeedStrategyFactoryTest extends TestCase { + use ProphecyTrait; + private function createContainer() { $renderer = $this->prophesize(FeedRenderer::class); diff --git a/test/Service/ViewHelperManagerFactoryTest.php b/test/Service/ViewHelperManagerFactoryTest.php index 2a00ab6b1..4064d3d1d 100644 --- a/test/Service/ViewHelperManagerFactoryTest.php +++ b/test/Service/ViewHelperManagerFactoryTest.php @@ -21,7 +21,7 @@ class ViewHelperManagerFactoryTest extends TestCase { - public function setUp() + protected function setUp() : void { $this->services = new ServiceManager(); $this->factory = new ViewHelperManagerFactory(); diff --git a/test/Service/ViewJsonStrategyFactoryTest.php b/test/Service/ViewJsonStrategyFactoryTest.php index e7cf3ff2b..270131080 100644 --- a/test/Service/ViewJsonStrategyFactoryTest.php +++ b/test/Service/ViewJsonStrategyFactoryTest.php @@ -13,9 +13,12 @@ use Laminas\View\Renderer\JsonRenderer; use Laminas\View\Strategy\JsonStrategy; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class ViewJsonStrategyFactoryTest extends TestCase { + use ProphecyTrait; + private function createContainer() { $renderer = $this->prophesize(JsonRenderer::class); diff --git a/test/Service/ViewManagerFactoryTest.php b/test/Service/ViewManagerFactoryTest.php index 804560217..04e1be7f7 100644 --- a/test/Service/ViewManagerFactoryTest.php +++ b/test/Service/ViewManagerFactoryTest.php @@ -12,9 +12,12 @@ use Laminas\Mvc\Service\ViewManagerFactory; use Laminas\Mvc\View\Http\ViewManager as HttpViewManager; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class ViewManagerFactoryTest extends TestCase { + use ProphecyTrait; + private function createContainer() { $http = $this->prophesize(HttpViewManager::class); diff --git a/test/Service/ViewPrefixPathStackResolverFactoryTest.php b/test/Service/ViewPrefixPathStackResolverFactoryTest.php index 8314f3579..f8db763b8 100644 --- a/test/Service/ViewPrefixPathStackResolverFactoryTest.php +++ b/test/Service/ViewPrefixPathStackResolverFactoryTest.php @@ -13,9 +13,12 @@ use Laminas\ServiceManager\ServiceLocatorInterface; use Laminas\View\Resolver\PrefixPathStackResolver; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class ViewPrefixPathStackResolverFactoryTest extends TestCase { + use ProphecyTrait; + public function testCreateService() { $serviceLocator = $this->prophesize(ServiceLocatorInterface::class); diff --git a/test/View/CreateViewModelListenerTest.php b/test/View/CreateViewModelListenerTest.php index bcd20d22b..fb4eacce8 100644 --- a/test/View/CreateViewModelListenerTest.php +++ b/test/View/CreateViewModelListenerTest.php @@ -20,7 +20,7 @@ class CreateViewModelListenerTest extends TestCase { use EventListenerIntrospectionTrait; - public function setUp() + protected function setUp() : void { $this->listener = new CreateViewModelListener(); $this->event = new MvcEvent(); diff --git a/test/View/DefaultRendereringStrategyTest.php b/test/View/DefaultRendereringStrategyTest.php index 8dac04719..e4b2c4a06 100644 --- a/test/View/DefaultRendereringStrategyTest.php +++ b/test/View/DefaultRendereringStrategyTest.php @@ -36,7 +36,7 @@ class DefaultRendereringStrategyTest extends TestCase protected $renderer; protected $strategy; - public function setUp() + protected function setUp() : void { $this->view = new View(); $this->request = new Request(); @@ -170,6 +170,6 @@ public function testTriggersRenderErrorEventInCaseOfRenderingException() $this->assertTrue($test->flag); $this->assertEquals(Application::ERROR_EXCEPTION, $test->error); $this->assertInstanceOf('Exception', $test->exception); - $this->assertContains('script', $test->exception->getMessage()); + $this->assertStringContainsString('script', $test->exception->getMessage()); } } diff --git a/test/View/ExceptionStrategyTest.php b/test/View/ExceptionStrategyTest.php index a45e09a03..187dd4216 100644 --- a/test/View/ExceptionStrategyTest.php +++ b/test/View/ExceptionStrategyTest.php @@ -21,7 +21,7 @@ class ExceptionStrategyTest extends TestCase { use EventListenerIntrospectionTrait; - public function setUp() + protected function setUp() : void { $this->strategy = new ExceptionStrategy(); } @@ -88,7 +88,7 @@ public function testCatchesApplicationExceptions() $variables = $model->getVariables(); $this->assertArrayHasKey('message', $variables); - $this->assertContains('error occurred', $variables['message']); + $this->assertStringContainsString('error occurred', $variables['message']); $this->assertArrayHasKey('exception', $variables); $this->assertSame($exception, $variables['exception']); $this->assertArrayHasKey('display_exceptions', $variables); diff --git a/test/View/InjectTemplateListenerTest.php b/test/View/InjectTemplateListenerTest.php index 8ca2e8d99..01865b45f 100644 --- a/test/View/InjectTemplateListenerTest.php +++ b/test/View/InjectTemplateListenerTest.php @@ -22,7 +22,7 @@ class InjectTemplateListenerTest extends TestCase { use EventListenerIntrospectionTrait; - public function setUp() + protected function setUp() : void { $controllerMap = [ 'MappedNs' => true, diff --git a/test/View/InjectViewModelListenerTest.php b/test/View/InjectViewModelListenerTest.php index 629727a86..fe7bac087 100644 --- a/test/View/InjectViewModelListenerTest.php +++ b/test/View/InjectViewModelListenerTest.php @@ -20,7 +20,7 @@ class InjectViewModelListenerTest extends TestCase { use EventListenerIntrospectionTrait; - public function setUp() + protected function setUp() : void { $this->listener = new InjectViewModelListener(); $this->event = new MvcEvent(); diff --git a/test/View/RouteNotFoundStrategyTest.php b/test/View/RouteNotFoundStrategyTest.php index 0f485b534..8c5137b56 100644 --- a/test/View/RouteNotFoundStrategyTest.php +++ b/test/View/RouteNotFoundStrategyTest.php @@ -27,7 +27,7 @@ class RouteNotFoundStrategyTest extends TestCase */ private $strategy; - public function setUp() + protected function setUp() : void { $this->strategy = new RouteNotFoundStrategy(); } From bd2ebf9af86b0a361f29a9bd6745440bde174c91 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sun, 3 May 2020 19:56:06 +1000 Subject: [PATCH 4/9] Drop replace for zend-mvc Signed-off-by: Aleksei Khudiakov --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index d6e233d22..17d93c2d4 100644 --- a/composer.json +++ b/composer.json @@ -81,8 +81,5 @@ "cs-fix": "phpcbf", "test": "phpunit --colors=always", "test-coverage": "phpunit --colors=always --coverage-clover clover.xml" - }, - "replace": { - "zendframework/zend-mvc": "^3.1.1" } } From e0409e40523d784e4ba32b4b0b6125f155e8d74c Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Tue, 9 Jun 2020 15:24:56 +1000 Subject: [PATCH 5/9] Bump dependencies to ensure php 7.4 compatible versions are used Signed-off-by: Aleksei Khudiakov --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 17d93c2d4..0a0dc8ec8 100644 --- a/composer.json +++ b/composer.json @@ -27,19 +27,19 @@ "require": { "php": "^7.3", "laminas/laminas-eventmanager": "^3.2", - "laminas/laminas-http": "^2.7", - "laminas/laminas-modulemanager": "^2.8", - "laminas/laminas-router": "^3.0.2", - "laminas/laminas-servicemanager": "^3.3", + "laminas/laminas-http": "^2.11.2", + "laminas/laminas-modulemanager": "^2.8.2", + "laminas/laminas-router": "^3.3.2", + "laminas/laminas-servicemanager": "^3.4.1", "laminas/laminas-stdlib": "^3.2.1", - "laminas/laminas-view": "^2.9", + "laminas/laminas-view": "^2.11.4", "psr/container": "^1.0" }, "require-dev": { "http-interop/http-middleware": "^0.4.1", "laminas/laminas-coding-standard": "~1.0.0", "laminas/laminas-json": "^2.6.1 || ^3.0", - "laminas/laminas-psr7bridge": "^1.0", + "laminas/laminas-psr7bridge": "^1.2.2", "laminas/laminas-stratigility": ">=2.0.1 <2.2", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.1.4" From 94d12fd53c13d5d7c3d5a2ba418ff24922ec5ffb Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Tue, 9 Jun 2020 17:16:22 +1000 Subject: [PATCH 6/9] Fix typo in test case name Signed-off-by: Aleksei Khudiakov --- .../InvalidControllerTypeShouldTriggerDispatchErrorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php index b13594582..3e99cc6be 100644 --- a/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php +++ b/test/Application/InvalidControllerTypeShouldTriggerDispatchErrorTest.php @@ -12,7 +12,7 @@ use Laminas\Mvc\MvcEvent; use PHPUnit\Framework\TestCase; -class InvalidControllerTypeShouldTrigerDispatchErrorTest extends TestCase +class InvalidControllerTypeShouldTriggerDispatchErrorTest extends TestCase { use InvalidControllerTypeTrait; From 3684abb32ebe3145f334e1b71e5237e46e1c4816 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Tue, 9 Jun 2020 17:28:14 +1000 Subject: [PATCH 7/9] Move exception expectations to the call expected to throw Signed-off-by: Aleksei Khudiakov --- test/Service/ServiceListenerFactoryTest.php | 64 ++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/test/Service/ServiceListenerFactoryTest.php b/test/Service/ServiceListenerFactoryTest.php index a87f510b4..d6bfe7ab2 100644 --- a/test/Service/ServiceListenerFactoryTest.php +++ b/test/Service/ServiceListenerFactoryTest.php @@ -26,21 +26,17 @@ protected function setUp() : void public function testInvalidOptionType() { - $this->expectException(ServiceNotCreatedException::class); - $this->expectExceptionMessage('The value of service_listener_options must be an array, string given.'); $this->sm->expects($this->once()) ->method('get') ->will($this->returnValue(['service_listener_options' => 'string'])); + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage('The value of service_listener_options must be an array, string given.'); $this->factory->__invoke($this->sm, 'ServiceListener'); } public function testMissingServiceManager() { - $this->expectException(ServiceNotCreatedException::class); - $this->expectExceptionMessage( - 'Invalid service listener options detected, 0 array must contain service_manager key.' - ); $config['service_listener_options'][0]['service_manager'] = null; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 'test'; @@ -50,17 +46,15 @@ public function testMissingServiceManager() ->method('get') ->will($this->returnValue($config)); + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, 0 array must contain service_manager key.' + ); $this->factory->__invoke($this->sm, 'ServiceListener'); } public function testInvalidTypeServiceManager() { - $this->expectException( - ServiceNotCreatedException::class - ); - $this->expectExceptionMessage( - 'Invalid service listener options detected, service_manager must be a string, integer given.' - ); $config['service_listener_options'][0]['service_manager'] = 1; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 'test'; @@ -70,15 +64,17 @@ public function testInvalidTypeServiceManager() ->method('get') ->will($this->returnValue($config)); + $this->expectException( + ServiceNotCreatedException::class + ); + $this->expectExceptionMessage( + 'Invalid service listener options detected, service_manager must be a string, integer given.' + ); $this->factory->__invoke($this->sm, 'ServiceListener'); } public function testMissingConfigKey() { - $this->expectException(ServiceNotCreatedException::class); - $this->expectExceptionMessage( - 'Invalid service listener options detected, 0 array must contain config_key key.' - ); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = null; $config['service_listener_options'][0]['interface'] = 'test'; @@ -88,15 +84,15 @@ public function testMissingConfigKey() ->method('get') ->will($this->returnValue($config)); + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, 0 array must contain config_key key.' + ); $this->factory->__invoke($this->sm, 'ServiceListener'); } public function testInvalidTypeConfigKey() { - $this->expectException(ServiceNotCreatedException::class); - $this->expectExceptionMessage( - 'Invalid service listener options detected, config_key must be a string, integer given.' - ); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 1; $config['service_listener_options'][0]['interface'] = 'test'; @@ -106,13 +102,15 @@ public function testInvalidTypeConfigKey() ->method('get') ->will($this->returnValue($config)); + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, config_key must be a string, integer given.' + ); $this->factory->__invoke($this->sm, 'ServiceListener'); } public function testMissingInterface() { - $this->expectException(ServiceNotCreatedException::class); - $this->expectExceptionMessage('Invalid service listener options detected, 0 array must contain interface key.'); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = null; @@ -122,15 +120,13 @@ public function testMissingInterface() ->method('get') ->will($this->returnValue($config)); + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage('Invalid service listener options detected, 0 array must contain interface key.'); $this->factory->__invoke($this->sm, 'ServiceListener'); } public function testInvalidTypeInterface() { - $this->expectException(ServiceNotCreatedException::class); - $this->expectExceptionMessage( - 'Invalid service listener options detected, interface must be a string, integer given.' - ); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 1; @@ -140,13 +136,15 @@ public function testInvalidTypeInterface() ->method('get') ->will($this->returnValue($config)); + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, interface must be a string, integer given.' + ); $this->factory->__invoke($this->sm, 'ServiceListener'); } public function testMissingMethod() { - $this->expectException(ServiceNotCreatedException::class); - $this->expectExceptionMessage('Invalid service listener options detected, 0 array must contain method key.'); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 'test'; @@ -156,15 +154,13 @@ public function testMissingMethod() ->method('get') ->will($this->returnValue($config)); + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage('Invalid service listener options detected, 0 array must contain method key.'); $this->factory->__invoke($this->sm, 'ServiceListener'); } public function testInvalidTypeMethod() { - $this->expectException(ServiceNotCreatedException::class); - $this->expectExceptionMessage( - 'Invalid service listener options detected, method must be a string, integer given.' - ); $config['service_listener_options'][0]['service_manager'] = 'test'; $config['service_listener_options'][0]['config_key'] = 'test'; $config['service_listener_options'][0]['interface'] = 'test'; @@ -174,6 +170,10 @@ public function testInvalidTypeMethod() ->method('get') ->will($this->returnValue($config)); + $this->expectException(ServiceNotCreatedException::class); + $this->expectExceptionMessage( + 'Invalid service listener options detected, method must be a string, integer given.' + ); $this->factory->__invoke($this->sm, 'ServiceListener'); } } From 150e0b44f9bc814619163ea5c68a71cc2d6ee724 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Sat, 12 Sep 2020 11:00:56 +0200 Subject: [PATCH 8/9] Remove branch aliases from package Signed-off-by: Geert Eltink --- composer.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/composer.json b/composer.json index 0a0dc8ec8..71f5d9958 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,6 @@ "sort-packages": true }, "extra": { - "branch-alias": { - "dev-master": "3.1-dev", - "dev-develop": "3.2-dev" - } }, "require": { "php": "^7.3", From 67acecb75ee08429066cb2e7b16bc25a960154d6 Mon Sep 17 00:00:00 2001 From: Martin Seysen Date: Fri, 23 Apr 2021 15:10:30 +0200 Subject: [PATCH 9/9] Optimize Code When calling `create()` outside of the `processPostData()` method (analog to `processBodyContent`) we can override the method to change the behaviour of parsing POST-Params and also getting the result back and not the response of the action. All other cases `GET`, `PUT`, `PATCH` and `DELETE` also calls their similar method in directly in the `onDispatch()` method. These changes doesn't infect the workflow. It's just a small code optimization. Signed-off-by: Martin Seysen --- src/Controller/AbstractRestfulController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Controller/AbstractRestfulController.php b/src/Controller/AbstractRestfulController.php index 3e83e73ba..b0ceb07a7 100644 --- a/src/Controller/AbstractRestfulController.php +++ b/src/Controller/AbstractRestfulController.php @@ -425,7 +425,8 @@ public function onDispatch(MvcEvent $e) // POST case 'post': $action = 'create'; - $return = $this->processPostData($request); + $data = $this->processPostData($request); + $return = $this->create($data); break; // PUT case 'put': @@ -454,7 +455,7 @@ public function onDispatch(MvcEvent $e) } /** - * Process post data and call create + * Process post data * * @param Request $request * @return mixed @@ -464,10 +465,10 @@ public function onDispatch(MvcEvent $e) public function processPostData(Request $request) { if ($this->requestHasContentType($request, self::CONTENT_TYPE_JSON)) { - return $this->create($this->jsonDecode($request->getContent())); + return $this->jsonDecode($request->getContent()); } - return $this->create($request->getPost()->toArray()); + return $request->getPost()->toArray(); } /**