Skip to content

Commit

Permalink
Simplify mocking assertions. (#40786)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored Feb 3, 2022
1 parent 0a973b1 commit 5164e0e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions tests/Database/DatabaseConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ public function testPostgresSearchPathCommaSeparatedValueSupported()
$config = ['host' => 'foo', 'database' => 'bar', 'search_path' => 'public, "user"', 'charset' => 'utf8'];
$connector = $this->getMockBuilder('Illuminate\Database\Connectors\PostgresConnector')->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock('stdClass');
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set search_path to "public", "user"')->andReturn($connection);
$connection->shouldReceive('execute')->twice();
Expand All @@ -145,8 +145,8 @@ public function testPostgresSearchPathVariablesSupported()
$config = ['host' => 'foo', 'database' => 'bar', 'search_path' => '"$user", public, user', 'charset' => 'utf8'];
$connector = $this->getMockBuilder('Illuminate\Database\Connectors\PostgresConnector')->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock('stdClass');
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set search_path to "$user", "public", "user"')->andReturn($connection);
$connection->shouldReceive('execute')->twice();
Expand Down
6 changes: 3 additions & 3 deletions tests/Foundation/Testing/DatabaseMigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function __reflectAndSetupAccessibleForProtectedTraitMethod($methodName)
public function testRefreshTestDatabaseDefault()
{
$this->traitObject
->expects($this->exactly(1))
->expects($this->once())
->method('artisan')
->with('migrate:fresh', [
'--drop-views' => false,
Expand All @@ -64,7 +64,7 @@ public function testRefreshTestDatabaseWithDropViewsOption()
$this->traitObject->dropViews = true;

$this->traitObject
->expects($this->exactly(1))
->expects($this->once())
->method('artisan')
->with('migrate:fresh', [
'--drop-views' => true,
Expand All @@ -82,7 +82,7 @@ public function testRefreshTestDatabaseWithDropTypesOption()
$this->traitObject->dropTypes = true;

$this->traitObject
->expects($this->exactly(1))
->expects($this->once())
->method('artisan')
->with('migrate:fresh', [
'--drop-views' => false,
Expand Down
6 changes: 3 additions & 3 deletions tests/Foundation/Testing/RefreshDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function __reflectAndSetupAccessibleForProtectedTraitMethod($methodName)
public function testRefreshTestDatabaseDefault()
{
$this->traitObject
->expects($this->exactly(1))
->expects($this->once())
->method('artisan')
->with('migrate:fresh', [
'--drop-views' => false,
Expand All @@ -64,7 +64,7 @@ public function testRefreshTestDatabaseWithDropViewsOption()
$this->traitObject->dropViews = true;

$this->traitObject
->expects($this->exactly(1))
->expects($this->once())
->method('artisan')
->with('migrate:fresh', [
'--drop-views' => true,
Expand All @@ -82,7 +82,7 @@ public function testRefreshTestDatabaseWithDropTypesOption()
$this->traitObject->dropTypes = true;

$this->traitObject
->expects($this->exactly(1))
->expects($this->once())
->method('artisan')
->with('migrate:fresh', [
'--drop-views' => false,
Expand Down
4 changes: 1 addition & 3 deletions tests/Support/SupportNamespacedItemResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function testParsedItemsAreCached()
public function testParsedItemsMayBeFlushed()
{
$r = $this->getMockBuilder(NamespacedItemResolver::class)->onlyMethods(['parseBasicSegments', 'parseNamespacedSegments'])->getMock();
$r->expects($this->once())->method('parseBasicSegments')->will(
$this->returnValue(['bar'])
);
$r->expects($this->once())->method('parseBasicSegments')->willReturn(['bar']);

$r->setParsedKey('foo.bar', ['foo']);
$r->flushParsedKeys();
Expand Down

0 comments on commit 5164e0e

Please sign in to comment.