Skip to content

Commit 588774a

Browse files
committed
Make sure we can add resources with same name. Ie no overwrite
1 parent d98c876 commit 588774a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/MultipartStreamBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function addResource($name, $resource, array $options = [])
7676
}
7777

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

8181
return $this;
8282
}

tests/FunctionTest.php

Lines changed: 11 additions & 0 deletions
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)