Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional DB test fixes #38699

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/Database/DatabaseConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testBeginTransactionMethodRetriesOnFailure()
{
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
$pdo->method('beginTransaction')
->willReturnOnConsecutiveCalls($this->throwException(new ErrorException('server has gone away')));
->willReturnOnConsecutiveCalls($this->throwException(new ErrorException('server has gone away')), true);
$connection = $this->getMockConnection(['reconnect'], $pdo);
$connection->expects($this->once())->method('reconnect');
$connection->beginTransaction();
Expand Down Expand Up @@ -324,7 +324,7 @@ public function testOnLostConnectionPDOIsSwappedOutsideTransaction()

$statement = m::mock(PDOStatement::class);
$statement->shouldReceive('execute')->once()->andThrow(new PDOException('server has gone away'));
$statement->shouldReceive('execute')->once()->andReturn('result');
$statement->shouldReceive('execute')->once()->andReturn(true);

$pdo->shouldReceive('prepare')->twice()->andReturn($statement);

Expand All @@ -336,7 +336,7 @@ public function testOnLostConnectionPDOIsSwappedOutsideTransaction()
$called = true;
});

$this->assertSame('result', $connection->statement('foo'));
$this->assertTrue($connection->statement('foo'));

$this->assertTrue($called);
}
Expand Down
39 changes: 23 additions & 16 deletions tests/Database/DatabaseConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Connectors\SqlServerConnector;
use Mockery as m;
use PDO;
use PDOStatement;
use PHPUnit\Framework\TestCase;
use stdClass;

Expand All @@ -35,8 +36,9 @@ public function testMySqlConnectCallsCreateConnectionWithProperArguments($dsn, $
$connection = m::mock(PDO::class);
$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\' collate \'utf8_unicode_ci\'')->andReturn($connection);
$connection->shouldReceive('execute')->once();
$statement = m::mock(PDOStatement::class);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\' collate \'utf8_unicode_ci\'')->andReturn($statement);
$statement->shouldReceive('execute')->once();
$connection->shouldReceive('exec')->zeroOrMoreTimes();
$result = $connector->connect($config);

Expand All @@ -61,9 +63,10 @@ public function testMySqlConnectCallsCreateConnectionWithIsolationLevel()
$connection = m::mock(PDO::class);
$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\' collate \'utf8_unicode_ci\'')->andReturn($connection);
$connection->shouldReceive('prepare')->once()->with('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ')->andReturn($connection);
$connection->shouldReceive('execute')->zeroOrMoreTimes();
$statement = m::mock(PDOStatement::class);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\' collate \'utf8_unicode_ci\'')->andReturn($statement);
$connection->shouldReceive('prepare')->once()->with('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ')->andReturn($statement);
$statement->shouldReceive('execute')->zeroOrMoreTimes();
$connection->shouldReceive('exec')->zeroOrMoreTimes();
$result = $connector->connect($config);

Expand All @@ -78,8 +81,9 @@ public function testPostgresConnectCallsCreateConnectionWithProperArguments()
$connection = m::mock(stdClass::class);
$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('execute')->once();
$statement = m::mock(PDOStatement::class);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($statement);
$statement->shouldReceive('execute')->once();
$result = $connector->connect($config);

$this->assertSame($result, $connection);
Expand All @@ -93,9 +97,10 @@ public function testPostgresSearchPathIsSet()
$connection = m::mock(stdClass::class);
$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"')->andReturn($connection);
$connection->shouldReceive('execute')->twice();
$statement = m::mock(PDOStatement::class);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($statement);
$connection->shouldReceive('prepare')->once()->with('set search_path to "public"')->andReturn($statement);
$statement->shouldReceive('execute')->twice();
$result = $connector->connect($config);

$this->assertSame($result, $connection);
Expand All @@ -109,9 +114,10 @@ public function testPostgresSearchPathArraySupported()
$connection = m::mock(stdClass::class);
$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();
$statement = m::mock(PDOStatement::class);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($statement);
$connection->shouldReceive('prepare')->once()->with('set search_path to "public", "user"')->andReturn($statement);
$statement->shouldReceive('execute')->twice();
$result = $connector->connect($config);

$this->assertSame($result, $connection);
Expand All @@ -125,9 +131,10 @@ public function testPostgresApplicationNameIsSet()
$connection = m::mock(stdClass::class);
$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 application_name to \'Laravel App\'')->andReturn($connection);
$connection->shouldReceive('execute')->twice();
$statement = m::mock(PDOStatement::class);
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($statement);
$connection->shouldReceive('prepare')->once()->with('set application_name to \'Laravel App\'')->andReturn($statement);
$statement->shouldReceive('execute')->twice();
$result = $connector->connect($config);

$this->assertSame($result, $connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testSyncReturnValueType()
});

$user->articles->each(function (BelongsToManySyncTestTestArticle $article) {
$this->assertSame('0', $article->pivot->visible);
$this->assertEquals('0', $article->pivot->visible);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason here is that sqlite now returns integers instead of strings for integer valued columns, in PHP 8.1.

});
}

Expand All @@ -108,7 +108,7 @@ public function testSyncWithPivotDefaultsReturnValueType()
});

$user->articles->each(function (BelongsToManySyncTestTestArticle $article) {
$this->assertSame('1', $article->pivot->visible);
$this->assertEquals('1', $article->pivot->visible);
});
}

Expand Down