Skip to content

Commit 1946a1e

Browse files
committed
Rework the usage of the deprecated at() matcher
1 parent 568bf0c commit 1946a1e

File tree

8 files changed

+105
-125
lines changed

8 files changed

+105
-125
lines changed

tests/Doctrine/Tests/DBAL/Connection/LoggingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function createConnection(DriverConnection $driverConnection, string $ex
5454
$logger->expects($this->once())
5555
->method('startQuery')
5656
->with($this->equalTo($expectedSQL), $this->equalTo([]));
57-
$logger->expects($this->at(1))
57+
$logger->expects($this->once())
5858
->method('stopQuery');
5959

6060
$connection = new Connection([], $driver);

tests/Doctrine/Tests/DBAL/ConnectionTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function testConnectDispatchEvent(): void
152152
$eventManager->addEventListener([Events::postConnect], $listenerMock);
153153

154154
$driverMock = $this->createMock(Driver::class);
155-
$driverMock->expects($this->at(0))
155+
$driverMock->expects($this->once())
156156
->method('connect');
157157

158158
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
@@ -846,13 +846,11 @@ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnecting
846846
$originalException = new Exception('Original exception');
847847
$fallbackException = new Exception('Fallback exception');
848848

849-
$driverMock->expects($this->at(0))
850-
->method('connect')
851-
->willThrowException($originalException);
852-
853-
$driverMock->expects($this->at(1))
854-
->method('connect')
855-
->willThrowException($fallbackException);
849+
$driverMock->method('connect')
850+
->will(self::onConsecutiveCalls(
851+
self::throwException($originalException),
852+
self::throwException($fallbackException)
853+
));
856854

857855
$this->expectExceptionMessage($originalException->getMessage());
858856

tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,12 @@ public function testExecute(array $params): void
3333
->disableOriginalConstructor()
3434
->getMock();
3535

36-
$statement->expects($this->at(0))
36+
$statement->expects($this->exactly(3))
3737
->method('bindValue')
38-
->with(
39-
$this->equalTo(1),
40-
$this->equalTo($params[0])
41-
);
42-
$statement->expects($this->at(1))
43-
->method('bindValue')
44-
->with(
45-
$this->equalTo(2),
46-
$this->equalTo($params[1])
47-
);
48-
$statement->expects($this->at(2))
49-
->method('bindValue')
50-
->with(
51-
$this->equalTo(3),
52-
$this->equalTo($params[2])
38+
->withConsecutive(
39+
[1, $params[0]],
40+
[2, $params[1]],
41+
[3, $params[2]],
5342
);
5443

5544
// the return value is irrelevant to the test

tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,29 +1174,17 @@ public function testComparesNamespaces(): void
11741174
->method('getNamespaces')
11751175
->will($this->returnValue(['foo', 'bar']));
11761176

1177-
$fromSchema->expects($this->at(0))
1178-
->method('hasNamespace')
1179-
->with('bar')
1180-
->will($this->returnValue(true));
1181-
1182-
$fromSchema->expects($this->at(1))
1183-
->method('hasNamespace')
1184-
->with('baz')
1185-
->will($this->returnValue(false));
1177+
$fromSchema->method('hasNamespace')
1178+
->withConsecutive(['bar'], ['baz'])
1179+
->willReturnOnConsecutiveCalls(true, false);
11861180

11871181
$toSchema->expects($this->once())
11881182
->method('getNamespaces')
11891183
->will($this->returnValue(['bar', 'baz']));
11901184

1191-
$toSchema->expects($this->at(1))
1192-
->method('hasNamespace')
1193-
->with('foo')
1194-
->will($this->returnValue(false));
1195-
1196-
$toSchema->expects($this->at(2))
1197-
->method('hasNamespace')
1198-
->with('bar')
1199-
->will($this->returnValue(true));
1185+
$toSchema->method('hasNamespace')
1186+
->withConsecutive(['foo'], ['bar'])
1187+
->willReturnOnConsecutiveCalls(false, true);
12001188

12011189
$expected = new SchemaDiff();
12021190
$expected->fromSchema = $fromSchema;

tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public function testVisitsVisitor(): void
371371
[$schema->getSequence('war')]
372372
);
373373

374-
self::assertNull($schema->visit($visitor));
374+
$schema->visit($visitor);
375375
}
376376

377377
public function testVisitsNamespaceVisitor(): void
@@ -392,34 +392,24 @@ public function testVisitsNamespaceVisitor(): void
392392
->method('acceptSchema')
393393
->with($schema);
394394

395-
$visitor->expects($this->at(1))
395+
$visitor->expects($this->exactly(3))
396396
->method('acceptNamespace')
397-
->with('foo');
397+
->withConsecutive(['foo'], ['bar'], ['bla']);
398398

