diff --git a/.gitignore b/.gitignore index b2358c4..22e5621 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ +# Ignore files of IDE +.idea + # Ignore potentially sensitive phpunit file phpunit.xml +# Ignore PHPUnit cache file +.phpunit.result.cache # Ignore composer generated files composer.lock diff --git a/src/EightPointsGuzzleBundle.php b/src/EightPointsGuzzleBundle.php index 67cd9a7..0f1ab3b 100644 --- a/src/EightPointsGuzzleBundle.php +++ b/src/EightPointsGuzzleBundle.php @@ -11,7 +11,7 @@ class EightPointsGuzzleBundle extends Bundle { - /** @var \EightPoints\Bundle\GuzzleBundle\PluginInterface[] */ + /** @var array */ protected $plugins = []; /** @@ -50,7 +50,7 @@ public function build(ContainerBuilder $container) public function getContainerExtension() : ExtensionInterface { if ($this->extension === null) { - $this->extension = new EightPointsGuzzleExtension($this->plugins); + $this->extension = new EightPointsGuzzleExtension(array_values($this->plugins)); } return $this->extension; @@ -75,16 +75,15 @@ public function boot() */ protected function registerPlugin(PluginInterface $plugin) : void { + $pluginName = $plugin->getPluginName(); // Check plugins name duplication - foreach ($this->plugins as $registeredPlugin) { - if ($registeredPlugin->getPluginName() === $plugin->getPluginName()) { - throw new InvalidConfigurationException(sprintf( - 'Trying to connect two plugins with same name: %s', - $plugin->getPluginName() - )); - } + if (array_key_exists($pluginName, $this->plugins)) { + throw new InvalidConfigurationException(sprintf( + 'Trying to connect two plugins with same name: %s', + $pluginName + )); } - $this->plugins[] = $plugin; + $this->plugins[$pluginName] = $plugin; } } diff --git a/tests/DataCollector/HttpDataCollectorTest.php b/tests/DataCollector/HttpDataCollectorTest.php index 6c080bb..ad99876 100644 --- a/tests/DataCollector/HttpDataCollectorTest.php +++ b/tests/DataCollector/HttpDataCollectorTest.php @@ -341,8 +341,8 @@ public function testTotalTime() $collector->addTotalTime(3.14); $this->assertEquals(3.14, $collector->getTotalTime()); - $collector->addTotalTime(2.17); - $this->assertEquals(5.31, $collector->getTotalTime()); + $collector->addTotalTime(2.18); + $this->assertEquals(5.32, $collector->getTotalTime()); } /** diff --git a/tests/EightPointsGuzzleBundleTest.php b/tests/EightPointsGuzzleBundleTest.php index 79f851f..388abac 100644 --- a/tests/EightPointsGuzzleBundleTest.php +++ b/tests/EightPointsGuzzleBundleTest.php @@ -39,13 +39,33 @@ public function testInitWithPluginsNameDuplication() ->willReturn('wsse'); $secondPlugin = $this->getMockBuilder(PluginInterface::class)->getMock(); - $secondPlugin->expects($this->exactly(2)) + $secondPlugin->expects($this->once()) ->method('getPluginName') ->willReturn('wsse'); new EightPointsGuzzleBundle([$firstPlugin, $secondPlugin]); } + public function testPluginNameAskedOnceOnInit() + { + $firstPlugin = $this->getMockBuilder(PluginInterface::class)->getMock(); + $firstPlugin->expects($this->once()) + ->method('getPluginName') + ->willReturn('a'); + + $secondPlugin = $this->getMockBuilder(PluginInterface::class)->getMock(); + $secondPlugin->expects($this->once()) + ->method('getPluginName') + ->willReturn('b'); + + $thirdPlugin = $this->getMockBuilder(PluginInterface::class)->getMock(); + $thirdPlugin->expects($this->once()) + ->method('getPluginName') + ->willReturn('c'); + + new EightPointsGuzzleBundle([$firstPlugin, $secondPlugin, $thirdPlugin]); + } + public function testBoot() { $plugin = $this->getMockBuilder(PluginInterface::class)->getMock();