From 4c5c3463a44663a29d3cfbd443c2dc574335eb43 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Thu, 3 Jul 2025 16:18:25 -0400 Subject: [PATCH 1/3] test: Add boundary tests for `isChildOf()` method in `NestedSetsBehavior` class. --- composer.json | 2 +- tests/NestedSetsBehaviorTest.php | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 01b9b17..715a066 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "require-dev": { "ext-simplexml": "*", - "infection/infection": "^0.27|^0.29", + "infection/infection": "^0.27|^0.30", "maglnet/composer-require-checker": "^4.1", "php-forge/support": "^0.1", "phpstan/extension-installer": "^1.4", diff --git a/tests/NestedSetsBehaviorTest.php b/tests/NestedSetsBehaviorTest.php index 4e6cab8..b1e2966 100644 --- a/tests/NestedSetsBehaviorTest.php +++ b/tests/NestedSetsBehaviorTest.php @@ -1388,6 +1388,52 @@ public function testReturnIsChildOfForMultipleTreeNodeUnderVariousAncestors(): v ); } + public function testIsChildOfReturnsFalseWhenLeftValuesAreEqual(): void + { + $this->generateFixtureTree(); + + $parentNode = Tree::findOne(2); + $childNode = Tree::findOne(3); + + self::assertNotNull($parentNode, "Parent node should exist for boundary testing."); + self::assertNotNull($childNode, "Child node should exist for boundary testing."); + + $originalChildLeft = $childNode->getAttribute('lft'); + + $parentLeft = $parentNode->getAttribute('lft'); + $childNode->setAttribute('lft', $parentLeft); + + self::assertFalse( + $childNode->isChildOf($parentNode), + "Node should not be child when left values are equal (tests <= condition)." + ); + + $childNode->setAttribute('lft', $originalChildLeft); + } + + public function testIsChildOfReturnsFalseWhenRightValuesAreEqual(): void + { + $this->generateFixtureTree(); + + $parentNode = Tree::findOne(2); + $childNode = Tree::findOne(3); + + self::assertNotNull($parentNode, "Parent node should exist for boundary testing."); + self::assertNotNull($childNode, "Child node should exist for boundary testing."); + + $originalChildRight = $childNode->getAttribute('rgt'); + + $parentRight = $parentNode->getAttribute('rgt'); + $childNode->setAttribute('rgt', $parentRight); + + self::assertFalse( + $childNode->isChildOf($parentNode), + "Node should not be child when right values are equal (tests >= condition)." + ); + + $childNode->setAttribute('rgt', $originalChildRight); + } + public function testIsLeafReturnsTrueForLeafAndFalseForRoot(): void { $this->generateFixtureTree(); From 53680b0ab70eaa9f061d718aebfcea309516abdc Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 3 Jul 2025 20:18:51 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- tests/NestedSetsBehaviorTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/NestedSetsBehaviorTest.php b/tests/NestedSetsBehaviorTest.php index b1e2966..0408642 100644 --- a/tests/NestedSetsBehaviorTest.php +++ b/tests/NestedSetsBehaviorTest.php @@ -1395,8 +1395,8 @@ public function testIsChildOfReturnsFalseWhenLeftValuesAreEqual(): void $parentNode = Tree::findOne(2); $childNode = Tree::findOne(3); - self::assertNotNull($parentNode, "Parent node should exist for boundary testing."); - self::assertNotNull($childNode, "Child node should exist for boundary testing."); + self::assertNotNull($parentNode, 'Parent node should exist for boundary testing.'); + self::assertNotNull($childNode, 'Child node should exist for boundary testing.'); $originalChildLeft = $childNode->getAttribute('lft'); @@ -1405,7 +1405,7 @@ public function testIsChildOfReturnsFalseWhenLeftValuesAreEqual(): void self::assertFalse( $childNode->isChildOf($parentNode), - "Node should not be child when left values are equal (tests <= condition)." + 'Node should not be child when left values are equal (tests <= condition).' ); $childNode->setAttribute('lft', $originalChildLeft); @@ -1418,8 +1418,8 @@ public function testIsChildOfReturnsFalseWhenRightValuesAreEqual(): void $parentNode = Tree::findOne(2); $childNode = Tree::findOne(3); - self::assertNotNull($parentNode, "Parent node should exist for boundary testing."); - self::assertNotNull($childNode, "Child node should exist for boundary testing."); + self::assertNotNull($parentNode, 'Parent node should exist for boundary testing.'); + self::assertNotNull($childNode, 'Child node should exist for boundary testing.'); $originalChildRight = $childNode->getAttribute('rgt'); @@ -1428,7 +1428,7 @@ public function testIsChildOfReturnsFalseWhenRightValuesAreEqual(): void self::assertFalse( $childNode->isChildOf($parentNode), - "Node should not be child when right values are equal (tests >= condition)." + 'Node should not be child when right values are equal (tests >= condition).' ); $childNode->setAttribute('rgt', $originalChildRight); From 923379ee75f9a15bfcad6fde96276ecfe09c1420 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Thu, 3 Jul 2025 16:21:47 -0400 Subject: [PATCH 3/3] fix: Correct assertion messages in `isChildOf()` tests for clarity. --- tests/NestedSetsBehaviorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/NestedSetsBehaviorTest.php b/tests/NestedSetsBehaviorTest.php index 0408642..719c9a3 100644 --- a/tests/NestedSetsBehaviorTest.php +++ b/tests/NestedSetsBehaviorTest.php @@ -1405,7 +1405,7 @@ public function testIsChildOfReturnsFalseWhenLeftValuesAreEqual(): void self::assertFalse( $childNode->isChildOf($parentNode), - 'Node should not be child when left values are equal (tests <= condition).' + 'Node should not be child when left values are equal (tests <= condition).', ); $childNode->setAttribute('lft', $originalChildLeft); @@ -1428,7 +1428,7 @@ public function testIsChildOfReturnsFalseWhenRightValuesAreEqual(): void self::assertFalse( $childNode->isChildOf($parentNode), - 'Node should not be child when right values are equal (tests >= condition).' + 'Node should not be child when right values are equal (tests >= condition).', ); $childNode->setAttribute('rgt', $originalChildRight);