Skip to content

Commit c78d9e7

Browse files
authored
Make sure we can add resources with same name. Ie no overwrite (#32)
* Make sure we can add resources with same name. Ie no overwrite * added changelog * Updated docs
1 parent 74d5ac5 commit c78d9e7

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Change Log
22

3+
## 0.2.0 - ???
4+
5+
### Fixed
6+
7+
- Make sure one can add resources with same name without overwrite.
8+
39
## 0.1.6 - 2017-02-16
410

511
### Fixed
612

713
- Performance improvements by avoid using `uniqid()`.
14+
- Make sure one can add resources with same name without overwrite.
815

916
## 0.1.5 - 2017-02-14
1017

src/MultipartStreamBuilder.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public function __construct(StreamFactory $streamFactory = null)
4444
}
4545

4646
/**
47-
* Add a resource to the Multipart Stream. If the same $name is used twice the first resource will
48-
* be overwritten.
47+
* Add a resource to the Multipart Stream.
4948
*
5049
* @param string $name the formpost name
5150
* @param string|resource|StreamInterface $resource
@@ -76,7 +75,7 @@ public function addResource($name, $resource, array $options = [])
7675
}
7776

7877
$this->prepareHeaders($name, $stream, $options['filename'], $options['headers']);
79-
$this->data[$name] = ['contents' => $stream, 'headers' => $options['headers'], 'filename' => $options['filename']];
78+
$this->data[] = ['contents' => $stream, 'headers' => $options['headers'], 'filename' => $options['filename']];
8079

8180
return $this;
8281
}

tests/FunctionTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ public function testFormName()
101101
$this->assertTrue(false !== strpos($multipartStream, 'Content-Disposition: form-data; name="a-formname"'));
102102
}
103103

104+
public function testAddResourceWithSameName()
105+
{
106+
$builder = new MultipartStreamBuilder();
107+
$builder->addResource('name', 'foo1234567890foo');
108+
$builder->addResource('name', 'bar1234567890bar');
109+
110+
$multipartStream = (string) $builder->build();
111+
$this->assertTrue(false !== strpos($multipartStream, 'bar1234567890bar'));
112+
$this->assertTrue(false !== strpos($multipartStream, 'foo1234567890foo'), 'Using same name must not overwrite');
113+
}
114+
104115
public function testBoundary()
105116
{
106117
$boundary = 'SpecialBoundary';

0 commit comments

Comments
 (0)