Skip to content

Commit 96964ee

Browse files
committed
feat: Enhance EchoMigrateController and ExtendableNestedSetsBehavior class with improved documentation and type hints for better test coverage and clarity.
1 parent 6f01a4d commit 96964ee

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

tests/support/stub/EchoMigrateController.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,26 @@
66

77
use yii\console\controllers\MigrateController;
88

9+
/**
10+
* Console migrate controller stub that echoes output for testing.
11+
*
12+
* Provides a stub implementation of the {@see MigrateController} for use in test environments, overriding the
13+
* {@see stdout()} method to directly echo output instead of writing to the console output stream.
14+
*
15+
* This class is intended for use in automated tests where migration output needs to be captured or asserted without
16+
* relying on the Yii Console output infrastructure.
17+
*
18+
* Key features:
19+
* - Designed for use in migration-related test scenarios.
20+
* - Overrides {@see stdout()} to echo output for test assertions.
21+
* - Simplifies output handling in test environments.
22+
*
23+
* @copyright Copyright (C) 2023 Terabytesoftw.
24+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
25+
*/
926
final class EchoMigrateController extends MigrateController
1027
{
11-
public function stdout($string)
28+
public function stdout($string): bool
1229
{
1330
echo $string;
1431

tests/support/stub/ExtendableNestedSetsBehavior.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,60 @@
55
namespace yii2\extensions\nestedsets\tests\support\stub;
66

77
use yii\db\ActiveRecord;
8+
use yii\db\Exception;
89
use yii2\extensions\nestedsets\NestedSetsBehavior;
10+
use yii2\extensions\nestedsets\NodeContext;
911

1012
/**
11-
* @phpstan-template T of ActiveRecord
13+
* Extensible Nested Sets Behavior stub for testing method exposure and call tracking.
14+
*
15+
* Provides a test double for {@see NestedSetsBehavior} exposing protected methods and tracking their invocation for
16+
* unit testing purposes.
17+
*
18+
* This class enables direct invocation of internal behavior logic and records method calls, supporting fine-grained
19+
* assertions in test scenarios.
20+
*
21+
* It also allows manual manipulation of internal state for advanced test coverage.
1222
*
23+
* Key features:
24+
* - Allows manual state manipulation (node, operation).
25+
* - Exposes protected methods for direct testing.
26+
* - Supports cache invalidation tracking.
27+
* - Tracks method invocations for assertion.
28+
*
29+
* @phpstan-template T of ActiveRecord
1330
* @phpstan-extends NestedSetsBehavior<T>
31+
*
32+
* @copyright Copyright (C) 2023 Terabytesoftw.
33+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
1434
*/
1535
final class ExtendableNestedSetsBehavior extends NestedSetsBehavior
1636
{
1737
/**
38+
* Tracks method calls for assertions.
39+
*
1840
* @phpstan-var array<string, bool>
1941
*/
2042
public array $calledMethods = [];
43+
44+
/**
45+
* Indicates if the cache invalidation method was called.
46+
*/
2147
public bool $invalidateCacheCalled = false;
2248

49+
/**
50+
* @throws Exception if an unexpected error occurs during execution.
51+
*/
2352
public function exposedBeforeInsertNode(int $value, int $depth): void
2453
{
2554
$this->calledMethods['beforeInsertNode'] = true;
2655

2756
$this->beforeInsertNode($value, $depth);
2857
}
2958

59+
/**
60+
* @throws Exception if an unexpected error occurs during execution.
61+
*/
3062
public function exposedBeforeInsertRootNode(): void
3163
{
3264
$this->calledMethods['beforeInsertRootNode'] = true;
@@ -38,7 +70,7 @@ public function exposedMoveNode(ActiveRecord $node, int $value, int $depth): voi
3870
{
3971
$this->calledMethods['moveNode'] = true;
4072

41-
$context = new \yii2\extensions\nestedsets\NodeContext(
73+
$context = new NodeContext(
4274
$node,
4375
0,
4476
0,

0 commit comments

Comments
 (0)