Skip to content

Commit 9fe6d95

Browse files
committed
test: reach full package coverage
1 parent fdad56b commit 9fe6d95

10 files changed

Lines changed: 129 additions & 14 deletions

File tree

tests/Calendar/MonthTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,19 @@ public function itIdentifiesQuarterEndMonths(): void
6363
#[Test]
6464
public function itDescribesMonths(): void
6565
{
66-
self::assertSame(
66+
self::assertSame([
6767
'Month 1 of the Gregorian calendar, commonly associated with yearly planning.',
68-
Month::January->description(),
69-
);
68+
'Month 2 of the Gregorian calendar, with 28 days or 29 in leap years.',
69+
'Month 3 of the Gregorian calendar, often used as the end of the first quarter.',
70+
'Month 4 of the Gregorian calendar, following the close of Q1 in many businesses.',
71+
'Month 5 of the Gregorian calendar, typically part of the second quarter.',
72+
'Month 6 of the Gregorian calendar and common end of the first half-year.',
73+
'Month 7 of the Gregorian calendar and common start of the second half-year.',
74+
'Month 8 of the Gregorian calendar, often used in summer scheduling contexts.',
75+
'Month 9 of the Gregorian calendar and common start of many annual cycles.',
76+
'Month 10 of the Gregorian calendar, typically within fourth-quarter planning.',
77+
'Month 11 of the Gregorian calendar, often used for year-end preparation.',
78+
'Month 12 of the Gregorian calendar and common close of fiscal or calendar years.',
79+
], array_map(static fn(Month $month): string => $month->description(), Month::cases()));
7080
}
7181
}

tests/Calendar/QuarterTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public function itResolvesAQuarterFromAMonth(): void
7474
#[Test]
7575
public function itDescribesQuarters(): void
7676
{
77-
self::assertSame('First quarter of the year, covering January through March.', Quarter::Q1->description());
77+
self::assertSame([
78+
'First quarter of the year, covering January through March.',
79+
'Second quarter of the year, covering April through June.',
80+
'Third quarter of the year, covering July through September.',
81+
'Fourth quarter of the year, covering October through December.',
82+
], array_map(static fn(Quarter $quarter): string => $quarter->description(), Quarter::cases()));
7883
}
7984
}

tests/Calendar/WeekdayTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ public function itKeepsIsoWeekOrder(): void
6363
#[Test]
6464
public function itDescribesWeekdays(): void
6565
{
66-
self::assertSame(
66+
self::assertSame([
6767
'First business day of the ISO week in most workflows and calendars.',
68-
Weekday::Monday->description(),
69-
);
68+
'Second day of the ISO week, commonly used for regular working schedules.',
69+
'Midweek day often used for routine meetings and delivery checkpoints.',
70+
'Late-week working day before typical end-of-week wrap-up.',
71+
'Final common business day before the weekend in many regions.',
72+
'Weekend day typically treated as non-working in standard business calendars.',
73+
'Weekend day that closes the ISO week and often precedes planning for Monday.',
74+
], array_map(static fn(Weekday $weekday): string => $weekday->description(), Weekday::cases()));
7075
}
7176
}

tests/Comparison/ComparisonOperatorTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ public function itNegatesOperators(): void
111111
#[Test]
112112
public function itDescribesOperators(): void
113113
{
114-
self::assertSame('Matches when both operands are strictly equal.', ComparisonOperator::Equal->description());
114+
self::assertSame([
115+
'Matches when both operands are strictly equal.',
116+
'Matches when both operands are not strictly equal.',
117+
'Matches when the left operand is greater than the right operand.',
118+
'Matches when the left operand is greater than or equal to the right operand.',
119+
'Matches when the left operand is less than the right operand.',
120+
'Matches when the left operand is less than or equal to the right operand.',
121+
'Matches when the left operand is contained in the right-hand candidate set.',
122+
'Matches when the left operand is not contained in the right-hand candidate set.',
123+
], array_map(
124+
static fn(ComparisonOperator $operator): string => $operator->description(),
125+
ComparisonOperator::cases(),
126+
));
115127
}
116128
}

tests/DateTime/IntervalUnitTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,14 @@ public function itIdentifiesCalendarAwareUnits(): void
6969
#[Test]
7070
public function itDescribesIntervalUnits(): void
7171
{
72-
self::assertSame(
72+
self::assertSame([
7373
'Represents one-second intervals for fine-grained timing and retry policies.',
74-
IntervalUnit::Second->description(),
75-
);
74+
'Represents one-minute intervals for short-lived scheduling and cache policies.',
75+
'Represents one-hour intervals for operational windows and batch execution.',
76+
'Represents one-day intervals for daily schedules and retention policies.',
77+
'Represents one-week intervals for weekly planning, reports, and cleanup jobs.',
78+
'Represents one-month intervals for monthly billing, reporting, and rotation schedules.',
79+
'Represents one-year intervals for annual cycles, compliance, and archival horizons.',
80+
], array_map(static fn(IntervalUnit $unit): string => $unit->description(), IntervalUnit::cases()));
7681
}
7782
}

