@@ -20,23 +20,34 @@ abstract class IntegrationTestCase extends TestCase
20
20
/** @var TestPersonSchema */
21
21
protected $ personSchema ;
22
22
23
+ /** @var TestParentSchema */
24
+ protected $ parentSchema ;
25
+
23
26
abstract protected function createConnection (): Connection ;
24
27
abstract protected function setUpDatabase (Connection $ connection ): void ;
25
28
26
29
protected function setUp ()
27
30
{
28
31
$ container = new Container ();
32
+
29
33
$ this ->personSchema = new TestPersonSchema ($ container );
34
+ $ this ->parentSchema = new TestParentSchema ($ container );
30
35
31
36
$ container [TestPersonSchema::class] = $ this ->personSchema ;
37
+ $ container [TestParentSchema::class] = $ this ->parentSchema ;
32
38
33
39
$ this ->connection = $ this ->createConnection ();
34
40
$ this ->setUpDatabase ($ this ->connection );
35
41
}
36
42
43
+ private function getTestPersonRepository (): TestPersonRepository
44
+ {
45
+ return new TestPersonRepository ($ this ->connection , $ this ->personSchema , $ this ->parentSchema );
46
+ }
47
+
37
48
public function testCrudOperations (): void
38
49
{
39
- $ repository = new TestPersonRepository ( $ this ->connection , $ this -> personSchema );
50
+ $ repository = $ this ->getTestPersonRepository ( );
40
51
41
52
$ person = $ repository ->createPerson ('Jane ' , 'Doe ' , 20 );
42
53
$ repository ->savePerson ($ person );
@@ -61,7 +72,7 @@ public function testCrudOperations(): void
61
72
62
73
public function testFindMultiple (): void
63
74
{
64
- $ repository = new TestPersonRepository ( $ this ->connection , $ this -> personSchema );
75
+ $ repository = $ this ->getTestPersonRepository ( );
65
76
66
77
$ repository ->savePerson ($ repository ->createPerson ('John ' , 'Doe ' , 20 ));
67
78
$ repository ->savePerson ($ repository ->createPerson ('Jane ' , 'Doe ' , 20 ));
@@ -75,7 +86,7 @@ public function testFindMultiple(): void
75
86
76
87
public function testOrderedLimits (): void
77
88
{
78
- $ repository = new TestPersonRepository ( $ this ->connection , $ this -> personSchema );
89
+ $ repository = $ this ->getTestPersonRepository ( );
79
90
80
91
$ repository ->savePerson ($ repository ->createPerson ('Elizabeth ' , 'Jones ' , 35 ));
81
92
$ repository ->savePerson ($ repository ->createPerson ('Carmen ' , 'Martinez ' , 47 ));
@@ -111,7 +122,7 @@ public function testOrderedLimits(): void
111
122
112
123
public function testDecimalNulls (): void
113
124
{
114
- $ repository = new TestPersonRepository ( $ this ->connection , $ this -> personSchema );
125
+ $ repository = $ this ->getTestPersonRepository ( );
115
126
116
127
$ jane = $ repository ->createPerson ('Jane ' , 'Doe ' , 20 );
117
128
$ jane ->setWeight (72.1 );
@@ -132,7 +143,7 @@ public function testDecimalNulls(): void
132
143
133
144
public function testBooleanFields (): void
134
145
{
135
- $ repository = new TestPersonRepository ( $ this ->connection , $ this -> personSchema );
146
+ $ repository = $ this ->getTestPersonRepository ( );
136
147
137
148
$ repository ->savePerson ($ repository ->createPerson ('Jane ' , 'Doe ' , 20 ));
138
149
@@ -149,4 +160,37 @@ public function testBooleanFields(): void
149
160
$ this ->assertCount (1 , $ repository ->findByHasLicense (true ));
150
161
$ this ->assertCount (0 , $ repository ->findByHasLicense (false ));
151
162
}
163
+
164
+ public function testLoadingReferences (): void
165
+ {
166
+ $ repository = $ this ->getTestPersonRepository ();
167
+
168
+ $ jane = $ repository ->createPerson ('Jane ' , 'Doe ' , 20 );
169
+ $ john = $ repository ->createPerson ('John ' , 'Doe ' , 20 );
170
+ $ mama = $ repository ->createPerson ('Mama ' , 'Doe ' , 40 );
171
+ $ papa = $ repository ->createPerson ('Papa ' , 'Doe ' , 40 );
172
+
173
+ $ repository ->savePerson ($ jane );
174
+ $ repository ->savePerson ($ john );
175
+ $ repository ->savePerson ($ mama );
176
+ $ repository ->savePerson ($ papa );
177
+
178
+ $ repository ->makeParent ($ jane , $ mama );
179
+ $ repository ->makeParent ($ jane , $ papa );
180
+ $ repository ->makeParent ($ john , $ mama );
181
+ $ repository ->makeParent ($ john , $ papa );
182
+
183
+ $ person = $ repository ->findByFirstName ('John ' )[0 ];
184
+
185
+ $ repository ->loadFamily ([$ person ]);
186
+
187
+ $ firstName = function (TestPersonModel $ model ): string {
188
+ return $ model ->getFirstName ();
189
+ };
190
+
191
+ $ names = array_map ($ firstName , $ person ->getParents ());
192
+ sort ($ names );
193
+
194
+ $ this ->assertSame (['Mama ' , 'Papa ' ], $ names );
195
+ }
152
196
}
0 commit comments