From 11c55a5082154185b104b7ccde28e8428b1a55ac Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 15 Feb 2017 15:25:24 +0100 Subject: [PATCH 1/3] Make sure we can add resources with same name. Ie no overwrite --- src/MultipartStreamBuilder.php | 2 +- tests/FunctionTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/MultipartStreamBuilder.php b/src/MultipartStreamBuilder.php index f8170b8..fe10170 100644 --- a/src/MultipartStreamBuilder.php +++ b/src/MultipartStreamBuilder.php @@ -76,7 +76,7 @@ public function addResource($name, $resource, array $options = []) } $this->prepareHeaders($name, $stream, $options['filename'], $options['headers']); - $this->data[$name] = ['contents' => $stream, 'headers' => $options['headers'], 'filename' => $options['filename']]; + $this->data[] = ['contents' => $stream, 'headers' => $options['headers'], 'filename' => $options['filename']]; return $this; } diff --git a/tests/FunctionTest.php b/tests/FunctionTest.php index 16d06e2..10d16d4 100644 --- a/tests/FunctionTest.php +++ b/tests/FunctionTest.php @@ -101,6 +101,17 @@ public function testFormName() $this->assertTrue(false !== strpos($multipartStream, 'Content-Disposition: form-data; name="a-formname"')); } + public function testAddResourceWithSameName() + { + $builder = new MultipartStreamBuilder(); + $builder->addResource('name', 'foo1234567890foo'); + $builder->addResource('name', 'bar1234567890bar'); + + $multipartStream = (string) $builder->build(); + $this->assertTrue(false !== strpos($multipartStream, 'bar1234567890bar')); + $this->assertTrue(false !== strpos($multipartStream, 'foo1234567890foo'), 'Using same name must not overwrite'); + } + public function testBoundary() { $boundary = 'SpecialBoundary'; From 396b49e7e8e5aa057e183ac634f298258d1aa3d5 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 15 Feb 2017 15:26:45 +0100 Subject: [PATCH 2/3] added changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 144cbc4..9b3a469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Performance improvements by avoid using `uniqid()`. +- Make sure one can add resources with same name without overwrite. ## 0.1.5 - 2017-02-14 From 17b4c146577ff24c7bea0c4cd1e16130a21cbc35 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 15 Feb 2017 16:00:45 +0100 Subject: [PATCH 3/3] Updated docs --- CHANGELOG.md | 6 ++++++ src/MultipartStreamBuilder.php | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b3a469..0e4eb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 0.2.0 - ??? + +### Fixed + +- Make sure one can add resources with same name without overwrite. + ## 0.1.6 - 2017-02-16 ### Fixed diff --git a/src/MultipartStreamBuilder.php b/src/MultipartStreamBuilder.php index fe10170..3421d73 100644 --- a/src/MultipartStreamBuilder.php +++ b/src/MultipartStreamBuilder.php @@ -44,8 +44,7 @@ public function __construct(StreamFactory $streamFactory = null) } /** - * Add a resource to the Multipart Stream. If the same $name is used twice the first resource will - * be overwritten. + * Add a resource to the Multipart Stream. * * @param string $name the formpost name * @param string|resource|StreamInterface $resource