From 96964ee80f0e9774ea1f9a937f799f93a489e5f4 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 8 Jul 2025 17:53:15 -0400 Subject: [PATCH 1/2] feat: Enhance `EchoMigrateController` and `ExtendableNestedSetsBehavior` class with improved documentation and type hints for better test coverage and clarity. --- tests/support/stub/EchoMigrateController.php | 19 +++++++++- .../stub/ExtendableNestedSetsBehavior.php | 36 +++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/support/stub/EchoMigrateController.php b/tests/support/stub/EchoMigrateController.php index 8cfeaf6..d630e1a 100644 --- a/tests/support/stub/EchoMigrateController.php +++ b/tests/support/stub/EchoMigrateController.php @@ -6,9 +6,26 @@ use yii\console\controllers\MigrateController; +/** + * Console migrate controller stub that echoes output for testing. + * + * Provides a stub implementation of the {@see MigrateController} for use in test environments, overriding the + * {@see stdout()} method to directly echo output instead of writing to the console output stream. + * + * This class is intended for use in automated tests where migration output needs to be captured or asserted without + * relying on the Yii Console output infrastructure. + * + * Key features: + * - Designed for use in migration-related test scenarios. + * - Overrides {@see stdout()} to echo output for test assertions. + * - Simplifies output handling in test environments. + * + * @copyright Copyright (C) 2023 Terabytesoftw. + * @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License. + */ final class EchoMigrateController extends MigrateController { - public function stdout($string) + public function stdout($string): bool { echo $string; diff --git a/tests/support/stub/ExtendableNestedSetsBehavior.php b/tests/support/stub/ExtendableNestedSetsBehavior.php index ee5819c..83f6ab0 100644 --- a/tests/support/stub/ExtendableNestedSetsBehavior.php +++ b/tests/support/stub/ExtendableNestedSetsBehavior.php @@ -5,21 +5,50 @@ namespace yii2\extensions\nestedsets\tests\support\stub; use yii\db\ActiveRecord; +use yii\db\Exception; use yii2\extensions\nestedsets\NestedSetsBehavior; +use yii2\extensions\nestedsets\NodeContext; /** - * @phpstan-template T of ActiveRecord + * Extensible Nested Sets Behavior stub for testing method exposure and call tracking. + * + * Provides a test double for {@see NestedSetsBehavior} exposing protected methods and tracking their invocation for + * unit testing purposes. + * + * This class enables direct invocation of internal behavior logic and records method calls, supporting fine-grained + * assertions in test scenarios. + * + * It also allows manual manipulation of internal state for advanced test coverage. * + * Key features: + * - Allows manual state manipulation (node, operation). + * - Exposes protected methods for direct testing. + * - Supports cache invalidation tracking. + * - Tracks method invocations for assertion. + * + * @phpstan-template T of ActiveRecord * @phpstan-extends NestedSetsBehavior + * + * @copyright Copyright (C) 2023 Terabytesoftw. + * @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License. */ final class ExtendableNestedSetsBehavior extends NestedSetsBehavior { /** + * Tracks method calls for assertions. + * * @phpstan-var array */ public array $calledMethods = []; + + /** + * Indicates if the cache invalidation method was called. + */ public bool $invalidateCacheCalled = false; + /** + * @throws Exception if an unexpected error occurs during execution. + */ public function exposedBeforeInsertNode(int $value, int $depth): void { $this->calledMethods['beforeInsertNode'] = true; @@ -27,6 +56,9 @@ public function exposedBeforeInsertNode(int $value, int $depth): void $this->beforeInsertNode($value, $depth); } + /** + * @throws Exception if an unexpected error occurs during execution. + */ public function exposedBeforeInsertRootNode(): void { $this->calledMethods['beforeInsertRootNode'] = true; @@ -38,7 +70,7 @@ public function exposedMoveNode(ActiveRecord $node, int $value, int $depth): voi { $this->calledMethods['moveNode'] = true; - $context = new \yii2\extensions\nestedsets\NodeContext( + $context = new NodeContext( $node, 0, 0, From 70f93bad8e02a66570d125207c3973e86e077707 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 8 Jul 2025 21:53:39 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- tests/support/stub/ExtendableNestedSetsBehavior.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/support/stub/ExtendableNestedSetsBehavior.php b/tests/support/stub/ExtendableNestedSetsBehavior.php index 83f6ab0..4b1fd80 100644 --- a/tests/support/stub/ExtendableNestedSetsBehavior.php +++ b/tests/support/stub/ExtendableNestedSetsBehavior.php @@ -27,6 +27,7 @@ * - Tracks method invocations for assertion. * * @phpstan-template T of ActiveRecord + * * @phpstan-extends NestedSetsBehavior * * @copyright Copyright (C) 2023 Terabytesoftw.