Skip to content

Make sure we can add resources with same name. Ie no overwrite #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is probably no longer needed (assuming the changes will only be part of the 0.2.0 release)


## 0.1.5 - 2017-02-14

Expand Down
5 changes: 2 additions & 3 deletions src/MultipartStreamBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down