Skip to content

Commit

Permalink
Fix base64 test
Browse files Browse the repository at this point in the history
  • Loading branch information
zbateson committed Mar 21, 2019
1 parent e2bf1a5 commit af46847
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tests/StreamDecorators/Base64StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testDecodeFile()
$org = './tests/_data/blueball.png';
$f = fopen($encoded, 'r');

$streamDecorator = new Base64Stream(Psr7\stream_for($f));
$streamDecorator = new Base64Stream(new PregReplaceFilterStream(Psr7\stream_for($f), '/[^a-zA-Z0-9\/\+=]/', ''));
$handle = StreamWrapper::getResource($streamDecorator);

$this->assertEquals(file_get_contents($org), stream_get_contents($handle), 'Decoded blueball not equal to original file');
Expand All @@ -90,28 +90,22 @@ public function testDecodeFile()
fclose($f);
}

public function testDecodeWordFile()
public function testDecodeWordFileWithStreamGetContents()
{
$encoded = './tests/_data/test.b64.txt';
$org = './tests/_data/test.doc';
$f = fopen($encoded, 'r');

$streamDecorator = new Base64Stream(Psr7\stream_for($f));
//$handle = StreamWrapper::getResource($streamDecorator);
$streamDecorator = new Base64Stream(new PregReplaceFilterStream(Psr7\stream_for($f), '/[^a-zA-Z0-9\/\+=]/', ''));
$handle = StreamWrapper::getResource($streamDecorator);

$offset = 0;
$horg = fopen($org, 'r');
while (!$streamDecorator->eof()) {
$this->assertEquals(
fread($horg, 50),
$streamDecorator->read(50),
'Decoded test.doc not equal to original file while reading 50 bytes at offset ' . $offset
);
$offset += 50;
}
$this->assertTrue(
stream_get_contents($handle) === stream_get_contents($horg)
);

fclose($horg);
//fclose($handle);
fclose($handle);
fclose($f);
}

Expand Down

0 comments on commit af46847

Please sign in to comment.