Skip to content

Commit

Permalink
Make sure we can add resources with same name. Ie no overwrite (#32)
Browse files Browse the repository at this point in the history
* Make sure we can add resources with same name. Ie no overwrite

* added changelog

* Updated docs
  • Loading branch information
Nyholm committed Feb 17, 2017
1 parent 74d5ac5 commit c78d9e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
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.

## 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

0 comments on commit c78d9e7

Please sign in to comment.