tests/Helper/EnumHelperTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@
3636
#[UsesTrait(HasLabel::class)]
3737
final class EnumHelperTest extends TestCase
3838
{
39+
/**
40+
* @return void
41+
*/
42+
#[Test]
43+
public function itReturnsCasesForUnitEnums(): void
44+
{
45+
self::assertSame([Direction::North, Direction::South], EnumHelper::cases(Direction::class));
46+
self::assertSame([Direction::North, Direction::South], EnumHelper::cases(Direction::North));
47+
}
48+
3949
/**
4050
* @return void
4151
*/
@@ -98,6 +108,8 @@ public function itCanLookUpCasesByName(): void
98108
{
99109
self::assertSame(Direction::South, EnumHelper::fromName(Direction::class, 'South'));
100110
self::assertSame(Direction::North, EnumHelper::fromName(Direction::South, 'North'));
111+
self::assertTrue(EnumHelper::hasName(Direction::class, 'North'));
112+
self::assertFalse(EnumHelper::hasName(Direction::class, 'East'));
101113
self::assertNull(EnumHelper::tryFromName(Direction::class, 'East'));
102114
}
103115

tests/Logger/LogLevelTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ public function itKeepsLogLevelOrder(): void
6464
#[Test]
6565
public function itDescribesLogLevels(): void
6666
{
67-
self::assertSame(
67+
self::assertSame([
6868
'System is unusable and requires immediate global attention.',
69-
LogLevel::Emergency->description(),
70-
);
69+
'Action must be taken immediately to avoid severe service disruption.',
70+
'Critical condition indicating serious failure in a core capability.',
71+
'Runtime error indicating part of the current operation failed.',
72+
'Potential issue that should be reviewed before it becomes an error.',
73+
'Normal but noteworthy event that may deserve operational awareness.',
74+
'Informational event describing expected application flow.',
75+
'Verbose diagnostic information intended for debugging and development.',
76+
], array_map(static fn(LogLevel $level): string => $level->description(), LogLevel::cases()));
7177
}
7278
}

tests/Sort/SortDirectionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public function itProvidesNullsPositionHelpers(): void
7575
self::assertTrue(NullsPosition::Last->isLast());
7676
self::assertSame(-1, NullsPosition::First->compareNullability(null, 'value'));
7777
self::assertSame(1, NullsPosition::Last->compareNullability(null, 'value'));
78+
self::assertSame(0, NullsPosition::First->compareNullability(null, null));
79+
self::assertSame(1, NullsPosition::First->compareNullability('value', null));
80+
self::assertSame(-1, NullsPosition::Last->compareNullability('value', null));
7881
self::assertSame(0, NullsPosition::First->compareNullability('left', 'right'));
7982
}
8083

tests/StateMachine/HasTransitionsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use FastForward\Enum\StateMachine\HasTransitions;
2626
use FastForward\Enum\StateMachine\InvalidTransitionException;
2727
use FastForward\Enum\Tests\Support\ArticleWorkflow;
28+
use FastForward\Enum\Tests\Support\InferredWorkflow;
2829

2930
#[CoversTrait(HasTransitions::class)]
3031
#[CoversClass(InvalidTransitionException::class)]
@@ -48,6 +49,20 @@ public function itSupportsStateMachineStyleTransitions(): void
4849
);
4950
self::assertTrue(ArticleWorkflow::Draft->canTransitionTo(ArticleWorkflow::Reviewing));
5051
self::assertFalse(ArticleWorkflow::Draft->canTransitionTo(ArticleWorkflow::Published));
52+
53+
ArticleWorkflow::Draft->assertCanTransitionTo(ArticleWorkflow::Reviewing);
54+
}
55+
56+
/**
57+
* @return void
58+
*/
59+
#[Test]
60+
public function itInfersInitialStatesWhenNoInitialStateCasesAreConfigured(): void
61+
{
62+
self::assertSame([InferredWorkflow::Created], InferredWorkflow::initialStates());
63+
self::assertSame([InferredWorkflow::Completed], InferredWorkflow::terminalStates());
64+
self::assertTrue(InferredWorkflow::Created->isInitial());
65+
self::assertFalse(InferredWorkflow::Running->isInitial());
5166
}
5267

5368
/**

tests/Support/InferredWorkflow.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Ergonomic utilities for PHP enums, including names, values, lookups, and option maps.
7+
*
8+
* This file is part of fast-forward/enum project.
9+
*
10+
* @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
11+
* @license https://opensource.org/licenses/MIT MIT License
12+
*
13+
* @see https://github.com/php-fast-forward/enum
14+
* @see https://github.com/php-fast-forward/enum/issues
15+
* @see https://php-fast-forward.github.io/enum/
16+
* @see https://datatracker.ietf.org/doc/html/rfc2119
17+
*/
18+
19+
namespace FastForward\Enum\Tests\Support;
20+
21+
use FastForward\Enum\StateMachine\HasTransitions;
22+
23+
enum InferredWorkflow
24+
{
25+
use HasTransitions;
26+
27+
case Created;
28+
case Running;
29+
case Completed;
30+
31+
/**
32+
* @return array<string, list<self>>
33+
*/
34+
private static function transitionMap(): array
35+
{
36+
return [
37+
self::Created->name => [self::Running],
38+
self::Running->name => [self::Completed],
39+
self::Completed->name => [],
40+
];
41+
}
42+
}

0 commit comments

Comments
 (0)