Skip to content

Commit cb4abe3

Browse files
committed
fix tests
1 parent b5a25b6 commit cb4abe3

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

docs/includes/usage-examples/FindOneTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FindOneTest extends TestCase
1414
* @runInSeparateProcess
1515
* @preserveGlobalState disabled
1616
*/
17-
public function testFindOne(): void
17+
public function testEloquentFindOne(): void
1818
{
1919
require_once __DIR__ . '/Movie.php';
2020

@@ -25,12 +25,29 @@ public function testFindOne(): void
2525

2626
// begin-eloquent-find-one
2727
$movie = Movie::where('directors', 'Rob Reiner')
28-
->orderBy('_id')
28+
->orderBy('id')
2929
->first();
3030

3131
echo $movie->toJson();
3232
// end-eloquent-find-one
3333

34+
$this->assertInstanceOf(Movie::class, $movie);
35+
$this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
36+
}
37+
38+
/**
39+
* @runInSeparateProcess
40+
* @preserveGlobalState disabled
41+
*/
42+
public function testQBFindOne(): void
43+
{
44+
require_once __DIR__ . '/Movie.php';
45+
46+
Movie::truncate();
47+
Movie::insert([
48+
['title' => 'The Shawshank Redemption', 'directors' => ['Frank Darabont', 'Rob Reiner']],
49+
]);
50+
3451
// begin-qb-find-one
3552
$movie = DB::table('movies')
3653
->where('directors', 'Rob Reiner')
@@ -40,8 +57,7 @@ public function testFindOne(): void
4057
echo $movie['title'];
4158
// end-qb-find-one
4259

43-
$this->assertInstanceOf(Movie::class, $movie);
4460
$this->assertSame($movie['title'], 'The Shawshank Redemption');
45-
$this->expectOutputString('{"_id":"679cdb4834e26dc5370de462","title":"The Shawshank Redemption","directors":["Frank Darabont","Rob Reiner"]}The Shawshank Redemption');
61+
$this->expectOutputString('The Shawshank Redemption');
4662
}
4763
}

docs/includes/usage-examples/InsertOneTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class InsertOneTest extends TestCase
1414
* @runInSeparateProcess
1515
* @preserveGlobalState disabled
1616
*/
17-
public function testInsertOne(): void
17+
public function testEloquentInsertOne(): void
1818
{
1919
require_once __DIR__ . '/Movie.php';
2020

@@ -30,6 +30,20 @@ public function testInsertOne(): void
3030
echo $movie->toJson();
3131
// end-eloquent-insert-one
3232

33+
$this->assertInstanceOf(Movie::class, $movie);
34+
$this->assertSame($movie->title, 'Marriage Story');
35+
}
36+
37+
/**
38+
* @runInSeparateProcess
39+
* @preserveGlobalState disabled
40+
*/
41+
public function testQBInsertOne(): void
42+
{
43+
require_once __DIR__ . '/Movie.php';
44+
45+
Movie::truncate();
46+
3347
// begin-qb-insert-one
3448
$success = DB::table('movies')
3549
->insert([
@@ -41,8 +55,6 @@ public function testInsertOne(): void
4155
echo 'Insert operation success: ' . ($success ? 'yes' : 'no');
4256
// end-qb-insert-one
4357

44-
$this->assertInstanceOf(Movie::class, $movie);
45-
$this->assertSame($movie->title, 'Marriage Story');
46-
$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');
58+
$this->expectOutputString('Insert operation success: yes');
4759
}
4860
}

0 commit comments

Comments
 (0)