@@ -478,34 +478,59 @@ public function test_stale_reads(): void
478
478
$ this ->assertNotEmpty ($ timestamp );
479
479
480
480
$ timestampBound = new StrongRead ();
481
- $ rows = $ conn ->selectWithOptions ("SELECT * FROM $ { tableName} WHERE userID = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
481
+ $ rows = $ conn ->selectWithOptions ("SELECT * FROM { $ tableName } WHERE userId = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
482
482
$ this ->assertCount (1 , $ rows );
483
483
$ this ->assertSame ($ uuid , $ rows [0 ]['userId ' ]);
484
484
$ this ->assertSame ('first ' , $ rows [0 ]['name ' ]);
485
485
486
486
$ oldDatetime = Carbon::instance ($ timestamp ->get ())->subSecond ();
487
487
488
488
$ timestampBound = new ReadTimestamp ($ oldDatetime );
489
- $ rows = $ conn ->selectWithOptions ("SELECT * FROM $ { tableName} WHERE userID = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
489
+ $ rows = $ conn ->selectWithOptions ("SELECT * FROM { $ tableName } WHERE userId = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
490
490
$ this ->assertEmpty ($ rows );
491
491
492
492
$ timestampBound = new ExactStaleness (10 );
493
- $ rows = $ conn ->selectWithOptions ("SELECT * FROM $ { tableName} WHERE userID = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
493
+ $ rows = $ conn ->selectWithOptions ("SELECT * FROM { $ tableName } WHERE userId = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
494
494
$ this ->assertEmpty ($ rows );
495
495
496
496
$ timestampBound = new MaxStaleness (10 );
497
- $ rows = $ conn ->selectWithOptions ("SELECT * FROM $ { tableName} WHERE userID = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
497
+ $ rows = $ conn ->selectWithOptions ("SELECT * FROM { $ tableName } WHERE userId = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
498
498
$ this ->assertCount (1 , $ rows );
499
499
$ this ->assertSame ($ uuid , $ rows [0 ]['userId ' ]);
500
500
$ this ->assertSame ('first ' , $ rows [0 ]['name ' ]);
501
501
502
502
$ timestampBound = new MinReadTimestamp ($ oldDatetime );
503
- $ rows = $ conn ->selectWithOptions ("SELECT * FROM $ { tableName} WHERE userID = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
503
+ $ rows = $ conn ->selectWithOptions ("SELECT * FROM { $ tableName } WHERE userId = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
504
504
$ this ->assertCount (1 , $ rows );
505
505
$ this ->assertSame ($ uuid , $ rows [0 ]['userId ' ]);
506
506
$ this ->assertSame ('first ' , $ rows [0 ]['name ' ]);
507
507
}
508
508
509
+ public function test_stale_reads_in_transaction (): void
510
+ {
511
+ $ conn = $ this ->getDefaultConnection ();
512
+ $ tableName = self ::TABLE_NAME_USER ;
513
+ $ uuid = $ this ->generateUuid ();
514
+
515
+ $ conn ->transaction (function (Connection $ conn ) use ($ tableName , $ uuid ) {
516
+ $ conn ->insert ("INSERT INTO {$ tableName } (`userId`, `name`) VALUES (' {$ uuid }', 'first') " );
517
+
518
+ $ oldDatetime = now ()->subSecond ();
519
+
520
+ $ bounds = [
521
+ new StrongRead (),
522
+ new ExactStaleness (10 ),
523
+ new MaxStaleness (10 ),
524
+ new ReadTimestamp ($ oldDatetime ),
525
+ new MinReadTimestamp ($ oldDatetime ),
526
+ ];
527
+ foreach ($ bounds as $ timestampBound ) {
528
+ $ rows = $ conn ->selectWithOptions ("SELECT * FROM {$ tableName } WHERE userId = ? " , [$ uuid ], $ timestampBound ->transactionOptions ());
529
+ $ this ->assertEmpty ($ rows );
530
+ }
531
+ });
532
+ }
533
+
509
534
public function testEventListenOrder (): void
510
535
{
511
536
$ receivedEventClasses = [];
0 commit comments