@@ -153,6 +153,96 @@ public function testAssertHasOnlyCountFailsScoped()
153
153
});
154
154
}
155
155
156
+ public function testAssertHasWithWhereNotDoesNotFail ()
157
+ {
158
+ $ assert = AssertableJson::fromArray ([
159
+ 'data ' => [
160
+ [
161
+ 'id ' => 1 ,
162
+ 'name ' => 'Taylor ' ,
163
+ ],
164
+ [
165
+ 'id ' => 2 ,
166
+ 'name ' => 'Nuno ' ,
167
+ ],
168
+ ],
169
+ ]);
170
+
171
+ $ assert ->has ('data ' , function ($ bar ) {
172
+ $ bar ->has (2 )
173
+ ->each (fn ($ json ) => $ json ->whereNot ('id ' , 3 )->etc ());
174
+ });
175
+ }
176
+
177
+ public function testAssertHasWithWhereNotFails ()
178
+ {
179
+ $ assert = AssertableJson::fromArray ([
180
+ 'data ' => [
181
+ [
182
+ 'id ' => 1 ,
183
+ 'name ' => 'Taylor ' ,
184
+ ],
185
+ [
186
+ 'id ' => 2 ,
187
+ 'name ' => 'Mateus ' ,
188
+ ],
189
+ ],
190
+ ]);
191
+
192
+ $ this ->expectException (AssertionFailedError::class);
193
+ $ this ->expectExceptionMessage ('Property [data.1.id] contains a value that should be missing: [id, 2] ' );
194
+
195
+ $ assert ->has ('data ' , function ($ bar ) {
196
+ $ bar ->has (2 )
197
+ ->each (fn ($ json ) => $ json ->whereNot ('id ' , 2 )->etc ());
198
+ });
199
+ }
200
+
201
+ public function testAssertHasWithWhereNotDoesNotFailClosure ()
202
+ {
203
+ $ assert = AssertableJson::fromArray ([
204
+ 'data ' => [
205
+ [
206
+ 'id ' => 1 ,
207
+ 'name ' => 'Taylor ' ,
208
+ ],
209
+ [
210
+ 'id ' => 2 ,
211
+ 'name ' => 'Mateus ' ,
212
+ ],
213
+ ],
214
+ ]);
215
+
216
+ $ assert ->has ('data ' , function ($ bar ) {
217
+ $ bar ->has (2 )
218
+ ->each (fn ($ json ) => $ json ->whereNot ('id ' , fn ($ value ) => $ value === 3 )->etc ());
219
+ });
220
+ }
221
+
222
+ public function testAssertHasWithWhereNotFailsClosure ()
223
+ {
224
+ $ assert = AssertableJson::fromArray ([
225
+ 'data ' => [
226
+ [
227
+ 'id ' => 1 ,
228
+ 'name ' => 'Taylor ' ,
229
+ ],
230
+ [
231
+ 'id ' => 2 ,
232
+ 'name ' => 'Mateus ' ,
233
+ ],
234
+ ],
235
+ ]);
236
+
237
+ $ this ->expectException (AssertionFailedError::class);
238
+ $ this ->expectExceptionMessage ('Property [data.1.id] was marked as invalid using a closure. ' );
239
+
240
+ $ assert ->has ('data ' , function ($ bar ) {
241
+ $ bar ->has (2 )
242
+ ->each (fn ($ json ) => $ json ->whereNot ('id ' , fn ($ value ) => $ value === 2 )->etc ());
243
+ });
244
+ }
245
+
156
246
public function testAssertCount ()
157
247
{
158
248
$ assert = AssertableJson::fromArray ([
@@ -625,6 +715,64 @@ public function testAssertNestedWhereFailsWhenDoesNotMatchValue()
625
715
$ assert ->where ('example.nested ' , 'another-value ' );
626
716
}
627
717
718
+ public function testAssertWhereDoesNotMatchValue ()
719
+ {
720
+ $ assert = AssertableJson::fromArray ([
721
+ 'bar ' => 'value ' ,
722
+ ]);
723
+
724
+ $ assert ->whereNot ('bar ' , 'different_value ' );
725
+ }
726
+
727
+ public function testAssertWhereNotFailsWhenMatchingValue ()
728
+ {
729
+ $ assert = AssertableJson::fromArray ([
730
+ 'bar ' => 'value ' ,
731
+ ]);
732
+
733
+ $ this ->expectException (AssertionFailedError::class);
734
+ $ this ->expectExceptionMessage ('Property [bar] contains a value that should be missing: [bar, value] ' );
735
+
736
+ $ assert ->whereNot ('bar ' , 'value ' );
737
+ }
738
+
739
+ public function testAssertWhereNotFailsWhenNotMissing ()
740
+ {
741
+ $ assert = AssertableJson::fromArray ([
742
+ 'bar ' => 'value ' ,
743
+ ]);
744
+
745
+ $ this ->expectException (AssertionFailedError::class);
746
+ $ this ->expectExceptionMessage ('Property [baz] does not exist. ' );
747
+
748
+ $ assert ->whereNot ('baz ' , 'value ' );
749
+ }
750
+
751
+ public function testAssertWhereNotUsingClosure ()
752
+ {
753
+ $ assert = AssertableJson::fromArray ([
754
+ 'bar ' => 'baz ' ,
755
+ ]);
756
+
757
+ $ assert ->whereNot ('bar ' , function ($ value ) {
758
+ return $ value === 'foo ' ;
759
+ });
760
+ }
761
+
762
+ public function testAssertWhereNotFailsWhenMatchesValueUsingClosure ()
763
+ {
764
+ $ assert = AssertableJson::fromArray ([
765
+ 'bar ' => 'baz ' ,
766
+ ]);
767
+
768
+ $ this ->expectException (AssertionFailedError::class);
769
+ $ this ->expectExceptionMessage ('Property [bar] was marked as invalid using a closure. ' );
770
+
771
+ $ assert ->whereNot ('bar ' , function ($ value ) {
772
+ return $ value === 'baz ' ;
773
+ });
774
+ }
775
+
628
776
public function testScope ()
629
777
{
630
778
$ assert = AssertableJson::fromArray ([
0 commit comments