Skip to content

Commit 6f46267

Browse files
committed
Feature/Add tests for CriteriaSource interface methods and documentation
1 parent e4c8327 commit 6f46267

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use ComplexHeart\Domain\Criteria\Contracts\CriteriaSource;
6+
7+
test('CriteriaSource interface exists and is accessible', function () {
8+
expect(interface_exists(CriteriaSource::class))->toBeTrue();
9+
});
10+
11+
test('CriteriaSource interface has all required methods', function () {
12+
$reflection = new ReflectionClass(CriteriaSource::class);
13+
14+
$expectedMethods = [
15+
'filterGroups',
16+
'orderType',
17+
'orderBy',
18+
'pageLimit',
19+
'pageOffset',
20+
'pageNumber',
21+
];
22+
23+
foreach ($expectedMethods as $method) {
24+
expect($reflection->hasMethod($method))
25+
->toBeTrue("Method '{$method}' should exist in CriteriaSource interface");
26+
}
27+
});
28+
29+
test('CriteriaSource methods have correct return types', function () {
30+
$reflection = new ReflectionClass(CriteriaSource::class);
31+
32+
$methodReturnTypes = [
33+
'filterGroups' => 'array',
34+
'orderType' => 'string',
35+
'orderBy' => 'string',
36+
'pageLimit' => 'int',
37+
'pageOffset' => 'int',
38+
'pageNumber' => 'int',
39+
];
40+
41+
foreach ($methodReturnTypes as $methodName => $expectedType) {
42+
$method = $reflection->getMethod($methodName);
43+
expect($method->hasReturnType())->toBeTrue("Method {$methodName} should have return type");
44+
45+
$returnType = $method->getReturnType();
46+
expect($returnType)->not->toBeNull("Method {$methodName} return type should not be null");
47+
48+
if ($returnType instanceof ReflectionNamedType) {
49+
expect($returnType->getName())->toBe($expectedType, "Method {$methodName} should return {$expectedType}");
50+
}
51+
}
52+
});
53+
54+
test('CriteriaSource is an interface not a class', function () {
55+
$reflection = new ReflectionClass(CriteriaSource::class);
56+
57+
expect($reflection->isInterface())->toBeTrue()
58+
->and($reflection->isTrait())->toBeFalse();
59+
});
60+
61+
test('CriteriaSource interface has correct namespace', function () {
62+
expect(CriteriaSource::class)
63+
->toBe('ComplexHeart\Domain\Criteria\Contracts\CriteriaSource');
64+
});
65+
66+
test('CriteriaSource filterGroups method has correct docblock return type', function () {
67+
$reflection = new ReflectionClass(CriteriaSource::class);
68+
$method = $reflection->getMethod('filterGroups');
69+
70+
$docComment = $method->getDocComment();
71+
expect($docComment)->toContain('@return array<array<array<string, mixed>>>');
72+
});
73+
74+
test('CriteriaSource orderType method documents valid values', function () {
75+
$reflection = new ReflectionClass(CriteriaSource::class);
76+
$method = $reflection->getMethod('orderType');
77+
78+
$docComment = $method->getDocComment();
79+
expect($docComment)->toContain('asc, desc, none or random');
80+
});
81+
82+
test('CriteriaSource pageOffset method documents default behavior', function () {
83+
$reflection = new ReflectionClass(CriteriaSource::class);
84+
$method = $reflection->getMethod('pageOffset');
85+
86+
$docComment = $method->getDocComment();
87+
expect($docComment)->toContain('default should be 0');
88+
});
89+
90+
test('CriteriaSource pageNumber method documents offset computation', function () {
91+
$reflection = new ReflectionClass(CriteriaSource::class);
92+
$method = $reflection->getMethod('pageNumber');
93+
94+
$docComment = $method->getDocComment();
95+
expect($docComment)->toContain('used to compute the offset');
96+
});

0 commit comments

Comments
 (0)