Skip to content

Commit

Permalink
Constructor should use internal mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
henzeb committed Feb 16, 2022
1 parent af9a07e commit 35dc243
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/Concerns/Constructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 5 additions & 1 deletion tests/Fixtures/EnhancedEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/Concerns/MappersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,11 @@ public function testTryMakeArrayShouldMapWithoutMapperGiven()
EnhancedEnum::TryMakeArray(['anotherMappedEnum'])
);
}

public function testShouldUseMapperWhenConstructorIsUsed() {
$this->assertEquals(
EnhancedEnum::ENUM,
EnhancedEnum::anotherMappedEnum()
);
}
}

0 comments on commit 35dc243

Please sign in to comment.