diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c3b098..bd67582 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,14 @@ All notable changes to `Enumhancer` will be documented in this file +## 1.0.2 - 2022 02-16 + +- Bugfix: Constructor did not use internal mapper + ## 1.0.1 - 2022 02-16 - You can now define a mapper in a method -- When you use an empty string or null in mappable, it will return null now. +- When you use an empty string or null in mappable, it will return null now ## 1.0.0 - 2022-02-15 diff --git a/src/Concerns/Constructor.php b/src/Concerns/Constructor.php index 718c47b..f71da7b 100644 --- a/src/Concerns/Constructor.php +++ b/src/Concerns/Constructor.php @@ -8,6 +8,10 @@ trait Constructor { public static function __callStatic(string $name, array $arguments) { + if(method_exists(self::class, 'make')) { + return self::make($name); + } + return EnumMakers::make(self::class, $name); } } diff --git a/tests/Fixtures/EnhancedEnum.php b/tests/Fixtures/EnhancedEnum.php index 97bf16a..71c4f72 100644 --- a/tests/Fixtures/EnhancedEnum.php +++ b/tests/Fixtures/EnhancedEnum.php @@ -2,12 +2,16 @@ namespace Henzeb\Enumhancer\Tests\Fixtures; +use Henzeb\Enumhancer\Concerns\Constructor; use Henzeb\Enumhancer\Concerns\Enhancers; use Henzeb\Enumhancer\Contracts\Mapper; +/** + * @method static self anotherMappedEnum() + */ enum EnhancedEnum: string { - use Enhancers; + use Enhancers, Constructor; case ENUM = 'an enum'; case ANOTHER_ENUM = 'another enum'; diff --git a/tests/Unit/Concerns/MappersTest.php b/tests/Unit/Concerns/MappersTest.php index 28d6e91..1573b1e 100644 --- a/tests/Unit/Concerns/MappersTest.php +++ b/tests/Unit/Concerns/MappersTest.php @@ -180,4 +180,11 @@ public function testTryMakeArrayShouldMapWithoutMapperGiven() EnhancedEnum::TryMakeArray(['anotherMappedEnum']) ); } + + public function testShouldUseMapperWhenConstructorIsUsed() { + $this->assertEquals( + EnhancedEnum::ENUM, + EnhancedEnum::anotherMappedEnum() + ); + } }