diff --git a/src/Code.php b/src/Code.php index 6d75f87..e2fe7f7 100644 --- a/src/Code.php +++ b/src/Code.php @@ -38,7 +38,7 @@ public function __construct( ); } - if (empty($this->characterSet)) { + if ($this->characterSet === '') { throw new InvalidArgumentException( 'Character set cannot be empty' ); diff --git a/tests/unit/CodeTest.php b/tests/unit/CodeTest.php index 68f87a7..c123b0d 100644 --- a/tests/unit/CodeTest.php +++ b/tests/unit/CodeTest.php @@ -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')] diff --git a/tests/unit/ImageOptionsTest.php b/tests/unit/ImageOptionsTest.php index f68c215..6a6728f 100644 --- a/tests/unit/ImageOptionsTest.php +++ b/tests/unit/ImageOptionsTest.php @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/unit/ImageTest.php b/tests/unit/ImageTest.php index 7258dd0..159be67 100644 --- a/tests/unit/ImageTest.php +++ b/tests/unit/ImageTest.php @@ -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); } /** @@ -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); } /** @@ -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 @@ -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)); }