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

Create stubs instead of mocks #6564

Merged
merged 1 commit into from
Oct 21, 2024
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
74 changes: 37 additions & 37 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ protected function setUp(): void
/** @return Connection&MockObject */
private function getExecuteStatementMockConnection(): Connection
{
$driverMock = $this->createMock(Driver::class);
$driver = $this->createStub(Driver::class);

$driverMock
$driver
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);

$platform = $this->getMockForAbstractClass(AbstractPlatform::class);

return $this->getMockBuilder(Connection::class)
->onlyMethods(['executeStatement'])
->setConstructorArgs([['platform' => $platform], $driverMock])
->setConstructorArgs([['platform' => $platform], $driver])
->getMock();
}

Expand Down Expand Up @@ -183,13 +183,13 @@ public function testConnectDispatchEvent(): void
public function testTransactionBeginDispatchEvent(): void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
$driverMock
$driver = $this->createStub(Driver::class);
$driver
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$conn = new Connection([], $driver, new Configuration(), $eventManager);
$listenerMock = $this->createMock(TransactionBeginDispatchEventListener::class);
$listenerMock
->expects(self::exactly(1))
Expand All @@ -209,13 +209,13 @@ static function (TransactionBeginEventArgs $eventArgs) use ($conn): bool {
public function testTransactionCommitDispatchEvent(): void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
$driverMock
$driver = $this->createStub(Driver::class);
$driver
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$conn = new Connection([], $driver, new Configuration(), $eventManager);
$listenerMock = $this->createMock(TransactionCommitDispatchEventListener::class);
$listenerMock
->expects(self::exactly(1))
Expand All @@ -236,13 +236,13 @@ static function (TransactionCommitEventArgs $eventArgs) use ($conn): bool {
public function testTransactionCommitEventNotCalledAfterRollBack(): void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
$driverMock
$driver = $this->createStub(Driver::class);
$driver
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$conn = new Connection([], $driver, new Configuration(), $eventManager);
$rollBackListenerMock = $this->createMock(TransactionRollBackDispatchEventListener::class);
$rollBackListenerMock
->expects(self::exactly(1))
Expand Down Expand Up @@ -272,13 +272,13 @@ static function (TransactionRollBackEventArgs $eventArgs) use ($conn): bool {
public function testTransactionRollBackDispatchEvent(): void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
$driverMock
$driver = $this->createStub(Driver::class);
$driver
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$conn = new Connection([], $driver, new Configuration(), $eventManager);
$listenerMock = $this->createMock(TransactionRollBackDispatchEventListener::class);
$listenerMock
->expects(self::exactly(1))
Expand Down Expand Up @@ -306,7 +306,7 @@ public function testEventManagerPassedToPlatform(): void
->method('setEventManager')
->with($eventManager);

$driver = $this->createMock(Driver::class);
$driver = $this->createStub(Driver::class);
$driver
->method('getDatabasePlatform')
->willReturn($platform);
Expand Down Expand Up @@ -383,7 +383,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode(): void
$driverMock
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock);

Expand All @@ -398,13 +398,13 @@ public function testConnectStartsTransactionInNoAutoCommitMode(): void

public function testCommitStartsTransactionInNoAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock
$driver = $this->createStub(Driver::class);
$driver
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock);
$conn = new Connection([], $driver);

$conn->setAutoCommit(false);
$conn->connect();
Expand All @@ -420,12 +420,12 @@ public function testCommitReturn(bool $expectedResult): void
$driverConnection->expects(self::once())
->method('commit')->willReturn($expectedResult);

$driverMock = $this->createMock(Driver::class);
$driverMock
$driver = $this->createStub(Driver::class);
$driver
->method('connect')
->willReturn($driverConnection);

$conn = new Connection([], $driverMock);
$conn = new Connection([], $driver);

$conn->connect();
$conn->beginTransaction();
Expand All @@ -441,13 +441,13 @@ public static function resultProvider(): array

public function testRollBackStartsTransactionInNoAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock
$driver = $this->createStub(Driver::class);
$driver
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock);
$conn = new Connection([], $driver);

$conn->setAutoCommit(false);
$conn->connect();
Expand All @@ -458,13 +458,13 @@ public function testRollBackStartsTransactionInNoAutoCommitMode(): void

public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock
$driver = $this->createStub(Driver::class);
$driver
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class),
$this->createStub(DriverConnection::class),
);
$conn = new Connection([], $driverMock);
$conn = new Connection([], $driver);

$conn->connect();
$conn->beginTransaction();
Expand Down
2 changes: 1 addition & 1 deletion tests/Query/Expression/ExpressionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ExpressionBuilderTest extends TestCase

protected function setUp(): void
{
$conn = $this->createMock(Connection::class);
$conn = $this->createStub(Connection::class);

$this->expr = new ExpressionBuilder($conn);

Expand Down
2 changes: 1 addition & 1 deletion tests/Schema/Visitor/DropSchemaSqlCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testGetQueriesUsesAcceptedForeignKeys(): void

private function getStubKeyConstraint(string $name): ForeignKeyConstraint
{
$constraint = $this->createMock(ForeignKeyConstraint::class);
$constraint = $this->createStub(ForeignKeyConstraint::class);

$constraint
->method('getName')
Expand Down
Loading