From 48431dd32b3f73855f9463af41dba997a2962f9f Mon Sep 17 00:00:00 2001 From: Sam Light Date: Wed, 10 Jun 2026 19:00:32 +0100 Subject: Added more methods to the PathSegment class and tests --- tests/Unit/PathSegmentTest.php | 68 ++++++++++++++++++++++++++++++++++++++++++ tests/Unit/RouteTest.php | 2 +- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/PathSegmentTest.php (limited to 'tests') diff --git a/tests/Unit/PathSegmentTest.php b/tests/Unit/PathSegmentTest.php new file mode 100644 index 0000000..1d19e0e --- /dev/null +++ b/tests/Unit/PathSegmentTest.php @@ -0,0 +1,68 @@ +expect(fn () => new PathSegment('test')) + ->toBeInstanceOf(PathSegment::class); + +it('can get the content') + ->expect(fn () => (new PathSegment('test'))->getContent()) + ->toBe('test'); + +it('can get the parent') + ->expect(fn () => (new PathSegment( + 'test1', + new PathSegment('test2') + ))->getParent()) + ->toBeInstanceOf(PathSegment::class) + ->getContent()->toBe('test2'); + +it('has null parent by default') + ->expect(fn () => (new PathSegment('test'))->getParent()) + ->toBeNull(); + +$testChain = fn () => new PathSegment( + 'test3', + new PathSegment( + 'test2', + new PathSegment( + 'test1' + ) + ) +); + +it('can get all ancestors') + ->expect(fn () => $testChain()->getAncestors()) + ->toBeArray() + ->toContainOnlyInstancesOf(PathSegment::class) + ->toHaveCount(2); + +it('order all ancestors root first') + ->expect(fn () => $testChain()->getAncestors()) + ->{0}->getContent()->toBe('test1') + ->{1}->getContent()->toBe('test2'); + +it('can get all ancestors and self') + ->expect(fn () => $testChain()->getAncestorsAndSelf()) + ->toBeArray() + ->toContainOnlyInstancesOf(PathSegment::class) + ->toHaveCount(3); + +it('order all ancestors and self root first') + ->expect(fn () => $testChain()->getAncestorsAndSelf()) + ->{0}->getContent()->toBe('test1') + ->{1}->getContent()->toBe('test2') + ->{2}->getContent()->toBe('test3'); + +it('can have children')->todo(); + +it('can build full path')->todo(); + +it('can have routes')->todo(); + +it('can get routes by method')->todo(); + +it('can get routes for all methods')->todo(); diff --git a/tests/Unit/RouteTest.php b/tests/Unit/RouteTest.php index 5e3dc3b..0414649 100644 --- a/tests/Unit/RouteTest.php +++ b/tests/Unit/RouteTest.php @@ -13,4 +13,4 @@ it('initializes') HttpMethod::Get, fn () => null )) - ->toBeInstance(Route::class); + ->toBeInstanceOf(Route::class); -- cgit v1.2.3