399-
$visitor->expects($this->at(2))
400-
->method('acceptNamespace')
401-
->with('bar');
402-
403-
$visitor->expects($this->at(3))
404-
->method('acceptNamespace')
405-
->with('bla');
406-
407-
$visitor->expects($this->at(4))
399+
$visitor->expects($this->exactly(2))
408400
->method('acceptTable')
409-
->with($schema->getTable('baz'));
410-
411-
$visitor->expects($this->at(5))
412-
->method('acceptTable')
413-
->with($schema->getTable('bla.bloo'));
414-
415-
$visitor->expects($this->at(6))
416-
->method('acceptSequence')
417-
->with($schema->getSequence('moo'));
401+
->withConsecutive(
402+
[$schema->getTable('baz')],
403+
[$schema->getTable('bla.bloo')]
404+
);
418405

419-
$visitor->expects($this->at(7))
406+
$visitor->expects($this->exactly(2))
420407
->method('acceptSequence')
421-
->with($schema->getSequence('war'));
408+
->withConsecutive(
409+
[$schema->getSequence('moo')],
410+
[$schema->getSequence('war')]
411+
);
422412

423-
self::assertNull($schema->visit($visitor));
413+
$schema->visit($visitor);
424414
}
425415
}

tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ protected function setUp(): void
4545
->willReturn(['foo']);
4646
}
4747

48-
public function testAcceptsNamespace(): void
48+
public function testAcceptsNamespaceDoesNotSupportSchemas(): void
4949
{
50-
$this->platformMock->expects($this->at(0))
51-
->method('supportsSchemas')
52-
->will($this->returnValue(false));
53-
54-
$this->platformMock->expects($this->at(1))
55-
->method('supportsSchemas')
56-
->will($this->returnValue(true));
50+
$this->platformMock->method('supportsSchemas')
51+
->willReturn(false);
5752

5853
$this->visitor->acceptNamespace('foo');
5954

6055
self::assertEmpty($this->visitor->getQueries());
56+
}
57+
58+
public function testAcceptsNamespaceSupportsSchemas(): void
59+
{
60+
$this->platformMock->method('supportsSchemas')
61+
->willReturn(true);
6162

6263
$this->visitor->acceptNamespace('foo');
6364

@@ -73,22 +74,26 @@ public function testAcceptsTable(): void
7374
self::assertSame(['foo'], $this->visitor->getQueries());
7475
}
7576

76-
public function testAcceptsForeignKey(): void
77+
public function testAcceptsForeignKeyDoesNotSupportCreateDropForeignKeyConstraints(): void
7778
{
78-
$this->platformMock->expects($this->at(0))
79-
->method('supportsCreateDropForeignKeyConstraints')
80-
->will($this->returnValue(false));
81-
82-
$this->platformMock->expects($this->at(1))
83-
->method('supportsCreateDropForeignKeyConstraints')
84-
->will($this->returnValue(true));
79+
$this->platformMock->method('supportsCreateDropForeignKeyConstraints')
80+
->willReturn(false);
8581

8682
$table = $this->createTableMock();
8783
$foreignKey = $this->createForeignKeyConstraintMock();
8884

8985
$this->visitor->acceptForeignKey($table, $foreignKey);
9086

9187
self::assertEmpty($this->visitor->getQueries());
88+
}
89+
90+
public function testAcceptsForeignKeySupportsCreateDropForeignKeyConstraints(): void
91+
{
92+
$this->platformMock->method('supportsCreateDropForeignKeyConstraints')
93+
->willReturn(true);
94+
95+
$table = $this->createTableMock();
96+
$foreignKey = $this->createForeignKeyConstraintMock();
9297

9398
$this->visitor->acceptForeignKey($table, $foreignKey);
9499

tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ public function testSelectShard(): void
6363
$shardId = 10;
6464
$conn = $this->createConnectionMock();
6565

66-
$conn->expects($this->at(0))
67-
->method('getParams')
66+
$conn->method('getParams')
6867
->willReturn(['shardChoser' => $this->createPassthroughShardChoser()]);
6968

70-
$conn->expects($this->at(1))
71-
->method('connect')
72-
->with($this->equalTo($shardId));
69+
$conn->method('connect')
70+
->with($shardId);
7371

7472
$shardManager = new PoolingShardManager($conn);
7573
$shardManager->selectShard($shardId);
@@ -99,22 +97,24 @@ public function testQueryAll(): void
9997
$types = [1];
10098

10199
$conn = $this->createConnectionMock();
102-
$conn->expects($this->at(0))->method('getParams')->will($this->returnValue(
103-
['shards' => [['id' => 1], ['id' => 2]], 'shardChoser' => $this->createPassthroughShardChoser()]
104-
));
105-
$conn->expects($this->at(1))->method('getParams')->will($this->returnValue(
106-
['shards' => [['id' => 1], ['id' => 2]], 'shardChoser' => $this->createPassthroughShardChoser()]
107-
));
108-
$conn->expects($this->at(2))->method('connect')->with($this->equalTo(1));
109-
$conn->expects($this->at(3))
110-
->method('fetchAllAssociative')
111-
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types))
112-
->will($this->returnValue([['id' => 1]]));
113-
$conn->expects($this->at(4))->method('connect')->with($this->equalTo(2));
114-
$conn->expects($this->at(5))
115-
->method('fetchAllAssociative')
116-
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types))
117-
->will($this->returnValue([['id' => 2]]));
100+
101+
$conn->method('getParams')->willReturn([
102+
'shards' => [
103+
['id' => 1],
104+
['id' => 2],
105+
],
106+
'shardChoser' => $this->createPassthroughShardChoser(),
107+
]);
108+
109+
$conn->method('connect')
110+
->withConsecutive([1], [2]);
111+
112+
$conn->method('fetchAllAssociative')
113+
->with($sql, $params, $types)
114+
->willReturnOnConsecutiveCalls(
115+
[['id' => 1]],
116+
[['id' => 2]],
117+
);
118118

