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