From f687f1113f0060c15031a2899521dc9800297288 Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Thu, 24 Jul 2025 17:25:21 +0100 Subject: [PATCH 1/2] [TASK] Add tests for `DeclarationBlock` constructor The class extends `RuleSet`, but the constructor behaviour needs to be tested for each class. --- tests/Unit/RuleSet/DeclarationBlockTest.php | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/Unit/RuleSet/DeclarationBlockTest.php b/tests/Unit/RuleSet/DeclarationBlockTest.php index 5559c0444..c1496bf2b 100644 --- a/tests/Unit/RuleSet/DeclarationBlockTest.php +++ b/tests/Unit/RuleSet/DeclarationBlockTest.php @@ -53,6 +53,43 @@ public function implementsPositionable(): void self::assertInstanceOf(Positionable::class, $this->subject); } + /** + * @test + */ + public function getLineNumberByDefaultReturnsNull(): void + { + $result = $this->subject->getLineNumber(); + + self::assertNull($result); + } + + /** + * @return array}> + */ + public function provideLineNumber(): array + { + return [ + 'line 1' => [1], + 'line 42' => [42], + ]; + } + + /** + * @test + * + * @param int<1, max> $lineNumber + * + * @dataProvider provideLineNumber + */ + public function getLineNumberReturnsLineNumberPassedToConstructor(int $lineNumber): void + { + $subject = new DeclarationBlock($lineNumber); + + $result = $subject->getLineNumber(); + + self::assertSame($lineNumber, $result); + } + /** * @return array */ From 228212a2aebbddc5663550446c8f65c7f68d8cec Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Thu, 24 Jul 2025 18:44:12 +0100 Subject: [PATCH 2/2] Also test passing `null` to constructor as line number --- tests/Unit/RuleSet/DeclarationBlockTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Unit/RuleSet/DeclarationBlockTest.php b/tests/Unit/RuleSet/DeclarationBlockTest.php index c1496bf2b..3d85d98ca 100644 --- a/tests/Unit/RuleSet/DeclarationBlockTest.php +++ b/tests/Unit/RuleSet/DeclarationBlockTest.php @@ -64,11 +64,12 @@ public function getLineNumberByDefaultReturnsNull(): void } /** - * @return array}> + * @return array|null}> */ public function provideLineNumber(): array { return [ + 'null' => [null], 'line 1' => [1], 'line 42' => [42], ]; @@ -77,11 +78,11 @@ public function provideLineNumber(): array /** * @test * - * @param int<1, max> $lineNumber + * @param int<1, max>|null $lineNumber * * @dataProvider provideLineNumber */ - public function getLineNumberReturnsLineNumberPassedToConstructor(int $lineNumber): void + public function getLineNumberReturnsLineNumberPassedToConstructor(?int $lineNumber): void { $subject = new DeclarationBlock($lineNumber);