diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index f5871db5d..d641556d2 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -14,7 +14,7 @@ class FindOneTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testFindOne(): void + public function testEloquentFindOne(): void { require_once __DIR__ . '/Movie.php'; @@ -25,12 +25,29 @@ public function testFindOne(): void // begin-eloquent-find-one $movie = Movie::where('directors', 'Rob Reiner') - ->orderBy('_id') + ->orderBy('id') ->first(); echo $movie->toJson(); // end-eloquent-find-one + $this->assertInstanceOf(Movie::class, $movie); + $this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/'); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testQBFindOne(): void + { + require_once __DIR__ . '/Movie.php'; + + Movie::truncate(); + Movie::insert([ + ['title' => 'The Shawshank Redemption', 'directors' => ['Frank Darabont', 'Rob Reiner']], + ]); + // begin-qb-find-one $movie = DB::table('movies') ->where('directors', 'Rob Reiner') @@ -40,8 +57,7 @@ public function testFindOne(): void echo $movie['title']; // end-qb-find-one - $this->assertInstanceOf(Movie::class, $movie); $this->assertSame($movie['title'], 'The Shawshank Redemption'); - $this->expectOutputString('{"_id":"679cdb4834e26dc5370de462","title":"The Shawshank Redemption","directors":["Frank Darabont","Rob Reiner"]}The Shawshank Redemption'); + $this->expectOutputString('The Shawshank Redemption'); } } diff --git a/docs/includes/usage-examples/InsertOneTest.php b/docs/includes/usage-examples/InsertOneTest.php index 0310c67dd..4b8a8bdb7 100644 --- a/docs/includes/usage-examples/InsertOneTest.php +++ b/docs/includes/usage-examples/InsertOneTest.php @@ -14,7 +14,7 @@ class InsertOneTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testInsertOne(): void + public function testEloquentInsertOne(): void { require_once __DIR__ . '/Movie.php'; @@ -30,6 +30,20 @@ public function testInsertOne(): void echo $movie->toJson(); // end-eloquent-insert-one + $this->assertInstanceOf(Movie::class, $movie); + $this->assertSame($movie->title, 'Marriage Story'); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testQBInsertOne(): void + { + require_once __DIR__ . '/Movie.php'; + + Movie::truncate(); + // begin-qb-insert-one $success = DB::table('movies') ->insert([ @@ -41,8 +55,6 @@ public function testInsertOne(): void echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); // end-qb-insert-one - $this->assertInstanceOf(Movie::class, $movie); - $this->assertSame($movie->title, 'Marriage Story'); - $this->expectOutputString('{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":"2025-01-31T14:16:40.834000Z","created_at":"2025-01-31T14:16:40.834000Z","_id":"679cdb488f9fa3d481091a42"}Insert operation success: yes'); + $this->expectOutputString('Insert operation success: yes'); } }