Rework the usage of the deprecated at() matcher

parent 568bf0c0
...@@ -54,7 +54,7 @@ final class LoggingTest extends TestCase ...@@ -54,7 +54,7 @@ final class LoggingTest extends TestCase
$logger->expects($this->once()) $logger->expects($this->once())
->method('startQuery') ->method('startQuery')
->with($this->equalTo($expectedSQL), $this->equalTo([])); ->with($this->equalTo($expectedSQL), $this->equalTo([]));
$logger->expects($this->at(1)) $logger->expects($this->once())
->method('stopQuery'); ->method('stopQuery');
$connection = new Connection([], $driver); $connection = new Connection([], $driver);
......
...@@ -152,7 +152,7 @@ class ConnectionTest extends DbalTestCase ...@@ -152,7 +152,7 @@ class ConnectionTest extends DbalTestCase
$eventManager->addEventListener([Events::postConnect], $listenerMock); $eventManager->addEventListener([Events::postConnect], $listenerMock);
$driverMock = $this->createMock(Driver::class); $driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->at(0)) $driverMock->expects($this->once())
->method('connect'); ->method('connect');
$conn = new Connection([], $driverMock, new Configuration(), $eventManager); $conn = new Connection([], $driverMock, new Configuration(), $eventManager);
...@@ -846,13 +846,11 @@ EOF ...@@ -846,13 +846,11 @@ EOF
$originalException = new Exception('Original exception'); $originalException = new Exception('Original exception');
$fallbackException = new Exception('Fallback exception'); $fallbackException = new Exception('Fallback exception');
$driverMock->expects($this->at(0)) $driverMock->method('connect')
->method('connect') ->will(self::onConsecutiveCalls(
->willThrowException($originalException); self::throwException($originalException),
self::throwException($fallbackException)
$driverMock->expects($this->at(1)) ));
->method('connect')
->willThrowException($fallbackException);
$this->expectExceptionMessage($originalException->getMessage()); $this->expectExceptionMessage($originalException->getMessage());
......
...@@ -33,23 +33,12 @@ class OCI8StatementTest extends DbalTestCase ...@@ -33,23 +33,12 @@ class OCI8StatementTest extends DbalTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$statement->expects($this->at(0)) $statement->expects($this->exactly(3))
->method('bindValue') ->method('bindValue')
->with( ->withConsecutive(
$this->equalTo(1), [1, $params[0]],
$this->equalTo($params[0]) [2, $params[1]],
); [3, $params[2]],
$statement->expects($this->at(1))
->method('bindValue')
->with(
$this->equalTo(2),
$this->equalTo($params[1])
);
$statement->expects($this->at(2))
->method('bindValue')
->with(
$this->equalTo(3),
$this->equalTo($params[2])
); );
// the return value is irrelevant to the test // the return value is irrelevant to the test
......
...@@ -1174,29 +1174,17 @@ class ComparatorTest extends TestCase ...@@ -1174,29 +1174,17 @@ class ComparatorTest extends TestCase
->method('getNamespaces') ->method('getNamespaces')
->will($this->returnValue(['foo', 'bar'])); ->will($this->returnValue(['foo', 'bar']));
$fromSchema->expects($this->at(0)) $fromSchema->method('hasNamespace')
->method('hasNamespace') ->withConsecutive(['bar'], ['baz'])
->with('bar') ->willReturnOnConsecutiveCalls(true, false);
->will($this->returnValue(true));
$fromSchema->expects($this->at(1))
->method('hasNamespace')
->with('baz')
->will($this->returnValue(false));
$toSchema->expects($this->once()) $toSchema->expects($this->once())
->method('getNamespaces') ->method('getNamespaces')
->will($this->returnValue(['bar', 'baz'])); ->will($this->returnValue(['bar', 'baz']));
$toSchema->expects($this->at(1)) $toSchema->method('hasNamespace')
->method('hasNamespace') ->withConsecutive(['foo'], ['bar'])
->with('foo') ->willReturnOnConsecutiveCalls(false, true);
->will($this->returnValue(false));
$toSchema->expects($this->at(2))
->method('hasNamespace')
->with('bar')
->will($this->returnValue(true));
$expected = new SchemaDiff(); $expected = new SchemaDiff();
$expected->fromSchema = $fromSchema; $expected->fromSchema = $fromSchema;
......
...@@ -371,7 +371,7 @@ class SchemaTest extends TestCase ...@@ -371,7 +371,7 @@ class SchemaTest extends TestCase
[$schema->getSequence('war')] [$schema->getSequence('war')]
); );
self::assertNull($schema->visit($visitor)); $schema->visit($visitor);
} }
public function testVisitsNamespaceVisitor(): void public function testVisitsNamespaceVisitor(): void
...@@ -392,34 +392,24 @@ class SchemaTest extends TestCase ...@@ -392,34 +392,24 @@ class SchemaTest extends TestCase
->method('acceptSchema') ->method('acceptSchema')
->with($schema); ->with($schema);
$visitor->expects($this->at(1)) $visitor->expects($this->exactly(3))
->method('acceptNamespace') ->method('acceptNamespace')
->with('foo'); ->withConsecutive(['foo'], ['bar'], ['bla']);
$visitor->expects($this->at(2)) $visitor->expects($this->exactly(2))
->method('acceptNamespace')
->with('bar');
$visitor->expects($this->at(3))
->method('acceptNamespace')
->with('bla');
$visitor->expects($this->at(4))
->method('acceptTable') ->method('acceptTable')
->with($schema->getTable('baz')); ->withConsecutive(
[$schema->getTable('baz')],
$visitor->expects($this->at(5)) [$schema->getTable('bla.bloo')]
->method('acceptTable') );
->with($schema->getTable('bla.bloo'));
$visitor->expects($this->at(6))
->method('acceptSequence')
->with($schema->getSequence('moo'));
$visitor->expects($this->at(7)) $visitor->expects($this->exactly(2))
->method('acceptSequence') ->method('acceptSequence')
->with($schema->getSequence('war')); ->withConsecutive(
[$schema->getSequence('moo')],
[$schema->getSequence('war')]
);
self::assertNull($schema->visit($visitor)); $schema->visit($visitor);
} }
} }
...@@ -45,19 +45,20 @@ class CreateSchemaSqlCollectorTest extends TestCase ...@@ -45,19 +45,20 @@ class CreateSchemaSqlCollectorTest extends TestCase
->willReturn(['foo']); ->willReturn(['foo']);
} }
public function testAcceptsNamespace(): void public function testAcceptsNamespaceDoesNotSupportSchemas(): void
{ {
$this->platformMock->expects($this->at(0)) $this->platformMock->method('supportsSchemas')
->method('supportsSchemas') ->willReturn(false);
->will($this->returnValue(false));
$this->platformMock->expects($this->at(1))
->method('supportsSchemas')
->will($this->returnValue(true));
$this->visitor->acceptNamespace('foo'); $this->visitor->acceptNamespace('foo');
self::assertEmpty($this->visitor->getQueries()); self::assertEmpty($this->visitor->getQueries());
}
public function testAcceptsNamespaceSupportsSchemas(): void
{
$this->platformMock->method('supportsSchemas')
->willReturn(true);
$this->visitor->acceptNamespace('foo'); $this->visitor->acceptNamespace('foo');
...@@ -73,15 +74,10 @@ class CreateSchemaSqlCollectorTest extends TestCase ...@@ -73,15 +74,10 @@ class CreateSchemaSqlCollectorTest extends TestCase
self::assertSame(['foo'], $this->visitor->getQueries()); self::assertSame(['foo'], $this->visitor->getQueries());
} }
public function testAcceptsForeignKey(): void public function testAcceptsForeignKeyDoesNotSupportCreateDropForeignKeyConstraints(): void
{ {
$this->platformMock->expects($this->at(0)) $this->platformMock->method('supportsCreateDropForeignKeyConstraints')
->method('supportsCreateDropForeignKeyConstraints') ->willReturn(false);
->will($this->returnValue(false));
$this->platformMock->expects($this->at(1))
->method('supportsCreateDropForeignKeyConstraints')
->will($this->returnValue(true));
$table = $this->createTableMock(); $table = $this->createTableMock();
$foreignKey = $this->createForeignKeyConstraintMock(); $foreignKey = $this->createForeignKeyConstraintMock();
...@@ -89,6 +85,15 @@ class CreateSchemaSqlCollectorTest extends TestCase ...@@ -89,6 +85,15 @@ class CreateSchemaSqlCollectorTest extends TestCase
$this->visitor->acceptForeignKey($table, $foreignKey); $this->visitor->acceptForeignKey($table, $foreignKey);
self::assertEmpty($this->visitor->getQueries()); self::assertEmpty($this->visitor->getQueries());
}
public function testAcceptsForeignKeySupportsCreateDropForeignKeyConstraints(): void
{
$this->platformMock->method('supportsCreateDropForeignKeyConstraints')
->willReturn(true);
$table = $this->createTableMock();
$foreignKey = $this->createForeignKeyConstraintMock();
$this->visitor->acceptForeignKey($table, $foreignKey); $this->visitor->acceptForeignKey($table, $foreignKey);
......
...@@ -63,13 +63,11 @@ class PoolingShardManagerTest extends TestCase ...@@ -63,13 +63,11 @@ class PoolingShardManagerTest extends TestCase
$shardId = 10; $shardId = 10;
$conn = $this->createConnectionMock(); $conn = $this->createConnectionMock();
$conn->expects($this->at(0)) $conn->method('getParams')
->method('getParams')
->willReturn(['shardChoser' => $this->createPassthroughShardChoser()]); ->willReturn(['shardChoser' => $this->createPassthroughShardChoser()]);
$conn->expects($this->at(1)) $conn->method('connect')
->method('connect') ->with($shardId);
->with($this->equalTo($shardId));
$shardManager = new PoolingShardManager($conn); $shardManager = new PoolingShardManager($conn);
$shardManager->selectShard($shardId); $shardManager->selectShard($shardId);
...@@ -99,22 +97,24 @@ class PoolingShardManagerTest extends TestCase ...@@ -99,22 +97,24 @@ class PoolingShardManagerTest extends TestCase
$types = [1]; $types = [1];
$conn = $this->createConnectionMock(); $conn = $this->createConnectionMock();
$conn->expects($this->at(0))->method('getParams')->will($this->returnValue(
['shards' => [['id' => 1], ['id' => 2]], 'shardChoser' => $this->createPassthroughShardChoser()] $conn->method('getParams')->willReturn([
)); 'shards' => [
$conn->expects($this->at(1))->method('getParams')->will($this->returnValue( ['id' => 1],
['shards' => [['id' => 1], ['id' => 2]], 'shardChoser' => $this->createPassthroughShardChoser()] ['id' => 2],
)); ],
$conn->expects($this->at(2))->method('connect')->with($this->equalTo(1)); 'shardChoser' => $this->createPassthroughShardChoser(),
$conn->expects($this->at(3)) ]);
->method('fetchAllAssociative')
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) $conn->method('connect')
->will($this->returnValue([['id' => 1]])); ->withConsecutive([1], [2]);
$conn->expects($this->at(4))->method('connect')->with($this->equalTo(2));
$conn->expects($this->at(5)) $conn->method('fetchAllAssociative')
->method('fetchAllAssociative') ->with($sql, $params, $types)
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) ->willReturnOnConsecutiveCalls(
->will($this->returnValue([['id' => 2]])); [['id' => 1]],
[['id' => 2]],
);
$shardManager = new PoolingShardManager($conn); $shardManager = new PoolingShardManager($conn);
$result = $shardManager->queryAll($sql, $params, $types); $result = $shardManager->queryAll($sql, $params, $types);
...@@ -129,22 +129,24 @@ class PoolingShardManagerTest extends TestCase ...@@ -129,22 +129,24 @@ class PoolingShardManagerTest extends TestCase
$types = [1]; $types = [1];
$conn = $this->createConnectionMock(); $conn = $this->createConnectionMock();
$conn->expects($this->at(0))->method('getParams')->will($this->returnValue(
['shards' => [['id' => 1], ['id' => 2]], 'shardChoser' => $this->createStaticShardChooser()] $conn->method('getParams')->willReturn([
)); 'shards' => [
$conn->expects($this->at(1))->method('getParams')->will($this->returnValue( ['id' => 1],
['shards' => [['id' => 1], ['id' => 2]], 'shardChoser' => $this->createStaticShardChooser()] ['id' => 2],
)); ],
$conn->expects($this->at(2))->method('connect')->with($this->equalTo(1)); 'shardChoser' => $this->createStaticShardChooser(),
$conn->expects($this->at(3)) ]);
->method('fetchAllAssociative')
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) $conn->method('connect')
->will($this->returnValue([['id' => 1]])); ->withConsecutive([1], [2]);
$conn->expects($this->at(4))->method('connect')->with($this->equalTo(2));
$conn->expects($this->at(5)) $conn->method('fetchAllAssociative')
->method('fetchAllAssociative') ->with($sql, $params, $types)
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) ->willReturnOnConsecutiveCalls(
->will($this->returnValue([['id' => 2]])); [['id' => 1]],
[['id' => 2]],
);
$shardManager = new PoolingShardManager($conn); $shardManager = new PoolingShardManager($conn);
$result = $shardManager->queryAll($sql, $params, $types); $result = $shardManager->queryAll($sql, $params, $types);
......
...@@ -60,7 +60,8 @@ class SQLAzureShardManagerTest extends TestCase ...@@ -60,7 +60,8 @@ class SQLAzureShardManagerTest extends TestCase
], ],
]); ]);
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); $conn->method('isTransactionActive')
->willReturn(true);
$this->expectException(ShardingException::class); $this->expectException(ShardingException::class);
$this->expectExceptionMessage('Cannot switch shard during an active transaction.'); $this->expectExceptionMessage('Cannot switch shard during an active transaction.');
...@@ -79,8 +80,12 @@ class SQLAzureShardManagerTest extends TestCase ...@@ -79,8 +80,12 @@ class SQLAzureShardManagerTest extends TestCase
], ],
]); ]);
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); $conn->method('isTransactionActive')
$conn->expects($this->at(2))->method('exec')->with($this->equalTo('USE FEDERATION ROOT WITH RESET')); ->willReturn(false);
$conn->expects($this->once())
->method('exec')
->with('USE FEDERATION ROOT WITH RESET');
$sm = new SQLAzureShardManager($conn); $sm = new SQLAzureShardManager($conn);
$sm->selectGlobal(); $sm->selectGlobal();
...@@ -96,7 +101,8 @@ class SQLAzureShardManagerTest extends TestCase ...@@ -96,7 +101,8 @@ class SQLAzureShardManagerTest extends TestCase
], ],
]); ]);
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); $conn->method('isTransactionActive')
->willReturn(true);
$this->expectException(ShardingException::class); $this->expectException(ShardingException::class);
$this->expectExceptionMessage('Cannot switch shard during an active transaction.'); $this->expectExceptionMessage('Cannot switch shard during an active transaction.');
...@@ -118,7 +124,9 @@ class SQLAzureShardManagerTest extends TestCase ...@@ -118,7 +124,9 @@ class SQLAzureShardManagerTest extends TestCase
->onlyMethods(['getParams', 'exec', 'isTransactionActive']) ->onlyMethods(['getParams', 'exec', 'isTransactionActive'])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$conn->expects($this->at(0))->method('getParams')->will($this->returnValue($params));
$conn->method('getParams')
->willReturn($params);
return $conn; return $conn;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment