Skip to content

Commit

Permalink
Merge pull request #2 from lion-packages/testing
Browse files Browse the repository at this point in the history
test: test has been added for createImage method
  • Loading branch information
Sleon4 authored Nov 19, 2023
2 parents 29da11d + 80ad024 commit cff9439
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/LionTest/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,19 @@ public function createDirectory(string $directory): void
}
}
}

/**
* Generates a blank image with the defined properties
* */
public function createImage(
int $x = 100,
int $y = 100,
string $path = './storage/',
string $fileName = 'image.png'
): void
{
$image = imagecreatetruecolor($x, $y);
imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));
imagepng($image, "{$path}{$fileName}");
}
}
25 changes: 25 additions & 0 deletions tests/TestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
class TestTest extends Test
{
const BITS = 16;
const X = 200;
const Y = 150;
const PROPIERTY = 'bits';
const URL_PATH = './storage/example/';
const FILE_NAME = 'image.png';
const FILE_NAME_CUSTOM = 'custom.png';

private mixed $customClass;

protected function setUp(): void
{
$this->createDirectory(self::URL_PATH);

$this->customClass = new class {
private int $bits;

Expand All @@ -26,6 +32,11 @@ public function setBits(int $bits): void
};
}

protected function tearDown(): void
{
$this->rmdirRecursively('./storage/');
}

public function testGetPrivateProperty(): void
{
$this->initReflection($this->customClass);
Expand All @@ -48,4 +59,18 @@ public function testCreateDirectory(): void

$this->assertTrue(is_dir(self::URL_PATH));
}

public function testCreateImageDefaultValues(): void
{
$this->createImage();

$this->assertFileExists('./storage/image.png');
}

public function testCreateImageCustomValues(): void
{
$this->createImage(self::X, self::Y, self::URL_PATH, self::FILE_NAME_CUSTOM);

$this->assertFileExists(self::URL_PATH . self::FILE_NAME_CUSTOM);
}
}

0 comments on commit cff9439

Please sign in to comment.