Skip to content

Commit 056f106

Browse files
feat: Enhance EchoMigrateController and ExtendableNestedSetsBehavior class with improved documentation and type hints for better test coverage and clarity. (#80)
1 parent 6f01a4d commit 056f106

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,61 @@
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
/**
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.
22+
*
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+
*
1129
* @phpstan-template T of ActiveRecord
1230
*
1331
* @phpstan-extends NestedSetsBehavior<T>
32+
*
33+
* @copyright Copyright (C) 2023 Terabytesoftw.
34+
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
1435
*/
1536
final class ExtendableNestedSetsBehavior extends NestedSetsBehavior
1637
{
1738
/**
39+
* Tracks method calls for assertions.
40+
*
1841
* @phpstan-var array<string, bool>
1942
*/
2043
public array $calledMethods = [];
44+
45+
/**
46+
* Indicates if the cache invalidation method was called.
47+
*/
2148
public bool $invalidateCacheCalled = false;
2249

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

2757
$this->beforeInsertNode($value, $depth);
2858
}
2959

60+
/**
61+
* @throws Exception if an unexpected error occurs during execution.
62+
*/
3063
public function exposedBeforeInsertRootNode(): void
3164
{
3265
$this->calledMethods['beforeInsertRootNode'] = true;
@@ -38,7 +71,7 @@ public function exposedMoveNode(ActiveRecord $node, int $value, int $depth): voi
3871
{
3972
$this->calledMethods['moveNode'] = true;
4073

41-
$context = new \yii2\extensions\nestedsets\NodeContext(
74+
$context = new NodeContext(
4275
$node,
4376
0,
4477
0,

0 commit comments

Comments
 (0)