55namespace yii2 \extensions \nestedsets \tests \support \stub ;
66
77use yii \db \ActiveRecord ;
8+ use yii \db \Exception ;
89use 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 */
1535final 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