Skip to content

Commit 5fa9ec6

Browse files
authored
Merge pull request #2 from Micro-PHP/v1.6.0-dev
v1.6.0 release
2 parents 1c1894f + f562017 commit 5fa9ec6

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
}
1111
],
1212
"require": {
13-
"micro/kernel-boot-plugin-depended": "^1",
14-
"micro/plugin-event-emitter": "^1",
15-
"micro/plugin-http-core": "^1"
13+
"micro/kernel-app": "^1.6",
14+
"micro/kernel-boot-plugin-depended": "^1.6",
15+
"micro/plugin-event-emitter": "^1.6",
16+
"micro/plugin-http-core": "^1.6"
1617
},
1718
"require-dev": {
1819
"ergebnis/composer-normalize": "^2.29",

src/Listener/ApplicationStartedListener.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Micro\Component\EventEmitter\EventInterface;
1717
use Micro\Component\EventEmitter\EventListenerInterface;
1818
use Micro\Kernel\App\Business\Event\ApplicationReadyEvent;
19+
use Micro\Kernel\App\Business\Event\ApplicationReadyEventInterface;
1920
use Micro\Plugin\Http\Facade\HttpFacadeInterface;
2021
use Symfony\Component\HttpFoundation\Request;
2122

@@ -29,9 +30,15 @@ public function __construct(
2930
) {
3031
}
3132

33+
/**
34+
* @param ApplicationReadyEvent $event
35+
*
36+
* @psalm-suppress MoreSpecificImplementedParamType
37+
*/
3238
public function on(EventInterface $event): void
3339
{
34-
if (!$this->isHttp()) {
40+
$sysenv = $event->systemEnvironment();
41+
if ('cli' === $sysenv) {
3542
return;
3643
}
3744

@@ -40,13 +47,8 @@ public function on(EventInterface $event): void
4047
$this->httpFacade->execute($request);
4148
}
4249

43-
protected function isHttp(): bool
44-
{
45-
return \PHP_SAPI !== 'cli';
46-
}
47-
4850
public static function supports(EventInterface $event): bool
4951
{
50-
return $event instanceof ApplicationReadyEvent;
52+
return $event instanceof ApplicationReadyEventInterface;
5153
}
5254
}

tests/Unit/Listener/ApplicationStartedListenerTest.php

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
namespace Micro\Plugin\Http\Test\Unit\Listener;
1515

16-
use Micro\Kernel\App\AppKernelInterface;
17-
use Micro\Kernel\App\Business\Event\ApplicationReadyEvent;
16+
use Micro\Kernel\App\Business\Event\ApplicationReadyEventInterface;
1817
use Micro\Plugin\Http\Facade\HttpFacadeInterface;
1918
use Micro\Plugin\Http\Listener\ApplicationStartedListener;
2019
use PHPUnit\Framework\TestCase;
@@ -26,35 +25,26 @@ class ApplicationStartedListenerTest extends TestCase
2625

2726
private HttpFacadeInterface $httpFacade;
2827

29-
private ApplicationReadyEvent $applicationReadyEvent;
30-
3128
protected function setUp(): void
3229
{
3330
$this->httpFacade = $this->createMock(HttpFacadeInterface::class);
34-
$this->applicationStartedListener = $this->getMockBuilder(ApplicationStartedListener::class)
35-
->setConstructorArgs([
36-
$this->httpFacade,
37-
])
38-
->onlyMethods([
39-
'isHttp',
40-
])
41-
->getMock();
31+
$this->applicationStartedListener = new ApplicationStartedListener($this->httpFacade);
32+
}
4233

43-
$this->applicationReadyEvent = new ApplicationReadyEvent(
44-
$this->createMock(AppKernelInterface::class),
45-
'any',
46-
);
34+
protected function createEvent(bool $isHttp)
35+
{
36+
$evt = $this->createMock(ApplicationReadyEventInterface::class);
37+
$evt->method('systemEnvironment')->willReturn($isHttp ? 'http' : 'cli');
38+
39+
return $evt;
4740
}
4841

4942
/**
5043
* @dataProvider dataProvider
5144
*/
5245
public function testOn(bool $isHttp): void
5346
{
54-
$this->applicationStartedListener
55-
->expects($this->once())
56-
->method('isHttp')
57-
->willReturn($isHttp);
47+
$event = $this->createEvent($isHttp);
5848

5949
if (!$isHttp) {
6050
$this->httpFacade
@@ -69,18 +59,7 @@ public function testOn(bool $isHttp): void
6959
);
7060
}
7161

72-
$this->applicationStartedListener->on($this->applicationReadyEvent);
73-
}
74-
75-
public function testIsHttp()
76-
{
77-
$this->httpFacade->expects($this->never())->method('execute');
78-
79-
$appListener = new ApplicationStartedListener(
80-
$this->httpFacade
81-
);
82-
83-
$appListener->on($this->applicationReadyEvent);
62+
$this->applicationStartedListener->on($event);
8463
}
8564

8665
public function dataProvider(): array
@@ -96,6 +75,6 @@ public function testSupports()
9675
$httpFacade = $this->createMock(HttpFacadeInterface::class);
9776
$listener = new ApplicationStartedListener($httpFacade);
9877

99-
$this->assertTrue($listener->supports($this->applicationReadyEvent));
78+
$this->assertTrue($listener->supports($this->createEvent(true)));
10079
}
10180
}

0 commit comments

Comments
 (0)