@@ -64,30 +64,27 @@ class TransientNodeTest extends TestCase
64
64
type: references
65
65
YAML;
66
66
67
- /** @var array<string, array<mixed>> */
68
- private array $ nodeTypesFixture ;
69
-
70
- /** @var array<string, NodeType> */
71
- private array $ nodeTypes ;
67
+ private NodeTypeManager $ nodeTypeManager ;
72
68
73
69
public function setUp (): void
74
70
{
75
71
parent ::setUp ();
76
- $ this ->nodeTypesFixture = Yaml::parse (self ::NODE_TYPE_FIXTURES );
72
+ $ this ->nodeTypeManager = new NodeTypeManager ();
73
+ $ this ->nodeTypeManager ->overrideNodeTypes (Yaml::parse (self ::NODE_TYPE_FIXTURES ));
77
74
}
78
75
79
76
/** @test */
80
77
public function fromRegularAllowedChildNode (): void
81
78
{
82
- $ parentNode = $ this ->createFakeRegularTransientNode ($ this -> getNodeType ( 'A:Content1 ' ) );
79
+ $ parentNode = $ this ->createFakeRegularTransientNode ('A:Content1 ' );
83
80
self ::assertSame ($ this ->getNodeType ('A:Content1 ' ), $ parentNode ->getNodeType ());
84
81
$ parentNode ->requireConstraintsImposedByAncestorsToBeMet ($ this ->getNodeType ('A:Content2 ' ));
85
82
}
86
83
87
84
/** @test */
88
85
public function forTetheredChildNodeAllowedChildNode (): void
89
86
{
90
- $ grandParentNode = $ this ->createFakeRegularTransientNode ($ this -> getNodeType ( 'A:WithContent1AllowedCollectionAsChildNode ' ) );
87
+ $ grandParentNode = $ this ->createFakeRegularTransientNode ('A:WithContent1AllowedCollectionAsChildNode ' );
91
88
92
89
$ parentNode = $ grandParentNode ->forTetheredChildNode (NodeName::fromString ('collection ' ), []);
93
90
self ::assertSame ($ this ->getNodeType ('A:Collection.Allowed ' ), $ parentNode ->getNodeType ());
@@ -98,7 +95,7 @@ public function forTetheredChildNodeAllowedChildNode(): void
98
95
/** @test */
99
96
public function forTetheredChildNodeAllowedChildNodeBecauseConstraintOverride (): void
100
97
{
101
- $ grandParentNode = $ this ->createFakeRegularTransientNode ($ this -> getNodeType ( 'A:WithContent1AllowedCollectionAsChildNodeViaOverride ' ) );
98
+ $ grandParentNode = $ this ->createFakeRegularTransientNode ('A:WithContent1AllowedCollectionAsChildNodeViaOverride ' );
102
99
103
100
$ parentNode = $ grandParentNode ->forTetheredChildNode (NodeName::fromString ('collection ' ), []);
104
101
self ::assertSame ($ this ->getNodeType ('A:Collection.Disallowed ' ), $ parentNode ->getNodeType ());
@@ -109,7 +106,7 @@ public function forTetheredChildNodeAllowedChildNodeBecauseConstraintOverride():
109
106
/** @test */
110
107
public function forRegularChildNodeAllowedChildNode (): void
111
108
{
112
- $ grandParentNode = $ this ->createFakeRegularTransientNode ($ this -> getNodeType ( 'A:Content1 ' ) );
109
+ $ grandParentNode = $ this ->createFakeRegularTransientNode ('A:Content1 ' );
113
110
114
111
$ parentNode = $ grandParentNode ->forRegularChildNode ($ this ->getNodeType ('A:Content2 ' ), []);
115
112
self ::assertSame ($ this ->getNodeType ('A:Content2 ' ), $ parentNode ->getNodeType ());
@@ -123,7 +120,7 @@ public function fromRegularDisallowedChildNode(): void
123
120
$ this ->expectException (NodeConstraintException::class);
124
121
$ this ->expectExceptionMessage ('Node type "A:Content1" is not allowed for child nodes of type A:Collection.Disallowed ' );
125
122
126
- $ parentNode = $ this ->createFakeRegularTransientNode ($ this -> getNodeType ( 'A:Collection.Disallowed ' ) );
123
+ $ parentNode = $ this ->createFakeRegularTransientNode ('A:Collection.Disallowed ' );
127
124
self ::assertSame ($ this ->getNodeType ('A:Collection.Disallowed ' ), $ parentNode ->getNodeType ());
128
125
129
126
$ parentNode ->requireConstraintsImposedByAncestorsToBeMet ($ this ->getNodeType ('A:Content1 ' ));
@@ -135,7 +132,7 @@ public function forTetheredChildNodeDisallowedChildNode(): void
135
132
$ this ->expectException (NodeConstraintException::class);
136
133
$ this ->expectExceptionMessage ('Node type "A:Content1" is not allowed below tethered child nodes "collection" of nodes of type "A:WithDisallowedCollectionAsChildNode" ' );
137
134
138
- $ grandParentNode = $ this ->createFakeRegularTransientNode ($ this -> getNodeType ( 'A:WithDisallowedCollectionAsChildNode ' ) );
135
+ $ grandParentNode = $ this ->createFakeRegularTransientNode ('A:WithDisallowedCollectionAsChildNode ' );
139
136
140
137
$ parentNode = $ grandParentNode ->forTetheredChildNode (NodeName::fromString ('collection ' ), []);
141
138
self ::assertSame ($ this ->getNodeType ('A:Collection.Disallowed ' ), $ parentNode ->getNodeType ());
@@ -149,7 +146,7 @@ public function forRegularChildNodeDisallowedChildNode(): void
149
146
$ this ->expectException (NodeConstraintException::class);
150
147
$ this ->expectExceptionMessage ('Node type "A:Content1" is not allowed for child nodes of type A:Collection.Disallowed ' );
151
148
152
- $ grandParentNode = $ this ->createFakeRegularTransientNode ($ this -> getNodeType ( 'A:Content2 ' ) );
149
+ $ grandParentNode = $ this ->createFakeRegularTransientNode ('A:Content2 ' );
153
150
154
151
$ parentNode = $ grandParentNode ->forRegularChildNode ($ this ->getNodeType ('A:Collection.Disallowed ' ), []);
155
152
self ::assertSame ($ this ->getNodeType ('A:Collection.Disallowed ' ), $ parentNode ->getNodeType ());
@@ -162,7 +159,7 @@ public function splitPropertiesAndReferencesByTypeDeclaration(): void
162
159
{
163
160
$ node = TransientNode::forRegular (
164
161
$ this ->getNodeType ('A:ContentWithProperties ' ),
165
- $ this ->getMockBuilder (NodeTypeManager::class)-> disableOriginalConstructor ()-> getMock () ,
162
+ $ this ->nodeTypeManager ,
166
163
$ this ->getMockBuilder (Context::class)->disableOriginalConstructor ()->getMock (),
167
164
[
168
165
'property-string ' => '' ,
@@ -191,11 +188,13 @@ public function splitPropertiesAndReferencesByTypeDeclaration(): void
191
188
);
192
189
}
193
190
194
- private function createFakeRegularTransientNode (NodeType $ nodeType ): TransientNode
191
+ private function createFakeRegularTransientNode (string $ nodeTypeName ): TransientNode
195
192
{
193
+ $ nodeType = $ this ->getNodeType ($ nodeTypeName );
194
+
196
195
return TransientNode::forRegular (
197
196
$ nodeType ,
198
- $ this ->getMockBuilder (NodeTypeManager::class)-> disableOriginalConstructor ()-> getMock () ,
197
+ $ this ->nodeTypeManager ,
199
198
$ this ->getMockBuilder (Context::class)->disableOriginalConstructor ()->getMock (),
200
199
[]
201
200
);
@@ -206,34 +205,9 @@ private function createFakeRegularTransientNode(NodeType $nodeType): TransientNo
206
205
*/
207
206
private function getNodeType (string $ nodeTypeName ): ?NodeType
208
207
{
209
- if (!isset ($ this ->nodeTypesFixture [$ nodeTypeName ])) {
210
- return null ;
211
- }
212
-
213
- if (isset ($ this ->nodeTypes [$ nodeTypeName ])) {
214
- return $ this ->nodeTypes [$ nodeTypeName ];
215
- }
216
-
217
- $ configuration = $ this ->nodeTypesFixture [$ nodeTypeName ];
218
- $ declaredSuperTypes = [];
219
- if (isset ($ configuration ['superTypes ' ]) && is_array ($ configuration ['superTypes ' ])) {
220
- foreach ($ configuration ['superTypes ' ] as $ superTypeName => $ enabled ) {
221
- $ declaredSuperTypes [$ superTypeName ] = $ enabled === true ? $ this ->getNodeType ($ superTypeName ) : null ;
222
- }
223
- }
224
-
225
- $ nodeType = new NodeType (
226
- $ nodeTypeName ,
227
- $ declaredSuperTypes ,
228
- $ configuration
229
- );
230
-
231
- $ fakeNodeTypeManager = $ this ->getMockBuilder (NodeTypeManager::class)->onlyMethods (['getNodeType ' ])->getMock ();
232
-
233
- $ fakeNodeTypeManager ->expects (self ::any ())->method ('getNodeType ' )->willReturnCallback (fn ($ nodeType ) => $ this ->getNodeType ($ nodeType ));
234
-
235
- ObjectAccess::setProperty ($ nodeType , 'nodeTypeManager ' , $ fakeNodeTypeManager , true );
236
-
237
- return $ this ->nodeTypes [$ nodeTypeName ] = $ nodeType ;
208
+ $ nodeType = $ this ->nodeTypeManager ->getNodeType ($ nodeTypeName );
209
+ // no di here
210
+ ObjectAccess::setProperty ($ nodeType , 'nodeTypeManager ' , $ this ->nodeTypeManager , true );
211
+ return $ nodeType ;
238
212
}
239
213
}
0 commit comments