Skip to content

Commit

Permalink
PhpStan warnings have been resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
batumibiz committed Nov 5, 2024
1 parent 875f700 commit e76cb46
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
);
}

if (empty($this->characterSet)) {
if ($this->characterSet === '') {
throw new InvalidArgumentException(
'Character set cannot be empty'
);
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/CodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ class CodeTest extends TestCase
public function testCanGenerateRandomCode(): void
{
$code = (new Code())->generate();
$this->assertGreaterThanOrEqual(3, strlen($code));
self::assertGreaterThanOrEqual(3, strlen($code));
}

public function testToString(): void
{
$code = (string) new Code();
$this->assertGreaterThanOrEqual(3, strlen($code));
self::assertGreaterThanOrEqual(3, strlen($code));
}

public function testCanSpecifyLength(): void
{
$code = (string) new Code(2, 2);
$this->assertEquals(2, strlen($code));
self::assertEquals(2, strlen($code));
$code = (string) new Code(5, 5);
$this->assertEquals(5, strlen($code));
self::assertEquals(5, strlen($code));
}

public function testCanSpecifyLetters(): void
{
$code = (string) new Code(3, 3, 'aaaaa');
$this->assertEquals('aaa', $code);
self::assertEquals('aaa', $code);
$code = (string) new Code(3, 3, 'bb');
$this->assertEquals('bbb', $code);
self::assertEquals('bbb', $code);
}

#[DataProvider('invalidValues')]
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/ImageOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public function setUp(): void

public function testGetImageHeight(): void
{
$this->assertSame(80, $this->options->getHeight());
self::assertSame(80, $this->options->getHeight());
}

public function testSetImageHeight(): void
{
$this->options->setHeight(100);
$this->assertSame(100, $this->options->getHeight());
self::assertSame(100, $this->options->getHeight());
}

public function testSetImageHeightInvalidValue(): void
Expand All @@ -36,13 +36,13 @@ public function testSetImageHeightInvalidValue(): void

public function testGetImageWidth(): void
{
$this->assertSame(190, $this->options->getWidth());
self::assertSame(190, $this->options->getWidth());
}

public function testSetImageWidth(): void
{
$this->options->setWidth(100);
$this->assertSame(100, $this->options->getWidth());
self::assertSame(100, $this->options->getWidth());
}

public function testSetImageWidthInvalidValue(): void
Expand All @@ -53,13 +53,13 @@ public function testSetImageWidthInvalidValue(): void

public function testGetFontsFolder(): void
{
$this->assertStringEndsWith('fonts', $this->options->getFontsFolder());
self::assertStringEndsWith('fonts', $this->options->getFontsFolder());
}

public function testSetFontsFolder(): void
{
$this->options->setFontsFolder(__DIR__);
$this->assertSame(__DIR__, $this->options->getFontsFolder());
self::assertSame(__DIR__, $this->options->getFontsFolder());
}

public function testInvalidFontsFolder(): void
Expand All @@ -71,21 +71,21 @@ public function testInvalidFontsFolder(): void

public function testGetFontShuffle(): void
{
$this->assertTrue($this->options->getFontShuffle());
self::assertTrue($this->options->getFontShuffle());
}

public function testSetFontShuffle(): void
{
$this->options->setFontShuffle(false);
$this->assertFalse($this->options->getFontShuffle());
self::assertFalse($this->options->getFontShuffle());
$this->options->setFontShuffle(true);
$this->assertTrue($this->options->getFontShuffle());
self::assertTrue($this->options->getFontShuffle());
}

public function testSetDefaultFontSize(): void
{
$this->options->setDefaultFontSize(40);
$this->assertSame(40, $this->options->getFontSize());
self::assertSame(40, $this->options->getFontSize());
}

public function testInvalidDefaultFontSize(): void
Expand All @@ -99,8 +99,8 @@ public function testAdjustFont(): void
{
$font = 'somefont.ttf';
$this->options->adjustFont($font, 40, ImageOptions::FONT_CASE_UPPER);
$this->assertSame(40, $this->options->getFontSize($font));
$this->assertSame(ImageOptions::FONT_CASE_UPPER, $this->options->getFontCase($font));
self::assertSame(40, $this->options->getFontSize($font));
self::assertSame(ImageOptions::FONT_CASE_UPPER, $this->options->getFontCase($font));
}

public function testInvalidFontName(): void
Expand Down
15 changes: 8 additions & 7 deletions tests/unit/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function setUp(): void
public function testCanGenerateDataImageString(): void
{
$image = $this->imageObj->generate();
$this->assertStringStartsWith(self::DATAIMAGE, $image);
self::assertStringStartsWith(self::DATAIMAGE, $image);
}

/**
Expand All @@ -38,15 +38,15 @@ public function testCanGenerateValidImage(): void
{
$this->writeImage($this->imageObj->generate());
$info = getimagesize(self::FOLDER . 'test.png');
$this->assertSame(190, $info[0]);
$this->assertSame(80, $info[1]);
$this->assertSame('image/png', $info['mime']);
self::assertSame(190, $info[0]);
self::assertSame(80, $info[1]);
self::assertSame('image/png', $info['mime']);
}

public function testToString(): void
{
$image = (string) $this->imageObj;
$this->assertStringStartsWith(self::DATAIMAGE, $image);
self::assertStringStartsWith(self::DATAIMAGE, $image);
}

/**
Expand All @@ -57,7 +57,7 @@ public function testSetCustomFontsFolder(): void
$options = new ImageOptions();
$options->setFontsFolder(self::FOLDER);
$image = (new Image('abcd', $options))->generate();
$this->assertStringStartsWith(self::DATAIMAGE, $image);
self::assertStringStartsWith(self::DATAIMAGE, $image);
}

public function testFontsDoesNotExist(): void
Expand All @@ -81,12 +81,13 @@ public function testSetLetterCase(int $case): void
->adjustFont('test.ttf', 32, $case);
$captcha = new Image('abcd', $options);
$image = $captcha->generate();
$this->assertStringStartsWith(self::DATAIMAGE, $image);
self::assertStringStartsWith(self::DATAIMAGE, $image);
}

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

Expand Down

0 comments on commit e76cb46

Please sign in to comment.