Skip to content

Commit c1ee6d2

Browse files
committed
qa: ensure test setup mimics proper application
Ensures the test asset `Application` class implements the MVC `ApplicationInterface`, allowing us to test the `Module` class properly. Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
1 parent 95a2d62 commit c1ee6d2

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

psalm.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::with"/>
2929
</errorLevel>
3030
</InternalMethod>
31+
32+
<InvalidReturnType>
33+
<errorLevel type="suppress">
34+
<file name="./test/TestAsset/Application.php"/>
35+
</errorLevel>
36+
</InvalidReturnType>
3137
</issueHandlers>
38+
3239
<plugins>
3340
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
3441
</plugins>

src/Module.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Laminas\ApiTools\Versioning\ContentTypeListener;
99
use Laminas\ApiTools\Versioning\VersionListener;
1010
use Laminas\ModuleManager\ModuleManager;
11-
use Laminas\Mvc\Application;
11+
use Laminas\Mvc\ApplicationInterface;
1212
use Laminas\Mvc\MvcEvent;
1313

1414
use function assert;
@@ -56,7 +56,7 @@ public function init($moduleManager)
5656
public function onBootstrap($e)
5757
{
5858
$app = $e->getTarget();
59-
assert($app instanceof Application);
59+
assert($app instanceof ApplicationInterface);
6060
$events = $app->getEventManager();
6161
$services = $app->getServiceManager();
6262
$services->get(AcceptListener::class)->attach($events);

test/TestAsset/Application.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
namespace LaminasTest\ApiTools\Versioning\TestAsset;
66

77
use Laminas\EventManager\EventManagerInterface;
8+
use Laminas\Mvc\ApplicationInterface;
89
use Laminas\ServiceManager\ServiceLocatorInterface;
10+
use Laminas\Stdlib\RequestInterface;
11+
use Laminas\Stdlib\ResponseInterface;
912

10-
class Application
13+
/** @psalm-suppress MissingConstructor */
14+
class Application implements ApplicationInterface
1115
{
12-
/** @var EventManagerInterface|null */
16+
/** @var EventManagerInterface */
1317
protected $events;
1418

15-
/** @var ServiceLocatorInterface|null */
19+
/** @var ServiceLocatorInterface */
1620
protected $services;
1721

1822
public function setServiceManager(ServiceLocatorInterface $services): void
@@ -25,15 +29,47 @@ public function setEventManager(EventManagerInterface $events): void
2529
$this->events = $events;
2630
}
2731

28-
/** @return ServiceLocatorInterface|null */
32+
/** @return ServiceLocatorInterface */
2933
public function getServiceManager()
3034
{
3135
return $this->services;
3236
}
3337

34-
/** @return EventManagerInterface|null */
38+
/** @return EventManagerInterface */
3539
public function getEventManager()
3640
{
3741
return $this->events;
3842
}
43+
44+
// Unimplemented methods
45+
// phpcs:disable Squiz.Commenting.FunctionComment.InvalidNoReturn
46+
47+
/**
48+
* Get the request object
49+
*
50+
* @return RequestInterface
51+
*/
52+
public function getRequest()
53+
{
54+
}
55+
56+
/**
57+
* Get the response object
58+
*
59+
* @return ResponseInterface
60+
*/
61+
public function getResponse()
62+
{
63+
}
64+
65+
/**
66+
* Run the application
67+
*
68+
* @return self
69+
*/
70+
public function run()
71+
{
72+
}
73+
74+
// phpcs:enable Squiz Commenting.FunctionComment.InvalidNoReturn
3975
}

0 commit comments

Comments
 (0)