From 6fc58a5d733cdc8636e3b1b3bed4ba4a3d171aa4 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 19 Aug 2025 05:59:29 -0400 Subject: [PATCH] fix: Update `php-forge/support` version `0.2` in `composer.json` and refactor assertions in test cases. --- CHANGELOG.md | 1 + composer.json | 2 +- tests/TestCase.php | 2 + tests/base/AbstractCacheManagement.php | 77 +++++++++++++------------- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e37422..bc6cc4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Bug #85: Update license badge URL in `README.md` and add license header in `LICENSE.md` and kill infection mutant (@terabytesoftw) - Bug #87: Update `.gitattributes` to exclude additional files from the package, update `LICENSE.md` and add stable version worflows actions (@terabytesoftw) - Bug #88: Remove unused command coverage options from mutation workflow configuration (@terabytesoftw) +- Bug #89: Update `php-forge/support` version `0.2` in `composer.json` and refactor assertions in test cases (@terabytesoftw) ## 0.1.0 July 8, 2025 diff --git a/composer.json b/composer.json index 1fbc431..753d88d 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "ext-simplexml": "*", "infection/infection": "^0.27|^0.31", "maglnet/composer-require-checker": "^4.1", - "php-forge/support": "^0.1", + "php-forge/support": "^0.2", "phpstan/extension-installer": "^1.4", "phpstan/phpstan-strict-rules": "^2.0.3", "phpunit/phpunit": "^10.2", diff --git a/tests/TestCase.php b/tests/TestCase.php index 18e0e6c..964295c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,6 +4,7 @@ namespace yii2\extensions\nestedsets\tests; +use PHPForge\Support\TestSupport; use RuntimeException; use SimpleXMLElement; use Yii; @@ -69,6 +70,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { use SchemaBuilderTrait; + use TestSupport; /** * Database connection configuration. diff --git a/tests/base/AbstractCacheManagement.php b/tests/base/AbstractCacheManagement.php index a77e853..6e08cb7 100644 --- a/tests/base/AbstractCacheManagement.php +++ b/tests/base/AbstractCacheManagement.php @@ -4,7 +4,6 @@ namespace yii2\extensions\nestedsets\tests\base; -use PHPForge\Support\Assert; use yii\base\Behavior; use yii\db\ActiveRecord; use yii2\extensions\nestedsets\NestedSetsBehavior; @@ -99,17 +98,17 @@ public function testAfterInsertCacheInvalidationIntegration(): void ); self::assertEquals( 0, - Assert::invokeMethod($behavior, 'getDepthValue'), + self::invokeMethod($behavior, 'getDepthValue'), "New cached depth should be '0'.", ); self::assertEquals( 1, - Assert::invokeMethod($behavior, 'getLeftValue'), + self::invokeMethod($behavior, 'getLeftValue'), "New cached left should be '1'.", ); self::assertEquals( 2, - Assert::invokeMethod($behavior, 'getRightValue'), + self::invokeMethod($behavior, 'getRightValue'), "New cached right should be '2'.", ); } @@ -284,17 +283,17 @@ public function testCacheInvalidationAfterInsertWithoutTreeAttribute(): void self::assertEquals( 0, - Assert::invokeMethod($behavior, 'getDepthValue'), + self::invokeMethod($behavior, 'getDepthValue'), "New cached depth value should be '0' for root.", ); self::assertEquals( 1, - Assert::invokeMethod($behavior, 'getLeftValue'), + self::invokeMethod($behavior, 'getLeftValue'), "New cached left value should be '1' for root.", ); self::assertEquals( 2, - Assert::invokeMethod($behavior, 'getRightValue'), + self::invokeMethod($behavior, 'getRightValue'), "New cached right value should be '2' for root.", ); } @@ -322,17 +321,17 @@ public function testCacheInvalidationAfterInsertWithTreeAttribute(): void self::assertEquals( 0, - Assert::invokeMethod($behavior, 'getDepthValue'), + self::invokeMethod($behavior, 'getDepthValue'), "New cached depth value should be '0' for root.", ); self::assertEquals( 1, - Assert::invokeMethod($behavior, 'getLeftValue'), + self::invokeMethod($behavior, 'getLeftValue'), "New cached left value should be '1' for root.", ); self::assertEquals( 2, - Assert::invokeMethod($behavior, 'getRightValue'), + self::invokeMethod($behavior, 'getRightValue'), "New cached right value should be '2' for root.", ); self::assertNotFalse( @@ -375,17 +374,17 @@ public function testCacheInvalidationAfterMakeRoot(): void self::assertEquals( $child->getAttribute('depth'), - Assert::invokeMethod($behavior, 'getDepthValue'), + self::invokeMethod($behavior, 'getDepthValue'), 'Initial cached depth value should match attribute.', ); self::assertEquals( $child->getAttribute('lft'), - Assert::invokeMethod($behavior, 'getLeftValue'), + self::invokeMethod($behavior, 'getLeftValue'), 'Initial cached left value should match attribute.', ); self::assertEquals( $child->getAttribute('rgt'), - Assert::invokeMethod($behavior, 'getRightValue'), + self::invokeMethod($behavior, 'getRightValue'), 'Initial cached right value should match attribute.', ); @@ -395,17 +394,17 @@ public function testCacheInvalidationAfterMakeRoot(): void self::assertEquals( 0, - Assert::invokeMethod($behavior, 'getDepthValue'), + self::invokeMethod($behavior, 'getDepthValue'), "New cached depth value should be '0' for root.", ); self::assertEquals( 1, - Assert::invokeMethod($behavior, 'getLeftValue'), + self::invokeMethod($behavior, 'getLeftValue'), "New cached left value should be '1' for root.", ); self::assertEquals( 2, - Assert::invokeMethod($behavior, 'getRightValue'), + self::invokeMethod($behavior, 'getRightValue'), "New cached right value should be '2' for root.", ); } @@ -434,7 +433,7 @@ public function testGetDepthValueMemoization(): void 'Behavior should be attached to the node.', ); - $firstCall = Assert::invokeMethod($behavior, 'getDepthValue'); + $firstCall = self::invokeMethod($behavior, 'getDepthValue'); self::assertSame( 42, @@ -442,7 +441,7 @@ public function testGetDepthValueMemoization(): void 'First call should return the mocked value.', ); - $secondCall = Assert::invokeMethod($behavior, 'getDepthValue'); + $secondCall = self::invokeMethod($behavior, 'getDepthValue'); self::assertSame( 42, @@ -451,7 +450,7 @@ public function testGetDepthValueMemoization(): void ); self::assertSame( 42, - Assert::inaccessibleProperty($behavior, 'depthValue'), + self::inaccessibleProperty($behavior, 'depthValue'), 'Depth value should be cached after first access.', ); } @@ -480,7 +479,7 @@ public function testGetLeftValueMemoization(): void 'Behavior should be attached to the node.', ); - $firstCall = Assert::invokeMethod($behavior, 'getLeftValue'); + $firstCall = self::invokeMethod($behavior, 'getLeftValue'); self::assertSame( 123, @@ -488,7 +487,7 @@ public function testGetLeftValueMemoization(): void 'First call should return the mocked value.', ); - $secondCall = Assert::invokeMethod($behavior, 'getLeftValue'); + $secondCall = self::invokeMethod($behavior, 'getLeftValue'); self::assertSame( 123, @@ -497,7 +496,7 @@ public function testGetLeftValueMemoization(): void ); self::assertSame( 123, - Assert::inaccessibleProperty($behavior, 'leftValue'), + self::inaccessibleProperty($behavior, 'leftValue'), 'Left value should be cached after first access.', ); } @@ -525,7 +524,7 @@ public function testGetRightValueMemoization(): void 'Behavior should be attached to the node.', ); - $firstCall = Assert::invokeMethod($behavior, 'getRightValue'); + $firstCall = self::invokeMethod($behavior, 'getRightValue'); self::assertSame( 456, @@ -533,7 +532,7 @@ public function testGetRightValueMemoization(): void 'First call should return the mocked value.', ); - $secondCall = Assert::invokeMethod($behavior, 'getRightValue'); + $secondCall = self::invokeMethod($behavior, 'getRightValue'); self::assertSame( 456, @@ -542,7 +541,7 @@ public function testGetRightValueMemoization(): void ); self::assertSame( 456, - Assert::inaccessibleProperty($behavior, 'rightValue'), + self::inaccessibleProperty($behavior, 'rightValue'), 'Right value should be cached after first access.', ); } @@ -570,17 +569,17 @@ public function testManualCacheInvalidation(): void self::assertEquals( 0, - Assert::invokeMethod($behavior, 'getDepthValue'), + self::invokeMethod($behavior, 'getDepthValue'), 'Depth value should be correctly retrieved after invalidation.', ); self::assertEquals( 1, - Assert::invokeMethod($behavior, 'getLeftValue'), + self::invokeMethod($behavior, 'getLeftValue'), 'Left value should be correctly retrieved after invalidation.', ); self::assertEquals( 2, - Assert::invokeMethod($behavior, 'getRightValue'), + self::invokeMethod($behavior, 'getRightValue'), 'Right value should be correctly retrieved after invalidation.', ); } @@ -590,20 +589,20 @@ public function testManualCacheInvalidation(): void */ private function populateAndVerifyCache(Behavior $behavior): void { - Assert::invokeMethod($behavior, 'getDepthValue'); - Assert::invokeMethod($behavior, 'getLeftValue'); - Assert::invokeMethod($behavior, 'getRightValue'); + self::invokeMethod($behavior, 'getDepthValue'); + self::invokeMethod($behavior, 'getLeftValue'); + self::invokeMethod($behavior, 'getRightValue'); self::assertNotNull( - Assert::inaccessibleProperty($behavior, 'depthValue'), + self::inaccessibleProperty($behavior, 'depthValue'), 'Depth value cache should be populated.', ); self::assertNotNull( - Assert::inaccessibleProperty($behavior, 'leftValue'), + self::inaccessibleProperty($behavior, 'leftValue'), 'Left value cache should be populated.', ); self::assertNotNull( - Assert::inaccessibleProperty($behavior, 'rightValue'), + self::inaccessibleProperty($behavior, 'rightValue'), 'Right value cache should be populated.', ); } @@ -614,23 +613,23 @@ private function populateAndVerifyCache(Behavior $behavior): void private function verifyCacheInvalidation(Behavior $behavior): void { self::assertNull( - Assert::inaccessibleProperty($behavior, 'depthValue'), + self::inaccessibleProperty($behavior, 'depthValue'), "Depth value cache should be invalidated after 'makeRoot()'/'afterInsert()'.", ); self::assertNull( - Assert::inaccessibleProperty($behavior, 'leftValue'), + self::inaccessibleProperty($behavior, 'leftValue'), "Left value cache should be invalidated after 'makeRoot()'/'afterInsert()'.", ); self::assertNull( - Assert::inaccessibleProperty($behavior, 'node'), + self::inaccessibleProperty($behavior, 'node'), "Node cache should be 'null' after manual invalidation.", ); self::assertNull( - Assert::inaccessibleProperty($behavior, 'operation'), + self::inaccessibleProperty($behavior, 'operation'), "Operation cache should be 'null' after manual invalidation.", ); self::assertNull( - Assert::inaccessibleProperty($behavior, 'rightValue'), + self::inaccessibleProperty($behavior, 'rightValue'), "Right value cache should be invalidated after 'makeRoot()'/'afterInsert()'.", ); }