From 97ed74405d5caa41551a6e6877f5b89fb0910976 Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Thu, 23 Feb 2017 09:17:45 +0100 Subject: [PATCH 1/4] Add IDE files to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2c9d04ccd11..d34fabcc539 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ phpunit.xml composer.lock composer.phar vendor/* + +# IDEs +/.idea/ \ No newline at end of file From 9b5c4916ab9f3f1887575e3b1023a36b4c1fda19 Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Thu, 23 Feb 2017 09:24:47 +0100 Subject: [PATCH 2/4] Add failing UT to show bug --- test/Github/Tests/HttpClient/BuilderTest.php | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/Github/Tests/HttpClient/BuilderTest.php b/test/Github/Tests/HttpClient/BuilderTest.php index 3643dd292fa..dadfd4f44d8 100644 --- a/test/Github/Tests/HttpClient/BuilderTest.php +++ b/test/Github/Tests/HttpClient/BuilderTest.php @@ -49,4 +49,28 @@ public function shouldAddHeaders() $client->addHeaders($headers); } + + /** + * @test + */ + public function appendingHeaderShouldAddAndRemovePlugin() + { + $expectedHeaders = [ + 'Accept' => 'application/vnd.github.v3', + ]; + + $client = $this->getMockBuilder(\Github\HttpClient\Builder::class) + ->setMethods(array('removePlugin', 'addPlugin')) + ->getMock(); + + $client->expects($this->once()) + ->method('removePlugin') + ->with(Plugin\HeaderAppendPlugin::class); + + $client->expects($this->once()) + ->method('addPlugin') + ->with(new Plugin\HeaderAppendPlugin($expectedHeaders)); + + $client->addHeaderValue('Accept', 'application/vnd.github.v3'); + } } From bd63fa2c46a49edfcfe1d45e5d084af924157c9c Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Thu, 23 Feb 2017 09:26:37 +0100 Subject: [PATCH 3/4] Fix bug: reset plugin when headers change --- lib/Github/HttpClient/Builder.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 7d2052498e6..5b742285bd9 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -168,6 +168,9 @@ public function addHeaderValue($header, $headerValue) } else { $this->headers[$header] = array_merge((array)$this->headers[$header], array($headerValue)); } + + $this->removePlugin(Plugin\HeaderAppendPlugin::class); + $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); } /** From 0bd2ea12fb0ee10b683204c42d3bc99a0f340922 Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Thu, 23 Feb 2017 10:25:39 +0100 Subject: [PATCH 4/4] Remove IDEs from gitignore --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index d34fabcc539..2c9d04ccd11 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,3 @@ phpunit.xml composer.lock composer.phar vendor/* - -# IDEs -/.idea/ \ No newline at end of file