5
5
namespace yii2 \extensions \nestedsets \tests \support \stub ;
6
6
7
7
use yii \db \ActiveRecord ;
8
+ use yii \db \Exception ;
8
9
use yii2 \extensions \nestedsets \NestedSetsBehavior ;
10
+ use yii2 \extensions \nestedsets \NodeContext ;
9
11
10
12
/**
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.
12
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
+ *
29
+ * @phpstan-template T of ActiveRecord
13
30
* @phpstan-extends NestedSetsBehavior<T>
31
+ *
32
+ * @copyright Copyright (C) 2023 Terabytesoftw.
33
+ * @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
14
34
*/
15
35
final class ExtendableNestedSetsBehavior extends NestedSetsBehavior
16
36
{
17
37
/**
38
+ * Tracks method calls for assertions.
39
+ *
18
40
* @phpstan-var array<string, bool>
19
41
*/
20
42
public array $ calledMethods = [];
43
+
44
+ /**
45
+ * Indicates if the cache invalidation method was called.
46
+ */
21
47
public bool $ invalidateCacheCalled = false ;
22
48
49
+ /**
50
+ * @throws Exception if an unexpected error occurs during execution.
51
+ */
23
52
public function exposedBeforeInsertNode (int $ value , int $ depth ): void
24
53
{
25
54
$ this ->calledMethods ['beforeInsertNode ' ] = true ;
26
55
27
56
$ this ->beforeInsertNode ($ value , $ depth );
28
57
}
29
58
59
+ /**
60
+ * @throws Exception if an unexpected error occurs during execution.
61
+ */
30
62
public function exposedBeforeInsertRootNode (): void
31
63
{
32
64
$ this ->calledMethods ['beforeInsertRootNode ' ] = true ;
@@ -38,7 +70,7 @@ public function exposedMoveNode(ActiveRecord $node, int $value, int $depth): voi
38
70
{
39
71
$ this ->calledMethods ['moveNode ' ] = true ;
40
72
41
- $ context = new \ yii2 \ extensions \ nestedsets \ NodeContext (
73
+ $ context = new NodeContext (
42
74
$ node ,
43
75
0 ,
44
76
0 ,
0 commit comments