Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rustagir committed Jan 31, 2025
1 parent b5a25b6 commit cb4abe3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
24 changes: 20 additions & 4 deletions docs/includes/usage-examples/FindOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FindOneTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testFindOne(): void
public function testEloquentFindOne(): void
{
require_once __DIR__ . '/Movie.php';

Expand All @@ -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')
Expand All @@ -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');
}
}
20 changes: 16 additions & 4 deletions docs/includes/usage-examples/InsertOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class InsertOneTest extends TestCase
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testInsertOne(): void
public function testEloquentInsertOne(): void
{
require_once __DIR__ . '/Movie.php';

Expand All @@ -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([
Expand All @@ -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');
}
}

0 comments on commit cb4abe3

Please sign in to comment.