diff --git a/src/EncodedImage.php b/src/EncodedImage.php index 7f8d0848..7244048c 100644 --- a/src/EncodedImage.php +++ b/src/EncodedImage.php @@ -25,7 +25,7 @@ class EncodedImage } } - public function toDataUrl(): string + public function toDataUri(): string { return sprintf('data:%s;base64,%s', $this->mimetype, base64_encode($this->data)); } diff --git a/tests/EncodedImageTest.php b/tests/EncodedImageTest.php new file mode 100644 index 00000000..7e4ac637 --- /dev/null +++ b/tests/EncodedImageTest.php @@ -0,0 +1,37 @@ +assertInstanceOf(EncodedImage::class, $image); + } + + public function testSave(): void + { + $image = new EncodedImage('foo', 'bar'); + $path = __DIR__ . '/foo.tmp'; + $this->assertFalse(file_exists($path)); + $image->save($path); + $this->assertTrue(file_exists($path)); + $this->assertEquals('foo', file_get_contents($path)); + unlink($path); + } + + public function testToDataUri(): void + { + $image = new EncodedImage('foo', 'bar'); + $this->assertEquals('data:bar;base64,Zm9v', $image->toDataUri()); + } + + public function testToString(): void + { + $image = new EncodedImage('foo', 'bar'); + $this->assertEquals('foo', (string) $image); + } +}