119119
$shardManager = new PoolingShardManager($conn);
120120
$result = $shardManager->queryAll($sql, $params, $types);
@@ -129,22 +129,24 @@ public function testQueryAllWithStaticShardChoser(): void
129129
$types = [1];
130130

131131
$conn = $this->createConnectionMock();
132-
$conn->expects($this->at(0))->method('getParams')->will($this->returnValue(
133-
['shards' => [['id' => 1], ['id' => 2]], 'shardChoser' => $this->createStaticShardChooser()]
134-
));
135-
$conn->expects($this->at(1))->method('getParams')->will($this->returnValue(
136-
['shards' => [['id' => 1], ['id' => 2]], 'shardChoser' => $this->createStaticShardChooser()]
137-
));
138-
$conn->expects($this->at(2))->method('connect')->with($this->equalTo(1));
139-
$conn->expects($this->at(3))
140-
->method('fetchAllAssociative')
141-
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types))
142-
->will($this->returnValue([['id' => 1]]));
143-
$conn->expects($this->at(4))->method('connect')->with($this->equalTo(2));
144-
$conn->expects($this->at(5))
145-
->method('fetchAllAssociative')
146-
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types))
147-
->will($this->returnValue([['id' => 2]]));
132+
133+
$conn->method('getParams')->willReturn([
134+
'shards' => [
135+
['id' => 1],
136+
['id' => 2],
137+
],
138+
'shardChoser' => $this->createStaticShardChooser(),
139+
]);
140+
141+
$conn->method('connect')
142+
->withConsecutive([1], [2]);
143+
144+
$conn->method('fetchAllAssociative')
145+
->with($sql, $params, $types)
146+
->willReturnOnConsecutiveCalls(
147+
[['id' => 1]],
148+
[['id' => 2]],
149+
);
148150

149151
$shardManager = new PoolingShardManager($conn);
150152
$result = $shardManager->queryAll($sql, $params, $types);

tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public function testSelectGlobalTransactionActive(): void
6060
],
6161
]);
6262

63-
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true));
63+
$conn->method('isTransactionActive')
64+
->willReturn(true);
6465

6566
$this->expectException(ShardingException::class);
6667
$this->expectExceptionMessage('Cannot switch shard during an active transaction.');
@@ -79,8 +80,12 @@ public function testSelectGlobal(): void
7980
],
8081
]);
8182

82-
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false));
83-
$conn->expects($this->at(2))->method('exec')->with($this->equalTo('USE FEDERATION ROOT WITH RESET'));
83+
$conn->method('isTransactionActive')
84+
->willReturn(false);
85+
86+
$conn->expects($this->once())
87+
->method('exec')
88+
->with('USE FEDERATION ROOT WITH RESET');
8489

8590
$sm = new SQLAzureShardManager($conn);
8691
$sm->selectGlobal();
@@ -96,7 +101,8 @@ public function testSelectShard(): void
96101
],
97102
]);
98103

99-
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true));
104+
$conn->method('isTransactionActive')
105+
->willReturn(true);
100106

101107
$this->expectException(ShardingException::class);
102108
$this->expectExceptionMessage('Cannot switch shard during an active transaction.');
@@ -118,7 +124,9 @@ private function createConnection(array $params): Connection
118124
->onlyMethods(['getParams', 'exec', 'isTransactionActive'])
119125
->disableOriginalConstructor()
120126
->getMock();
121-
$conn->expects($this->at(0))->method('getParams')->will($this->returnValue($params));
127+
128+
$conn->method('getParams')
129+
->willReturn($params);
122130

123131
return $conn;
124132
}

0 commit comments

Comments
 (0)