Skip to content

Commit

Permalink
Updated unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
batumibiz committed Dec 20, 2024
1 parent 7e650c6 commit c36bfa3
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions tests/unit/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
const FOLDER = __DIR__ . '/../stubs/';
const DATAIMAGE = 'data:image/png;base64';

beforeEach(function () {
$this->imageObj = new Image('abcd');
});

test('Can generate data image string', function () {
$image = (string)$this->imageObj;
expect($image)->toStartWith(DATAIMAGE);
expect((string) new Image('abcd'))->toStartWith(DATAIMAGE);
});

test('Can generate valid image', function () {
writeImage((string)$this->imageObj);
writeImage((string) new Image('abcd'));
$info = getimagesize(FOLDER . 'test.png');
expect($info[0])->toBe(190);
expect($info[1])->toBe(80);
Expand All @@ -29,7 +24,7 @@
$options = new ImageOptions();
$options->setFontsFolder(FOLDER);
$image = (new Image('abcd', $options));
expect((string)$image)->toStartWith(DATAIMAGE);
expect((string) $image)->toStartWith(DATAIMAGE);
});

test('Fonts does not exist', function () {
Expand All @@ -51,16 +46,15 @@
dataset('customFontValues', function () {
return [
'random' => [0],
'upper' => [ImageOptions::FONT_CASE_UPPER],
'lower' => [ImageOptions::FONT_CASE_LOWER],
'upper' => [ImageOptions::FONT_CASE_UPPER],
'lower' => [ImageOptions::FONT_CASE_LOWER],
];
});

// phpcs:disable
function writeImage(string $image): void
{
$image = str_replace(DATAIMAGE, '', $image);
// @phpstan-ignore function.strict
file_put_contents(FOLDER . 'test.png', base64_decode($image));
}
// phpcs:enable

0 comments on commit c36bfa3

Please sign in to comment.