diff --git a/CHANGELOG.md b/CHANGELOG.md index 144cbc4..0e4eb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,17 @@ # Change Log +## 0.2.0 - ??? + +### Fixed + +- Make sure one can add resources with same name without overwrite. + ## 0.1.6 - 2017-02-16 ### Fixed - Performance improvements by avoid using `uniqid()`. +- Make sure one can add resources with same name without overwrite. ## 0.1.5 - 2017-02-14 diff --git a/src/MultipartStreamBuilder.php b/src/MultipartStreamBuilder.php index f8170b8..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 @@ -76,7 +75,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';