Skip to content

Commit 583dbc5

Browse files
authored
Work around same-name import bug in PHP 5.6 (#239)
fix class name collision in PHP 5.x
1 parent cd7f3ae commit 583dbc5

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5-
## Unreleased
5+
## 1.8.1 - 2017-12-06
6+
7+
### Fixed
8+
9+
- `PluginClientFactory` name conflict with PHP 5.x.
10+
11+
## 1.8.0 - 2017-11-30
612

713
### Added
814

Collector/PluginClientFactoryListener.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace Http\HttplugBundle\Collector;
44

5-
use Http\Client\Common\PluginClientFactory;
6-
use Http\HttplugBundle\Collector\PluginClientFactory as CollectorPluginClientFactory;
5+
use Http\Client\Common\PluginClientFactory as DefaultPluginClientFactory;
76
use Symfony\Component\EventDispatcher\Event;
87
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
98

@@ -19,14 +18,14 @@
1918
final class PluginClientFactoryListener implements EventSubscriberInterface
2019
{
2120
/**
22-
* @var CollectorPluginClientFactory
21+
* @var PluginClientFactory
2322
*/
2423
private $factory;
2524

2625
/**
27-
* @param CollectorPluginClientFactory $factory
26+
* @param PluginClientFactory $factory
2827
*/
29-
public function __construct(CollectorPluginClientFactory $factory)
28+
public function __construct(PluginClientFactory $factory)
3029
{
3130
$this->factory = $factory;
3231
}
@@ -38,7 +37,7 @@ public function __construct(CollectorPluginClientFactory $factory)
3837
*/
3938
public function onEvent(Event $e)
4039
{
41-
PluginClientFactory::setFactory([$this->factory, 'createClient']);
40+
DefaultPluginClientFactory::setFactory([$this->factory, 'createClient']);
4241
}
4342

4443
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Http\HttplugBundle\Tests\Unit\Collector;
4+
5+
use Http\Client\Common\PluginClientFactory as DefaultPluginClientFactory;
6+
use Http\HttplugBundle\Collector\Collector;
7+
use Http\HttplugBundle\Collector\Formatter;
8+
use Http\HttplugBundle\Collector\PluginClientFactory;
9+
use Http\HttplugBundle\Collector\PluginClientFactoryListener;
10+
use Nyholm\NSA;
11+
use PHPUnit\Framework\TestCase;
12+
use Symfony\Component\EventDispatcher\Event;
13+
use Symfony\Component\Stopwatch\Stopwatch;
14+
15+
final class PluginClientFactoryListenerTest extends TestCase
16+
{
17+
public function testRegisterPluginClientFactory()
18+
{
19+
$collector = $this->getMockBuilder(Collector::class)->getMock();
20+
$formatter = $this->getMockBuilder(Formatter::class)->disableOriginalConstructor()->getMock();
21+
$stopwatch = $this->getMockBuilder(Stopwatch::class)->getMock();
22+
23+
$factory = new PluginClientFactory($collector, $formatter, $stopwatch);
24+
25+
$listener = new PluginClientFactoryListener($factory);
26+
27+
$listener->onEvent(new Event());
28+
29+
$this->assertTrue(is_callable(NSA::getProperty(DefaultPluginClientFactory::class, 'factory')));
30+
}
31+
}

0 commit comments

Comments
 (0)