@@ -47,11 +47,11 @@ public function testFindExists(): void
47
47
48
48
$ customerQuery = new ActiveQuery (Customer::class);
49
49
50
- $ this ->assertTrue ($ customerQuery ->where (['[[id]] ' => 2 ])->exists ());
51
- $ this ->assertTrue ($ customerQuery ->where (['[[id]] ' => 2 ])->select ('[[name]] ' )->exists ());
50
+ $ this ->assertTrue (( clone $ customerQuery) ->where (['[[id]] ' => 2 ])->exists ());
51
+ $ this ->assertTrue (( clone $ customerQuery) ->where (['[[id]] ' => 2 ])->select ('[[name]] ' )->exists ());
52
52
53
- $ this ->assertFalse ($ customerQuery ->where (['[[id]] ' => 42 ])->exists ());
54
- $ this ->assertFalse ($ customerQuery ->where (['[[id]] ' => 42 ])->select ('[[name]] ' )->exists ());
53
+ $ this ->assertFalse (( clone $ customerQuery) ->where (['[[id]] ' => 42 ])->exists ());
54
+ $ this ->assertFalse (( clone $ customerQuery) ->where (['[[id]] ' => 42 ])->select ('[[name]] ' )->exists ());
55
55
}
56
56
57
57
public function testFindColumn (): void
@@ -191,12 +191,12 @@ public function testFindOneByColumnName(): void
191
191
$ customer = new ActiveQuery (Customer::class);
192
192
$ customerQuery = new CustomerQuery (Customer::class);
193
193
194
- $ arClass = $ customer ->findOne (['id ' => 1 ]);
194
+ $ arClass = ( clone $ customer) ->findOne (['id ' => 1 ]);
195
195
$ this ->assertEquals (1 , $ arClass ->getId ());
196
196
197
197
$ customerQuery ->joinWithProfile = true ;
198
198
199
- $ arClass = $ customer ->findOne (['customer.id ' => 1 ]);
199
+ $ arClass = ( clone $ customer) ->findOne (['customer.id ' => 1 ]);
200
200
$ this ->assertEquals (1 , $ arClass ->getId ());
201
201
202
202
$ customerQuery ->joinWithProfile = false ;
@@ -223,33 +223,33 @@ public function testFind(): void
223
223
224
224
/** find by a single primary key */
225
225
$ customerQuery = new ActiveQuery (Customer::class);
226
- $ customer = $ customerQuery ->findOne (2 );
226
+ $ customer = ( clone $ customerQuery) ->findOne (2 );
227
227
$ this ->assertInstanceOf (Customer::class, $ customer );
228
228
$ this ->assertEquals ('user2 ' , $ customer ->getName ());
229
229
230
- $ customer = $ customerQuery ->findOne (5 );
230
+ $ customer = ( clone $ customerQuery) ->findOne (5 );
231
231
$ this ->assertNull ($ customer );
232
232
233
233
$ customerQuery = new ActiveQuery (Customer::class);
234
- $ customer = $ customerQuery ->findOne (['id ' => [5 , 6 , 1 ]]);
234
+ $ customer = ( clone $ customerQuery) ->findOne (['id ' => [5 , 6 , 1 ]]);
235
235
$ this ->assertInstanceOf (Customer::class, $ customer );
236
236
237
- $ customer = $ customerQuery ->where (['id ' => [5 , 6 , 1 ]])->one ();
237
+ $ customer = ( clone $ customerQuery) ->where (['id ' => [5 , 6 , 1 ]])->one ();
238
238
$ this ->assertNotNull ($ customer );
239
239
240
240
/** find by column values */
241
241
$ customerQuery = new ActiveQuery (Customer::class);
242
- $ customer = $ customerQuery ->findOne (['id ' => 2 , 'name ' => 'user2 ' ]);
242
+ $ customer = ( clone $ customerQuery) ->findOne (['id ' => 2 , 'name ' => 'user2 ' ]);
243
243
$ this ->assertInstanceOf (Customer::class, $ customer );
244
244
$ this ->assertEquals ('user2 ' , $ customer ->getName ());
245
245
246
- $ customer = $ customerQuery ->findOne (['id ' => 2 , 'name ' => 'user1 ' ]);
246
+ $ customer = ( clone $ customerQuery) ->findOne (['id ' => 2 , 'name ' => 'user1 ' ]);
247
247
$ this ->assertNull ($ customer );
248
248
249
- $ customer = $ customerQuery ->findOne (['id ' => 5 ]);
249
+ $ customer = ( clone $ customerQuery) ->findOne (['id ' => 5 ]);
250
250
$ this ->assertNull ($ customer );
251
251
252
- $ customer = $ customerQuery ->findOne (['name ' => 'user5 ' ]);
252
+ $ customer = ( clone $ customerQuery) ->findOne (['name ' => 'user5 ' ]);
253
253
$ this ->assertNull ($ customer );
254
254
255
255
/** find by column */
@@ -379,10 +379,10 @@ public function testFindCount(): void
379
379
380
380
$ customerQuery = new ActiveQuery (Customer::class);
381
381
$ this ->assertEquals (3 , $ customerQuery ->count ());
382
- $ this ->assertEquals (1 , $ customerQuery ->where (['id ' => 1 ])->count ());
383
- $ this ->assertEquals (2 , $ customerQuery ->where (['id ' => [1 , 2 ]])->count ());
384
- $ this ->assertEquals (2 , $ customerQuery ->where (['id ' => [1 , 2 ]])->offset (1 )->count ());
385
- $ this ->assertEquals (2 , $ customerQuery ->where (['id ' => [1 , 2 ]])->offset (2 )->count ());
382
+ $ this ->assertEquals (1 , ( clone $ customerQuery) ->where (['id ' => 1 ])->count ());
383
+ $ this ->assertEquals (2 , ( clone $ customerQuery) ->where (['id ' => [1 , 2 ]])->count ());
384
+ $ this ->assertEquals (2 , ( clone $ customerQuery) ->where (['id ' => [1 , 2 ]])->offset (1 )->count ());
385
+ $ this ->assertEquals (2 , ( clone $ customerQuery) ->where (['id ' => [1 , 2 ]])->offset (2 )->count ());
386
386
387
387
$ customerQuery = new ActiveQuery (Customer::class);
388
388
$ this ->assertEquals (3 , $ customerQuery ->limit (1 )->count ());
@@ -450,32 +450,32 @@ public function testFindComplexCondition(): void
450
450
451
451
$ this ->assertEquals (
452
452
2 ,
453
- $ customerQuery ->where (['OR ' , ['name ' => 'user1 ' ], ['name ' => 'user2 ' ]])->count ()
453
+ ( clone $ customerQuery) ->where (['OR ' , ['name ' => 'user1 ' ], ['name ' => 'user2 ' ]])->count ()
454
454
);
455
455
456
456
$ this ->assertCount (
457
457
2 ,
458
- $ customerQuery ->where (['OR ' , ['name ' => 'user1 ' ], ['name ' => 'user2 ' ]])->all ()
458
+ ( clone $ customerQuery) ->where (['OR ' , ['name ' => 'user1 ' ], ['name ' => 'user2 ' ]])->all ()
459
459
);
460
460
461
461
$ this ->assertEquals (
462
462
2 ,
463
- $ customerQuery ->where (['name ' => ['user1 ' , 'user2 ' ]])->count ()
463
+ ( clone $ customerQuery) ->where (['name ' => ['user1 ' , 'user2 ' ]])->count ()
464
464
);
465
465
466
466
$ this ->assertCount (
467
467
2 ,
468
- $ customerQuery ->where (['name ' => ['user1 ' , 'user2 ' ]])->all ()
468
+ ( clone $ customerQuery) ->where (['name ' => ['user1 ' , 'user2 ' ]])->all ()
469
469
);
470
470
471
471
$ this ->assertEquals (
472
472
1 ,
473
- $ customerQuery ->where (['AND ' , ['name ' => ['user2 ' , 'user3 ' ]], ['BETWEEN ' , 'status ' , 2 , 4 ]])->count ()
473
+ ( clone $ customerQuery) ->where (['AND ' , ['name ' => ['user2 ' , 'user3 ' ]], ['BETWEEN ' , 'status ' , 2 , 4 ]])->count ()
474
474
);
475
475
476
476
$ this ->assertCount (
477
477
1 ,
478
- $ customerQuery ->where (['AND ' , ['name ' => ['user2 ' , 'user3 ' ]], ['BETWEEN ' , 'status ' , 2 , 4 ]])->all ()
478
+ ( clone $ customerQuery) ->where (['AND ' , ['name ' => ['user2 ' , 'user3 ' ]], ['BETWEEN ' , 'status ' , 2 , 4 ]])->all ()
479
479
);
480
480
}
481
481
@@ -485,11 +485,11 @@ public function testFindNullValues(): void
485
485
486
486
$ customerQuery = new ActiveQuery (Customer::class);
487
487
488
- $ customer = $ customerQuery ->findOne (2 );
488
+ $ customer = ( clone $ customerQuery) ->findOne (2 );
489
489
$ customer ->setName (null );
490
490
$ customer ->save ();
491
491
492
- $ result = $ customerQuery ->where (['name ' => null ])->all ();
492
+ $ result = ( clone $ customerQuery) ->where (['name ' => null ])->all ();
493
493
$ this ->assertCount (1 , $ result );
494
494
$ this ->assertEquals (2 , reset ($ result )->getPrimaryKey ());
495
495
}
@@ -649,16 +649,16 @@ public function testFindEmptyInCondition(): void
649
649
$ this ->checkFixture ($ this ->db (), 'customer ' );
650
650
651
651
$ customerQuery = new ActiveQuery (Customer::class);
652
- $ customers = $ customerQuery ->where (['id ' => [1 ]])->all ();
652
+ $ customers = ( clone $ customerQuery) ->where (['id ' => [1 ]])->all ();
653
653
$ this ->assertCount (1 , $ customers );
654
654
655
- $ customers = $ customerQuery ->where (['id ' => []])->all ();
655
+ $ customers = ( clone $ customerQuery) ->where (['id ' => []])->all ();
656
656
$ this ->assertCount (0 , $ customers );
657
657
658
- $ customers = $ customerQuery ->where (['IN ' , 'id ' , [1 ]])->all ();
658
+ $ customers = ( clone $ customerQuery) ->where (['IN ' , 'id ' , [1 ]])->all ();
659
659
$ this ->assertCount (1 , $ customers );
660
660
661
- $ customers = $ customerQuery ->where (['IN ' , 'id ' , []])->all ();
661
+ $ customers = ( clone $ customerQuery) ->where (['IN ' , 'id ' , []])->all ();
662
662
$ this ->assertCount (0 , $ customers );
663
663
}
664
664
@@ -667,15 +667,15 @@ public function testFindEagerIndexBy(): void
667
667
$ this ->checkFixture ($ this ->db (), 'order ' );
668
668
669
669
$ orderQuery = new ActiveQuery (Order::class);
670
- $ order = $ orderQuery ->with ('itemsIndexed ' )->where (['id ' => 1 ])->one ();
670
+ $ order = ( clone $ orderQuery) ->with ('itemsIndexed ' )->where (['id ' => 1 ])->one ();
671
671
$ this ->assertTrue ($ order ->isRelationPopulated ('itemsIndexed ' ));
672
672
673
673
$ items = $ order ->getItemsIndexed ();
674
674
$ this ->assertCount (2 , $ items );
675
675
$ this ->assertTrue (isset ($ items [1 ]));
676
676
$ this ->assertTrue (isset ($ items [2 ]));
677
677
678
- $ order = $ orderQuery ->with ('itemsIndexed ' )->where (['id ' => 2 ])->one ();
678
+ $ order = ( clone $ orderQuery) ->with ('itemsIndexed ' )->where (['id ' => 2 ])->one ();
679
679
$ this ->assertTrue ($ order ->isRelationPopulated ('itemsIndexed ' ));
680
680
681
681
$ items = $ order ->getItemsIndexed ();
0 commit comments