@@ -58,4 +58,95 @@ public function testCrudOperations(): void
58
58
59
59
$ this ->assertNull ($ repository ->findById ($ id ));
60
60
}
61
+
62
+ public function testFindMultiple (): void
63
+ {
64
+ $ repository = new TestPersonRepository ($ this ->connection , $ this ->personSchema );
65
+
66
+ $ repository ->savePerson ($ repository ->createPerson ('John ' , 'Doe ' , 20 ));
67
+ $ repository ->savePerson ($ repository ->createPerson ('Jane ' , 'Doe ' , 20 ));
68
+
69
+ $ this ->assertCount (0 , $ repository ->findByLastName ('John ' ));
70
+ $ this ->assertCount (1 , $ repository ->findByFirstName ('John ' ));
71
+ $ this ->assertCount (1 , $ repository ->findByFirstName ('Jane ' ));
72
+ $ this ->assertCount (2 , $ repository ->findByLastName ('Doe ' ));
73
+ $ this ->assertCount (2 , $ repository ->findByAnyFirstName (['John ' , 'Jane ' ]));
74
+ }
75
+
76
+ public function testOrderedLimits (): void
77
+ {
78
+ $ repository = new TestPersonRepository ($ this ->connection , $ this ->personSchema );
79
+
80
+ $ repository ->savePerson ($ repository ->createPerson ('Elizabeth ' , 'Jones ' , 35 ));
81
+ $ repository ->savePerson ($ repository ->createPerson ('Carmen ' , 'Martinez ' , 47 ));
82
+ $ repository ->savePerson ($ repository ->createPerson ('Isabell ' , 'Williams ' , 45 ));
83
+ $ repository ->savePerson ($ repository ->createPerson ('Corina ' , 'Keith ' , 64 ));
84
+ $ repository ->savePerson ($ repository ->createPerson ('Ruth ' , 'Ward ' , 44 ));
85
+ $ repository ->savePerson ($ repository ->createPerson ('Frances ' , 'Gray ' , 41 ));
86
+
87
+ $ lastName = function (TestPersonModel $ person ): string {
88
+ return $ person ->getLastName ();
89
+ };
90
+
91
+ $ this ->assertSame (
92
+ ['Gray ' , 'Jones ' , 'Keith ' , 'Martinez ' , 'Ward ' , 'Williams ' ],
93
+ array_map ($ lastName , $ repository ->findAllAlphabetically ())
94
+ );
95
+
96
+ $ this ->assertSame (
97
+ ['Williams ' , 'Ward ' , 'Martinez ' , 'Keith ' , 'Jones ' , 'Gray ' ],
98
+ array_map ($ lastName , $ repository ->findAllAlphabetically (null , false ))
99
+ );
100
+
101
+ $ this ->assertSame (
102
+ ['Gray ' , 'Jones ' , 'Keith ' ],
103
+ array_map ($ lastName , $ repository ->findAllAlphabetically (3 ))
104
+ );
105
+
106
+ $ this ->assertSame (
107
+ ['Williams ' , 'Ward ' , 'Martinez ' ],
108
+ array_map ($ lastName , $ repository ->findAllAlphabetically (3 , false ))
109
+ );
110
+ }
111
+
112
+ public function testDecimalNulls (): void
113
+ {
114
+ $ repository = new TestPersonRepository ($ this ->connection , $ this ->personSchema );
115
+
116
+ $ jane = $ repository ->createPerson ('Jane ' , 'Doe ' , 20 );
117
+ $ jane ->setWeight (72.1 );
118
+ $ repository ->savePerson ($ jane );
119
+
120
+ $ john = $ repository ->createPerson ('John ' , 'Doe ' , 20 );
121
+ $ john ->setWeight (82.0 );
122
+ $ repository ->savePerson ($ john );
123
+
124
+ $ repository ->savePerson ($ repository ->createPerson ('Jane ' , 'Smith ' , 22 ));
125
+
126
+ $ this ->assertSame (72.1 , $ repository ->findOneByWeight (72.1 )->getWeight ());
127
+ $ this ->assertNull ($ repository ->findOneByWeight (null )->getWeight ());
128
+ $ this ->assertCount (2 , $ repository ->findByAnyWeight ([72.1 , 82.0 ]));
129
+ $ this ->assertCount (2 , $ repository ->findByAnyWeight ([72.1 , null ]));
130
+ $ this ->assertCount (1 , $ repository ->findByAnyWeight ([null ]));
131
+ }
132
+
133
+ public function testBooleanFields (): void
134
+ {
135
+ $ repository = new TestPersonRepository ($ this ->connection , $ this ->personSchema );
136
+
137
+ $ repository ->savePerson ($ repository ->createPerson ('Jane ' , 'Doe ' , 20 ));
138
+
139
+ $ this ->assertCount (0 , $ repository ->findByHasLicense (true ));
140
+
141
+ $ unlicensed = $ repository ->findByHasLicense (false );
142
+ $ this ->assertCount (1 , $ unlicensed );
143
+
144
+ $ jane = array_pop ($ unlicensed );
145
+ $ jane ->giveLicense ();
146
+
147
+ $ repository ->savePerson ($ jane );
148
+
149
+ $ this ->assertCount (1 , $ repository ->findByHasLicense (true ));
150
+ $ this ->assertCount (0 , $ repository ->findByHasLicense (false ));
151
+ }
61
152
}
0 commit comments