Skip to content

Commit 8c33846

Browse files
committed
improved phpDoc
1 parent 04a8e40 commit 8c33846

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

src/Framework/DataProvider.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212

1313
/**
14-
* Data provider helpers.
14+
* Utility class for providing data from various sources for tests.
1515
* @internal
1616
*/
1717
class DataProvider
1818
{
1919
/**
20-
* @throws \Exception
20+
* Loads data from a specified file and filters them based on a query string. Supports both PHP files and INI files.
2121
*/
2222
public static function load(string $file, string $query = ''): array
2323
{
@@ -50,6 +50,9 @@ public static function load(string $file, string $query = ''): array
5050
}
5151

5252

53+
/**
54+
* Evaluates a query against a set of data keys to determine if the key matches the criteria.
55+
*/
5356
public static function testQuery(string $input, string $query): bool
5457
{
5558
$replaces = ['' => '=', '=>' => '>=', '=<' => '<='];
@@ -70,6 +73,9 @@ public static function testQuery(string $input, string $query): bool
7073
}
7174

7275

76+
/**
77+
* Compares two values using the specified operator.
78+
*/
7379
private static function compare(mixed $l, string $operator, mixed $r): bool
7480
{
7581
return match ($operator) {
@@ -85,7 +91,7 @@ private static function compare(mixed $l, string $operator, mixed $r): bool
8591

8692

8793
/**
88-
* @throws \Exception
94+
* Parses a data provider annotation from a test method to extract the file path and query.
8995
*/
9096
public static function parseAnnotation(string $annotation, string $file): array
9197
{

src/Framework/DomQuery.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
class DomQuery extends \SimpleXMLElement
1717
{
18+
/**
19+
* Creates a DomQuery object from an HTML string.
20+
*/
1821
public static function fromHtml(string $html): self
1922
{
2023
if (!str_contains($html, '<')) {
@@ -48,14 +51,17 @@ public static function fromHtml(string $html): self
4851
}
4952

5053

54+
/**
55+
* Creates a DomQuery object from an XML string.
56+
*/
5157
public static function fromXml(string $xml): self
5258
{
5359
return simplexml_load_string($xml, self::class);
5460
}
5561

5662

5763
/**
58-
* Returns array of descendants filtered by a selector.
64+
* Finds descendants of current element that match the given CSS selector.
5965
* @return DomQuery[]
6066
*/
6167
public function find(string $selector): array
@@ -65,7 +71,7 @@ public function find(string $selector): array
6571

6672

6773
/**
68-
* Check the current document against a selector.
74+
* Checks if any descendant of current element matches the given selector.
6975
*/
7076
public function has(string $selector): bool
7177
{
@@ -74,7 +80,7 @@ public function has(string $selector): bool
7480

7581

7682
/**
77-
* Transforms CSS expression to XPath.
83+
* Converts a CSS selector into an XPath expression.
7884
*/
7985
public static function css2xpath(string $css): string
8086
{

src/Framework/TestCase.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestCase
2727

2828

2929
/**
30-
* Runs the test case.
30+
* Runs all test methods in this test case or a specific test method if provided.
3131
*/
3232
public function run(): void
3333
{
@@ -69,8 +69,8 @@ public function run(): void
6969

7070

7171
/**
72-
* Runs the test method.
73-
* @param array $args test method parameters (dataprovider bypass)
72+
* Executes a specified test method within this test case, handling data providers and errors.
73+
* @param ?array $args arguments provided for the test method, bypassing data provider if provided.
7474
*/
7575
public function runTest(string $method, ?array $args = null): void
7676
{
@@ -165,7 +165,7 @@ protected function getData(string $provider)
165165

166166

167167
/**
168-
* This method is called before a test is executed.
168+
* Setup logic to be executed before each test method. Override in subclasses for specific behaviors.
169169
* @return void
170170
*/
171171
protected function setUp()
@@ -174,14 +174,17 @@ protected function setUp()
174174

175175

176176
/**
177-
* This method is called after a test is executed.
177+
* Teardown logic to be executed after each test method. Override in subclasses to release resources.
178178
* @return void
179179
*/
180180
protected function tearDown()
181181
{
182182
}
183183

184184

185+
/**
186+
* Executes the tearDown method and suppresses any errors, ensuring clean teardown in all cases.
187+
*/
185188
private function silentTearDown(): void
186189
{
187190
set_error_handler(fn() => null);
@@ -195,14 +198,17 @@ private function silentTearDown(): void
195198

196199

197200
/**
198-
* Skips the test.
201+
* Skips the current test, optionally providing a reason for skipping.
199202
*/
200203
protected function skip(string $message = ''): void
201204
{
202205
throw new TestCaseSkippedException($message);
203206
}
204207

205208

209+
/**
210+
* Outputs a list of all test methods in the current test case. Used for Runner.
211+
*/
206212
private function sendMethodList(array $methods): void
207213
{
208214
Environment::$checkAssertions = false;
@@ -230,6 +236,9 @@ private function sendMethodList(array $methods): void
230236
}
231237

232238

239+
/**
240+
* Prepares test data from specified data providers or default method parameters if no provider is specified.
241+
*/
233242
private function prepareTestData(\ReflectionMethod $method, array $dataprovider): array
234243
{
235244
$data = $defaultParams = [];
@@ -270,12 +279,16 @@ private function prepareTestData(\ReflectionMethod $method, array $dataprovider)
270279
}
271280
}
272281

273-
282+
/**
283+
* Errors specific to TestCase operations.
284+
*/
274285
class TestCaseException extends \Exception
275286
{
276287
}
277288

278-
289+
/**
290+
* Exception thrown when a test case or a test method is skipped.
291+
*/
279292
class TestCaseSkippedException extends \Exception
280293
{
281294
}

src/Framework/functions.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
use Tester\Environment;
88

99

10+
/**
11+
* Executes a provided test closure, handling setup and teardown operations.
12+
*/
1013
function test(string $description, Closure $closure): void
1114
{
1215
if (($count = func_num_args()) > 2) {
13-
throw new \Exception(__FUNCTION__ . "() expects 2 parameter, $count given.");
16+
throw new Exception(__FUNCTION__ . "() expects 2 parameters, $count given.");
1417
}
1518

1619
if ($fn = (new ReflectionFunction('setUp'))->getStaticVariables()['fn']) {
@@ -36,6 +39,9 @@ function test(string $description, Closure $closure): void
3639
}
3740

3841

42+
/**
43+
* Tests for exceptions thrown by a provided closure matching specific criteria.
44+
*/
3945
function testException(
4046
string $description,
4147
Closure $function,
@@ -59,13 +65,19 @@ function testException(
5965
}
6066

6167

68+
/**
69+
* Registers a function to be called before each test execution.
70+
*/
6271
function setUp(?Closure $closure): void
6372
{
6473
static $fn;
6574
$fn = $closure;
6675
}
6776

6877

78+
/**
79+
* Registers a function to be called after each test execution.
80+
*/
6981
function tearDown(?Closure $closure): void
7082
{
7183
static $fn;

0 commit comments

Comments
 (0)