Skip to content

Commit c8210ab

Browse files
committed
test: Response::blob
1 parent 0ca635c commit c8210ab

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Blob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __toString():string {
3333
public function __get(string $name):mixed {
3434
switch($name) {
3535
case "size":
36-
return $this->size;
36+
return strlen($this->content);
3737

3838
case "type":
3939
return $this->type;

test/phpunit/ResponseTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Gt\Http\Test;
33

44
use Gt\Http\ArrayBuffer;
5+
use Gt\Http\Blob;
56
use Gt\Http\FormData;
67
use Gt\Http\Header\ResponseHeaders;
78
use Gt\Http\Request;
@@ -164,6 +165,23 @@ public function testAwaitJson():void {
164165
self::assertSame("phpgt", $actualJson->getString("name"));
165166
}
166167

168+
public function testBlob():void {
169+
$blobString = random_bytes(32);
170+
171+
$stream = new Stream();
172+
$stream->write($blobString);
173+
174+
$sut = (new Response())->withBody($stream);
175+
176+
$actualBlob = null;
177+
$sut->blob()->then(function($blob) use(&$actualBlob) {
178+
$actualBlob = $blob;
179+
});
180+
181+
self::assertInstanceOf(Blob::class, $actualBlob);
182+
self::assertSame(32, $actualBlob->size);
183+
}
184+
167185
public function testAwaitBlob():void {
168186
$blobString = random_bytes(32);
169187

0 commit comments

Comments
 (0)