Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace yii2\extensions\nestedsets\tests;

use PHPForge\Support\TestSupport;
use RuntimeException;
use SimpleXMLElement;
use Yii;
Expand Down Expand Up @@ -69,6 +70,7 @@
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
use SchemaBuilderTrait;
use TestSupport;

/**
* Database connection configuration.
Expand Down
77 changes: 38 additions & 39 deletions tests/base/AbstractCacheManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'.",
);
}
Expand Down Expand Up @@ -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.",
);
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.',
);

Expand All @@ -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.",
);
}
Expand Down Expand Up @@ -434,15 +433,15 @@ public function testGetDepthValueMemoization(): void
'Behavior should be attached to the node.',
);

$firstCall = Assert::invokeMethod($behavior, 'getDepthValue');
$firstCall = self::invokeMethod($behavior, 'getDepthValue');

self::assertSame(
42,
$firstCall,
'First call should return the mocked value.',
);

$secondCall = Assert::invokeMethod($behavior, 'getDepthValue');
$secondCall = self::invokeMethod($behavior, 'getDepthValue');

self::assertSame(
42,
Expand All @@ -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.',
);
}
Expand Down Expand Up @@ -480,15 +479,15 @@ public function testGetLeftValueMemoization(): void
'Behavior should be attached to the node.',
);

$firstCall = Assert::invokeMethod($behavior, 'getLeftValue');
$firstCall = self::invokeMethod($behavior, 'getLeftValue');

self::assertSame(
123,
$firstCall,
'First call should return the mocked value.',
);

$secondCall = Assert::invokeMethod($behavior, 'getLeftValue');
$secondCall = self::invokeMethod($behavior, 'getLeftValue');

self::assertSame(
123,
Expand All @@ -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.',
);
}
Expand Down Expand Up @@ -525,15 +524,15 @@ public function testGetRightValueMemoization(): void
'Behavior should be attached to the node.',
);

$firstCall = Assert::invokeMethod($behavior, 'getRightValue');
$firstCall = self::invokeMethod($behavior, 'getRightValue');

self::assertSame(
456,
$firstCall,
'First call should return the mocked value.',
);

$secondCall = Assert::invokeMethod($behavior, 'getRightValue');
$secondCall = self::invokeMethod($behavior, 'getRightValue');

self::assertSame(
456,
Expand All @@ -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.',
);
}
Expand Down Expand Up @@ -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.',
);
}
Expand All @@ -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.',
);
}
Expand All @@ -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()'.",
);
}
Expand Down
Loading