From af468471c86cda58e5e223b9330558d2b8a48430 Mon Sep 17 00:00:00 2001 From: Zaahid Bateson Date: Wed, 20 Mar 2019 23:12:40 -0700 Subject: [PATCH] Fix base64 test --- tests/StreamDecorators/Base64StreamTest.php | 22 ++++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/StreamDecorators/Base64StreamTest.php b/tests/StreamDecorators/Base64StreamTest.php index 007cfb4..96114f4 100644 --- a/tests/StreamDecorators/Base64StreamTest.php +++ b/tests/StreamDecorators/Base64StreamTest.php @@ -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'); @@ -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); }