diff --git a/README.md b/README.md
index c4e64d8..b31955c 100644
--- a/README.md
+++ b/README.md
@@ -191,6 +191,6 @@ $larvatar = Larvatar::make(
);
// optional settings
-$larvatar->avatar->setSymmetry(false);
-$larvatar->avatar->setPixels(8);
+$larvatar->identicon->setSymmetry(false);
+$larvatar->identicon->setPixels(8);
```
\ No newline at end of file
diff --git a/phpunit.xml b/phpunit.xml
index b6dc2bf..0f0c520 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -23,4 +23,9 @@
src
+
+
+
+
+
diff --git a/src/Avatar.php b/src/Avatar.php
index 6985159..466d232 100644
--- a/src/Avatar.php
+++ b/src/Avatar.php
@@ -5,19 +5,13 @@
namespace Renfordt\Larvatar;
use Exception;
-use Renfordt\Larvatar\Enum\FormTypes;
abstract class Avatar
{
- protected int $fontSize = 0;
-
- protected string $fontFamily = '';
- protected string $fontPath = '';
- protected string $fontWeight = 'normal';
protected Name $name;
protected int $size = 100;
protected float $backgroundLightness = 0.8;
- protected float $textLightness = 0.35;
+ protected float $foregroundLightness = 0.35;
/**
* Retrieves the HTML representation of the data.
@@ -35,66 +29,6 @@ abstract public function getHTML(bool $base64 = false): string;
*/
abstract public function getBase64(): string;
- /**
- * Get the font size
- *
- * @return int The font size value
- */
- public function getFontSize(): int
- {
- return $this->fontSize;
- }
-
- /**
- * Set the font size.
- *
- * @param int $fontSize The font size.
- */
- public function setFontSize(int $fontSize): void
- {
- $this->fontSize = $fontSize;
- }
-
- /**
- * Get the font family
- *
- * @return string The font family
- */
- public function getFontFamily(): string
- {
- return $this->fontFamily;
- }
-
- /**
- * Set the font family for the application
- *
- * @param string $fontFamily The font family to set
- */
- public function setFontFamily(string $fontFamily): void
- {
- $this->fontFamily = $fontFamily;
- }
-
- /**
- * Get the font path
- *
- * @return string The font path
- */
- public function getFontPath(): string
- {
- return $this->fontPath;
- }
-
- /**
- * Set the font path
- *
- * @param string $fontPath The path to the font
- */
- public function setFontPath(string $fontPath): void
- {
- $this->fontPath = $fontPath;
- }
-
/**
* Get the name of the object
*
@@ -139,43 +73,23 @@ public function setBackgroundLightness(float $backgroundLightness): void
}
/**
- * Get the lightness value of the text
+ * Retrieves the lightness level of the foreground.
*
- * @return float The lightness value of the text
+ * @return float The lightness value of the foreground
*/
- public function getTextLightness(): float
+ public function getForegroundLightness(): float
{
- return $this->textLightness;
+ return $this->foregroundLightness;
}
/**
- * Set the text lightness value
+ * Sets the lightness value of the foreground within a specified range.
*
- * @param float $textLightness The text lightness value to be set
+ * @param float $foregroundLightness The desired lightness value, a float between 0 and 1.
*/
- public function setTextLightness(float $textLightness): void
+ public function setForegroundLightness(float $foregroundLightness): void
{
- $this->textLightness = (float)clamp($textLightness, 0, 1);
- }
-
- /**
- * Get the font weight
- *
- * @return string The font weight
- */
- public function getFontWeight(): string
- {
- return $this->fontWeight;
- }
-
- /**
- * Set the font weight for the application
- *
- * @param string $fontWeight The font weight to set
- */
- public function setFontWeight(string $fontWeight): void
- {
- $this->fontWeight = $fontWeight;
+ $this->foregroundLightness = (float)clamp($foregroundLightness, 0, 1);
}
/**
@@ -197,34 +111,4 @@ public function setSize(int $size): void
{
$this->size = $size;
}
-
- /**
- * Sets the font family and path
- *
- * @param string $font The font family
- * @param string $path The font path
- */
- public function setFont(string $font, string $path): void
- {
- $this->setFontFamily($font);
- $this->setFontPath($path);
- }
-
- public function setSymmetry(bool $symmetry): void
- {
- }
-
- public function setPixels(int $pixels): void
- {
- }
-
- public function setForm(string|FormTypes $form): void
- {
- }
-
- public function setRotation(int $angle): void
- {
- }
-
-
}
diff --git a/src/InitialsAvatar.php b/src/InitialsAvatar.php
index 66a36b3..97e814d 100644
--- a/src/InitialsAvatar.php
+++ b/src/InitialsAvatar.php
@@ -17,6 +17,10 @@ class InitialsAvatar extends Avatar
{
use ColorTrait;
+ protected int $fontSize = 0;
+ protected string $fontFamily = '';
+ protected string $fontPath = '';
+ protected string $fontWeight = 'normal';
private FormTypes $form = FormTypes::Circle;
private int $rotation = 0;
private int $offset = 0;
@@ -120,7 +124,7 @@ public function generate(): SVG
*/
[$darkColor, $lightColor] = $this->getColorSet(
$this->name,
- $this->textLightness,
+ $this->foregroundLightness,
$this->backgroundLightness
);
@@ -249,4 +253,116 @@ public function getBase64(): string
{
return 'data:image/svg+xml;base64,' . base64_encode($this->generate()->__toString());
}
+
+ /**
+ * Get the font size
+ *
+ * @return int The font size value
+ */
+ public function getFontSize(): int
+ {
+ return $this->fontSize;
+ }
+
+ /**
+ * Set the font size.
+ *
+ * @param int $fontSize The font size.
+ */
+ public function setFontSize(int $fontSize): void
+ {
+ $this->fontSize = $fontSize;
+ }
+
+ /**
+ * Get the font family
+ *
+ * @return string The font family
+ */
+ public function getFontFamily(): string
+ {
+ return $this->fontFamily;
+ }
+
+ /**
+ * Set the font family for the application
+ *
+ * @param string $fontFamily The font family to set
+ */
+ public function setFontFamily(string $fontFamily): void
+ {
+ $this->fontFamily = $fontFamily;
+ }
+
+ /**
+ * Get the font path
+ *
+ * @return string The font path
+ */
+ public function getFontPath(): string
+ {
+ return $this->fontPath;
+ }
+
+ /**
+ * Set the font path
+ *
+ * @param string $fontPath The path to the font
+ */
+ public function setFontPath(string $fontPath): void
+ {
+ $this->fontPath = $fontPath;
+ }
+
+ /**
+ * Get the font weight
+ *
+ * @return string The font weight
+ */
+ public function getFontWeight(): string
+ {
+ return $this->fontWeight;
+ }
+
+ /**
+ * Set the font weight for the application
+ *
+ * @param string $fontWeight The font weight to set
+ */
+ public function setFontWeight(string $fontWeight): void
+ {
+ $this->fontWeight = $fontWeight;
+ }
+
+ /**
+ * Sets the font family and path
+ *
+ * @param string $font The font family
+ * @param string $path The font path
+ */
+ public function setFont(string $font, string $path): void
+ {
+ $this->setFontFamily($font);
+ $this->setFontPath($path);
+ }
+
+ /**
+ * Get the lightness value of the text
+ *
+ * @return float The lightness value of the text
+ */
+ public function getTextLightness(): float
+ {
+ return $this->foregroundLightness;
+ }
+
+ /**
+ * Set the text lightness value
+ *
+ * @param float $textLightness The text lightness value to be set
+ */
+ public function setTextLightness(float $textLightness): void
+ {
+ $this->foregroundLightness = (float)clamp($textLightness, 0, 1);
+ }
}
diff --git a/src/Larvatar.php b/src/Larvatar.php
index 2d36f6a..bbe595f 100644
--- a/src/Larvatar.php
+++ b/src/Larvatar.php
@@ -4,11 +4,17 @@
namespace Renfordt\Larvatar;
+use Exception;
use Renfordt\Larvatar\Enum\LarvatarTypes;
class Larvatar
{
- public Avatar $avatar;
+ /**
+ * @deprecated 2.0.2
+ */
+ public Avatar|Identicon|InitialsAvatar $avatar;
+ public InitialsAvatar $initialsAvatar;
+ public Identicon $identicon;
protected LarvatarTypes $type = LarvatarTypes::mp;
protected Name $name;
protected string $email;
@@ -32,10 +38,12 @@ public function __construct(LarvatarTypes $type, string|Name $name = '', string
$this->email = $email;
$this->type = $type;
- if ($this->type == LarvatarTypes::InitialsAvatar) {
+ if ($this->type === LarvatarTypes::InitialsAvatar) {
$this->avatar = InitialsAvatar::make($this->name);
- } elseif ($this->type == LarvatarTypes::IdenticonLarvatar) {
+ $this->initialsAvatar = InitialsAvatar::make($this->name);
+ } elseif ($this->type === LarvatarTypes::IdenticonLarvatar) {
$this->avatar = Identicon::make($this->name);
+ $this->identicon = Identicon::make($this->name);
}
}
@@ -74,15 +82,21 @@ public static function create(
/**
* Generates the HTML or SVG code directly for usage
* @return string HTML or SVG code
+ * @throws Exception
*/
public function getImageHTML(bool $base64 = false): string
{
- if ($this->type == LarvatarTypes::InitialsAvatar || $this->type == LarvatarTypes::IdenticonLarvatar) {
+ if ($this->type === LarvatarTypes::InitialsAvatar) {
if (isset($this->font) && $this->font !== '' && $this->fontPath !== '') {
- $this->avatar->setFont($this->font, $this->fontPath);
+ $this->initialsAvatar->setFont($this->font, $this->fontPath);
}
- $this->avatar->setSize($this->size);
- return $this->avatar->getHTML($base64);
+ $this->initialsAvatar->setSize($this->size);
+ return $this->initialsAvatar->getHTML($base64);
+ }
+
+ if ($this->type === LarvatarTypes::IdenticonLarvatar) {
+ $this->identicon->setSize($this->size);
+ return $this->identicon->getHTML($base64);
}
$gravatar = new Gravatar($this->email);
@@ -92,17 +106,6 @@ public function getImageHTML(bool $base64 = false): string
return '';
}
- /**
- * Set the font for Initial Avatar
- * @param string $fontFamily Font family of the used font, e.g. 'Roboto'
- * @param string $path Relative path to the true type font file, starting with a /, e.g. '/font/Roboto-Bold.ttf'
- */
- public function setFont(string $fontFamily, string $path): void
- {
- $this->font = $fontFamily;
- $this->fontPath = $path;
- }
-
/**
* Sets the size of the object.
*
@@ -120,7 +123,29 @@ public function setSize(int $size): void
*/
public function getBase64(): string
{
- return $this->avatar->getBase64();
+ if ($this->type === LarvatarTypes::InitialsAvatar) {
+ return $this->initialsAvatar->getBase64();
+ }
+
+ if ($this->type === LarvatarTypes::IdenticonLarvatar) {
+ return $this->identicon->getBase64();
+ }
+
+ return '';
+ }
+
+ /**
+ * Set the font for Initial Avatar
+ * @param string $fontFamily Font family of the used font, e.g. 'Roboto'
+ * @param string $path Relative path to the true type font file, starting with a /, e.g. '/font/Roboto-Bold.ttf'
+ */
+ public function setFont(string $fontFamily, string $path): void
+ {
+ if ($this->type !== LarvatarTypes::InitialsAvatar) {
+ return;
+ }
+ $this->font = $fontFamily;
+ $this->fontPath = $path;
}
/**
@@ -130,10 +155,10 @@ public function getBase64(): string
*/
public function setWeight(string $weight): void
{
- if (!isset($this->avatar)) {
+ if ($this->type !== LarvatarTypes::InitialsAvatar) {
return;
}
- $this->avatar->setFontWeight($weight);
+ $this->initialsAvatar->setFontWeight($weight);
}
/**
@@ -143,7 +168,26 @@ public function setWeight(string $weight): void
*/
public function setFontLightness(float $lightness): void
{
- $this->avatar->setTextLightness($lightness);
+ if ($this->type !== LarvatarTypes::InitialsAvatar) {
+ return;
+ }
+ $this->initialsAvatar->setTextLightness($lightness);
+ }
+
+ /**
+ * Set the lightness value for the foreground of the avatar.
+ *
+ * @param float $lightness The lightness value to be set for the foreground.
+ */
+ public function setForegroundLightness(float $lightness): void
+ {
+ if ($this->type === LarvatarTypes::InitialsAvatar) {
+ $this->initialsAvatar->setForegroundLightness($lightness);
+ }
+
+ if ($this->type === LarvatarTypes::IdenticonLarvatar) {
+ $this->identicon->setForegroundLightness($lightness);
+ }
}
/**
@@ -153,6 +197,12 @@ public function setFontLightness(float $lightness): void
*/
public function setBackgroundLightness(float $lightness): void
{
- $this->avatar->setBackgroundLightness($lightness);
+ if ($this->type === LarvatarTypes::InitialsAvatar) {
+ $this->initialsAvatar->setBackgroundLightness($lightness);
+ }
+
+ if ($this->type === LarvatarTypes::IdenticonLarvatar) {
+ $this->identicon->setBackgroundLightness($lightness);
+ }
}
}
diff --git a/tests/AvatarTest.php b/tests/AvatarTest.php
index 3424faa..8aaf45b 100644
--- a/tests/AvatarTest.php
+++ b/tests/AvatarTest.php
@@ -4,14 +4,18 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Renfordt\Larvatar\Avatar;
+use Renfordt\Larvatar\InitialsAvatar;
use Renfordt\Larvatar\Name;
/**
* Unit tests for the Avatar class.
*/
#[CoversClass(Avatar::class)]
+#[UsesClass(InitialsAvatar::class)]
+#[UsesClass(Name::class)]
class AvatarTest extends TestCase
{
public static function fontDataProvider(): array
@@ -95,10 +99,10 @@ public static function sizeProvider(): array
#[DataProvider('fontDataProvider')]
public function testFontMethods(string $font, string $path): void
{
- $mock = $this->getMockForAbstractClass(Avatar::class);
- $mock->setFont($font, $path);
- $this->assertEquals($font, $mock->getFontFamily());
- $this->assertEquals($path, $mock->getFontPath());
+ $initialsAvatar = new InitialsAvatar(Name::create('John Doe'));
+ $initialsAvatar->setFont($font, $path);
+ $this->assertEquals($font, $initialsAvatar->getFontFamily());
+ $this->assertEquals($path, $initialsAvatar->getFontPath());
}
/**
@@ -108,9 +112,9 @@ public function testFontMethods(string $font, string $path): void
#[DataProvider('backgroundLightnessProvider')]
public function testBackgroundLightnessMethods(float|int $input, float|int $expected): void
{
- $mock = $this->getMockForAbstractClass(Avatar::class);
- $mock->setBackgroundLightness($input);
- $this->assertEquals($expected, $mock->getBackgroundLightness());
+ $initialsAvatar = new InitialsAvatar(Name::create('John Doe'));
+ $initialsAvatar->setBackgroundLightness($input);
+ $this->assertEquals($expected, $initialsAvatar->getBackgroundLightness());
}
/**
@@ -120,9 +124,9 @@ public function testBackgroundLightnessMethods(float|int $input, float|int $expe
#[DataProvider('textLightnessProvider')]
public function testTextLightnessMethods(int|float $input, int|float $expected): void
{
- $mock = $this->getMockForAbstractClass(Avatar::class);
- $mock->setTextLightness($input);
- $this->assertEquals($expected, $mock->getTextLightness());
+ $initialsAvatar = new InitialsAvatar(Name::create('John Doe'));
+ $initialsAvatar->setTextLightness($input);
+ $this->assertEquals($expected, $initialsAvatar->getTextLightness());
}
/**
@@ -132,9 +136,9 @@ public function testTextLightnessMethods(int|float $input, int|float $expected):
#[DataProvider('nameProvider')]
public function testNameMethods(\Renfordt\Larvatar\Name|string $name, string $expected): void
{
- $mock = $this->getMockForAbstractClass(Avatar::class);
- $mock->setName($name);
- $this->assertEquals($expected, $mock->getName()->getName());
+ $initialsAvatar = new InitialsAvatar(Name::create('John Doe'));
+ $initialsAvatar->setName($name);
+ $this->assertEquals($expected, $initialsAvatar->getName()->getName());
}
/**
@@ -144,9 +148,9 @@ public function testNameMethods(\Renfordt\Larvatar\Name|string $name, string $ex
#[DataProvider('fontSizeProvider')]
public function testFontSizeMethods(int $input): void
{
- $mock = $this->getMockForAbstractClass(Avatar::class);
- $mock->setFontSize($input);
- $this->assertEquals($input, $mock->getFontSize());
+ $initialsAvatar = new InitialsAvatar(Name::create('John Doe'));
+ $initialsAvatar->setFontSize($input);
+ $this->assertEquals($input, $initialsAvatar->getFontSize());
}
/**
@@ -156,9 +160,9 @@ public function testFontSizeMethods(int $input): void
#[DataProvider('fontWeightProvider')]
public function testFontWeightMethods(string $input): void
{
- $mock = $this->getMockForAbstractClass(Avatar::class);
- $mock->setFontWeight($input);
- $this->assertEquals($input, $mock->getFontWeight());
+ $initialsAvatar = new InitialsAvatar(Name::create('John Doe'));
+ $initialsAvatar->setFontWeight($input);
+ $this->assertEquals($input, $initialsAvatar->getFontWeight());
}
/**
@@ -168,8 +172,8 @@ public function testFontWeightMethods(string $input): void
#[DataProvider('sizeProvider')]
public function testSizeMethods(int $input): void
{
- $mock = $this->getMockForAbstractClass(Avatar::class);
- $mock->setSize($input);
- $this->assertEquals($input, $mock->getSize());
+ $initialsAvatar = new InitialsAvatar(Name::create('John Doe'));
+ $initialsAvatar->setSize($input);
+ $this->assertEquals($input, $initialsAvatar->getSize());
}
}
diff --git a/tests/IdenticonTest.php b/tests/IdenticonTest.php
index fe412ef..4ac9a35 100644
--- a/tests/IdenticonTest.php
+++ b/tests/IdenticonTest.php
@@ -3,11 +3,13 @@
declare(strict_types=1);
use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Renfordt\Larvatar\Identicon;
use Renfordt\Larvatar\Name;
#[CoversClass(Identicon::class)]
+#[UsesClass(Name::class)]
class IdenticonTest extends TestCase
{
/**
diff --git a/tests/InitialsAvatarTest.php b/tests/InitialsAvatarTest.php
index b388e65..5213744 100644
--- a/tests/InitialsAvatarTest.php
+++ b/tests/InitialsAvatarTest.php
@@ -3,6 +3,7 @@
declare(strict_types=1);
use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Renfordt\Colors\HexColor;
use Renfordt\Larvatar\Enum\FormTypes;
@@ -12,6 +13,7 @@
use SVG\Nodes\Shapes\SVGRect;
#[CoversClass(InitialsAvatar::class)]
+#[UsesClass(Name::class)]
final class InitialsAvatarTest extends TestCase
{
/**
@@ -28,6 +30,30 @@ public function testGenerateDefault(): void
);
}
+ public function testGetHTML(): void
+ {
+ $name = Name::make('Test Name');
+ $initialsAvatar = InitialsAvatar::make($name);
+
+ $this->assertEquals(
+ '',
+ $initialsAvatar->getHTML()
+ );
+ }
+
+ public function testGetHTMLWithEncryption(): void
+ {
+ $name = Name::make('Test Name');
+ $initialsAvatar = InitialsAvatar::make($name);
+
+ $this->assertEquals(
+ '',
+ $initialsAvatar->getHTML(true)
+ );
+ }
+
+
+
/**
* Tests the generate method with square form.
*/
@@ -110,6 +136,8 @@ public function testSetFont(): void
'',
$initialsAvatar->generate()
);
+ $this->assertEquals('/../src/font/Roboto-Bold.ttf', $initialsAvatar->getFontPath());
+ $this->assertEquals('Roboto', $initialsAvatar->getFontFamily());
}
public function testSetSize(): void
@@ -123,6 +151,18 @@ public function testSetSize(): void
);
}
+ public function testSetFontSize(): void
+ {
+ $name = Name::make('Test Name');
+ $initialsAvatar = InitialsAvatar::make($name);
+ $initialsAvatar->setFontSize(50);
+ $this->assertEquals(
+ '',
+ $initialsAvatar->generate()
+ );
+ $this->assertEquals(50, $initialsAvatar->getFontSize());
+ }
+
public function testGenerateWithBase64(): void
{
$name = Name::make('Test Name');
@@ -233,10 +273,8 @@ public function testSetFontWeight(): void
$name = Name::make('Test Name');
$initialsAvatar = InitialsAvatar::make($name);
$initialsAvatar->setFontWeight('bold');
- $reflector = new ReflectionObject($initialsAvatar);
- $property = $reflector->getProperty('fontWeight');
- $property->setAccessible(true);
- $this->assertEquals('bold', $property->getValue($initialsAvatar));
+
+ $this->assertEquals('bold', $initialsAvatar->getFontWeight());
}
public function testGetBackgroundLightnessDefaultValue(): void
diff --git a/tests/LarvatarTest.php b/tests/LarvatarTest.php
index 1718d64..f7c9d91 100644
--- a/tests/LarvatarTest.php
+++ b/tests/LarvatarTest.php
@@ -3,13 +3,44 @@
declare(strict_types=1);
use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Renfordt\Larvatar\Enum\LarvatarTypes;
+use Renfordt\Larvatar\Gravatar;
+use Renfordt\Larvatar\Identicon;
+use Renfordt\Larvatar\InitialsAvatar;
use Renfordt\Larvatar\Larvatar;
+use Renfordt\Larvatar\Name;
+use Renfordt\Larvatar\Traits\ColorTrait;
#[CoversClass(Larvatar::class)]
+#[UsesClass(Gravatar::class)]
+#[UsesClass(Name::class)]
+#[UsesClass(InitialsAvatar::class)]
+#[UsesClass(Identicon::class)]
+#[UsesClass(ColorTrait::class)]
class LarvatarTest extends TestCase
{
+ public function testCreateLarvatarWithAllTypes(): void
+ {
+ foreach (LarvatarTypes::cases() as $type) {
+ $larvatar = Larvatar::create($type, 'Test Name', 'test@example.com');
+ $larvatar->setSize(100);
+ $larvatar->setWeight('bold');
+ $larvatar->setFontLightness(0.5);
+ $larvatar->setForegroundLightness(0.5);
+ $larvatar->setBackgroundLightness(0.5);
+ $larvatar->setFont('Roboto', '/../src/font/Roboto-Bold.ttf');
+
+ $this->assertNotEmpty($larvatar->getImageHTML());
+ if ($type === LarvatarTypes::InitialsAvatar || $type === LarvatarTypes::IdenticonLarvatar) {
+ $this->assertNotEmpty($larvatar->getBase64());
+ } else {
+ $this->assertEmpty($larvatar->getBase64());
+ }
+ }
+ }
+
public function testCreateLarvatar(): void
{
$larvatar = new Larvatar(LarvatarTypes::InitialsAvatar, 'Test Name', 'test@example.com');
@@ -21,7 +52,7 @@ public function testCreateLarvatar(): void
public function testCreateLarvatarWithMake(): void
{
- $larvatar = Larvatar::make(LarvatarTypes::InitialsAvatar, 'Test Name', 'test@example.com');
+ $larvatar = Larvatar::make(LarvatarTypes::InitialsAvatar, 'Test Name', 'test@example.com');
$this->assertEquals(
'',
$larvatar->getImageHTML()
@@ -30,7 +61,7 @@ public function testCreateLarvatarWithMake(): void
public function testCreateLarvatarWithCreate(): void
{
- $larvatar = Larvatar::create(LarvatarTypes::InitialsAvatar, 'Test Name', 'test@example.com');
+ $larvatar = Larvatar::create(LarvatarTypes::InitialsAvatar, 'Test Name', 'test@example.com');
$this->assertEquals(
'',
$larvatar->getImageHTML()
@@ -40,7 +71,7 @@ public function testCreateLarvatarWithCreate(): void
public function testCreateLarvatarWithName(): void
{
$name = \Renfordt\Larvatar\Name::make('Test Name');
- $larvatar = Larvatar::create(LarvatarTypes::InitialsAvatar, $name, 'test@example.com');
+ $larvatar = Larvatar::create(LarvatarTypes::InitialsAvatar, $name, 'test@example.com');
$this->assertEquals(
'',
$larvatar->getImageHTML()
@@ -49,10 +80,6 @@ public function testCreateLarvatarWithName(): void
public function testCreateLarvatarException(): void
{
- set_error_handler(static function (int $errno, string $errstr): never {
- throw new Exception($errstr, $errno);
- }, E_USER_WARNING);
-
$this->expectExceptionMessage('must be of type Renfordt\Larvatar\Enum\LarvatarTypes');
new Larvatar(700, 'Test Name', 'test@example.com');
diff --git a/tests/Traits/LarvatarTraitTest.php b/tests/Traits/LarvatarTraitTest.php
index 39b6525..901009c 100644
--- a/tests/Traits/LarvatarTraitTest.php
+++ b/tests/Traits/LarvatarTraitTest.php
@@ -6,11 +6,26 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
+use Renfordt\Larvatar\Avatar;
use Renfordt\Larvatar\Enum\LarvatarTypes;
+use Renfordt\Larvatar\Gravatar;
+use Renfordt\Larvatar\Identicon;
+use Renfordt\Larvatar\InitialsAvatar;
+use Renfordt\Larvatar\Larvatar;
+use Renfordt\Larvatar\Name;
+use Renfordt\Larvatar\Traits\ColorTrait;
use Renfordt\Larvatar\Traits\LarvatarTrait;
#[CoversClass(LarvatarTrait::class)]
+#[UsesClass(Avatar::class)]
+#[UsesClass(InitialsAvatar::class)]
+#[UsesClass(Identicon::class)]
+#[UsesClass(Larvatar::class)]
+#[UsesClass(Name::class)]
+#[UsesClass(ColorTrait::class)]
+#[UsesClass(Gravatar::class)]
class LarvatarTraitTest extends TestCase
{
use LarvatarTrait;