31 - Add domain enums
This commit is contained in:
parent
1b1d9db626
commit
59807d8e33
7 changed files with 136 additions and 0 deletions
10
src/Enum/BucketAllocationType.php
Normal file
10
src/Enum/BucketAllocationType.php
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enum;
|
||||||
|
|
||||||
|
enum BucketAllocationType: string
|
||||||
|
{
|
||||||
|
case FIXED_LIMIT = 'fixed_limit';
|
||||||
|
case PERCENTAGE = 'percentage';
|
||||||
|
case UNLIMITED = 'unlimited';
|
||||||
|
}
|
||||||
26
src/Enum/BucketType.php
Normal file
26
src/Enum/BucketType.php
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enum;
|
||||||
|
|
||||||
|
enum BucketType: string
|
||||||
|
{
|
||||||
|
case NEED = 'need';
|
||||||
|
case WANT = 'want';
|
||||||
|
case OVERFLOW = 'overflow';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<BucketAllocationType>
|
||||||
|
*/
|
||||||
|
public function getAllowedAllocationTypes(): array
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::NEED, self::WANT => [
|
||||||
|
BucketAllocationType::FIXED_LIMIT,
|
||||||
|
BucketAllocationType::PERCENTAGE,
|
||||||
|
],
|
||||||
|
self::OVERFLOW => [
|
||||||
|
BucketAllocationType::UNLIMITED,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/Enum/DistributionMode.php
Normal file
9
src/Enum/DistributionMode.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enum;
|
||||||
|
|
||||||
|
enum DistributionMode: string
|
||||||
|
{
|
||||||
|
case EVEN = 'even';
|
||||||
|
case PRIORITY = 'priority';
|
||||||
|
}
|
||||||
14
src/Enum/StreamFrequency.php
Normal file
14
src/Enum/StreamFrequency.php
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enum;
|
||||||
|
|
||||||
|
enum StreamFrequency: string
|
||||||
|
{
|
||||||
|
case ONCE = 'once';
|
||||||
|
case DAILY = 'daily';
|
||||||
|
case WEEKLY = 'weekly';
|
||||||
|
case BIWEEKLY = 'biweekly';
|
||||||
|
case MONTHLY = 'monthly';
|
||||||
|
case QUARTERLY = 'quarterly';
|
||||||
|
case YEARLY = 'yearly';
|
||||||
|
}
|
||||||
9
src/Enum/StreamType.php
Normal file
9
src/Enum/StreamType.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enum;
|
||||||
|
|
||||||
|
enum StreamType: string
|
||||||
|
{
|
||||||
|
case INCOME = 'income';
|
||||||
|
case EXPENSE = 'expense';
|
||||||
|
}
|
||||||
32
tests/Enum/BucketTypeTest.php
Normal file
32
tests/Enum/BucketTypeTest.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tests\Enum;
|
||||||
|
|
||||||
|
use App\Enum\BucketAllocationType;
|
||||||
|
use App\Enum\BucketType;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class BucketTypeTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testBucketTypeCasesAndAllowedAllocationTypes(): void
|
||||||
|
{
|
||||||
|
$this->assertSame('need', BucketType::NEED->value);
|
||||||
|
$this->assertSame('want', BucketType::WANT->value);
|
||||||
|
$this->assertSame('overflow', BucketType::OVERFLOW->value);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[BucketAllocationType::FIXED_LIMIT, BucketAllocationType::PERCENTAGE],
|
||||||
|
BucketType::NEED->getAllowedAllocationTypes(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[BucketAllocationType::FIXED_LIMIT, BucketAllocationType::PERCENTAGE],
|
||||||
|
BucketType::WANT->getAllowedAllocationTypes(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[BucketAllocationType::UNLIMITED],
|
||||||
|
BucketType::OVERFLOW->getAllowedAllocationTypes(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
tests/Enum/RemainingEnumsTest.php
Normal file
36
tests/Enum/RemainingEnumsTest.php
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tests\Enum;
|
||||||
|
|
||||||
|
use App\Enum\BucketAllocationType;
|
||||||
|
use App\Enum\DistributionMode;
|
||||||
|
use App\Enum\StreamFrequency;
|
||||||
|
use App\Enum\StreamType;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class RemainingEnumsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRemainingEnumsExposeExpectedCases(): void
|
||||||
|
{
|
||||||
|
$this->assertSame('once', StreamFrequency::ONCE->value);
|
||||||
|
$this->assertSame('daily', StreamFrequency::DAILY->value);
|
||||||
|
$this->assertSame('weekly', StreamFrequency::WEEKLY->value);
|
||||||
|
$this->assertSame('biweekly', StreamFrequency::BIWEEKLY->value);
|
||||||
|
$this->assertSame('monthly', StreamFrequency::MONTHLY->value);
|
||||||
|
$this->assertSame('quarterly', StreamFrequency::QUARTERLY->value);
|
||||||
|
$this->assertSame('yearly', StreamFrequency::YEARLY->value);
|
||||||
|
|
||||||
|
$this->assertSame('income', StreamType::INCOME->value);
|
||||||
|
$this->assertSame('expense', StreamType::EXPENSE->value);
|
||||||
|
|
||||||
|
$this->assertSame('even', DistributionMode::EVEN->value);
|
||||||
|
$this->assertSame('priority', DistributionMode::PRIORITY->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBucketAllocationTypeBackingValues(): void
|
||||||
|
{
|
||||||
|
$this->assertSame('fixed_limit', BucketAllocationType::FIXED_LIMIT->value);
|
||||||
|
$this->assertSame('percentage', BucketAllocationType::PERCENTAGE->value);
|
||||||
|
$this->assertSame('unlimited', BucketAllocationType::UNLIMITED->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue