Skip to content

Commit

Permalink
Merge pull request #25 from php-http/issue-24
Browse files Browse the repository at this point in the history
Allow us to reset the builder
  • Loading branch information
dbu authored Dec 30, 2016
2 parents cf58c6d + f3fd223 commit 5e02c79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/MultipartStreamBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ public function setMimetypeHelper(MimetypeHelper $mimetypeHelper)
return $this;
}

/**
* Reset and clear all stored data. This allows you to use builder for a subsequent request.
*
* @return MultipartStreamBuilder
*/
public function reset()
{
$this->data = [];
$this->boundary = null;

return $this;
}

/**
* Gets the filename from a given path.
*
Expand Down
14 changes: 14 additions & 0 deletions tests/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ public function testBoundary()
$this->assertEquals(5, substr_count($multipartStream, $boundary));
}

public function testReset()
{
$boundary = 'SpecialBoundary';
$builder = new MultipartStreamBuilder();
$builder->addResource('content0', 'foobar');
$builder->setBoundary($boundary);

$builder->reset();
$multipartStream = (string) $builder->build();
$this->assertNotContains('foobar', $multipartStream, 'Stream should not have any data after reset()');
$this->assertNotEquals($boundary, $builder->getBoundary(), 'Stream should have a new boundary after reset()');
$this->assertNotEmpty($builder->getBoundary());
}

/**
* @param string $body
*
Expand Down

0 comments on commit 5e02c79

Please sign in to comment.