Skip to content

Commit a6f8945

Browse files
committed
Remove use of TestCase::getMock() from "Database" namepace tests.
1 parent 3c8d034 commit a6f8945

12 files changed

+246
-157
lines changed

tests/TestCase/Database/ConnectionTest.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public function testMissingDriver()
112112
*/
113113
public function testDisabledDriver()
114114
{
115-
$mock = $this->getMock('\Cake\Database\Connection\Driver', ['enabled'], [], 'DriverMock');
115+
$mock = $this->getMockBuilder('\Cake\Database\Connection\Driver')
116+
->setMethods(['enabled'])
117+
->setMockClassName('DriverMock')
118+
->getMock();
116119
$connection = new Connection(['driver' => $mock]);
117120
}
118121

@@ -686,7 +689,9 @@ public function testQuote()
686689
*/
687690
public function testQuoteIdentifier()
688691
{
689-
$driver = $this->getMock('Cake\Database\Driver\Sqlite', ['enabled']);
692+
$driver = $this->getMockBuilder('Cake\Database\Driver\Sqlite')
693+
->setMethods(['enabled'])
694+
->getMock();
690695
$driver->expects($this->once())
691696
->method('enabled')
692697
->will($this->returnValue(true));
@@ -869,11 +874,10 @@ public function testLogBeginRollbackTransaction()
869874
public function testLogCommitTransaction()
870875
{
871876
$driver = $this->getMockFormDriver();
872-
$connection = $this->getMock(
873-
'\Cake\Database\Connection',
874-
['connect'],
875-
[['driver' => $driver]]
876-
);
877+
$connection = $this->getMockBuilder('\Cake\Database\Connection')
878+
->setMethods(['connect'])
879+
->setConstructorArgs([['driver' => $driver]])
880+
->getMock();
877881

878882
$logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger')->getMock();
879883
$connection->logger($logger);
@@ -897,11 +901,10 @@ public function testLogCommitTransaction()
897901
public function testTransactionalSuccess()
898902
{
899903
$driver = $this->getMockFormDriver();
900-
$connection = $this->getMock(
901-
'\Cake\Database\Connection',
902-
['connect', 'commit', 'begin'],
903-
[['driver' => $driver]]
904-
);
904+
$connection = $this->getMockBuilder('\Cake\Database\Connection')
905+
->setMethods(['connect', 'commit', 'begin'])
906+
->setConstructorArgs([['driver' => $driver]])
907+
->getMock();
905908
$connection->expects($this->at(0))->method('begin');
906909
$connection->expects($this->at(1))->method('commit');
907910
$result = $connection->transactional(function ($conn) use ($connection) {
@@ -920,11 +923,10 @@ public function testTransactionalSuccess()
920923
public function testTransactionalFail()
921924
{
922925
$driver = $this->getMockFormDriver();
923-
$connection = $this->getMock(
924-
'\Cake\Database\Connection',
925-
['connect', 'commit', 'begin', 'rollback'],
926-
[['driver' => $driver]]
927-
);
926+
$connection = $this->getMockBuilder('\Cake\Database\Connection')
927+
->setMethods(['connect', 'commit', 'begin', 'rollback'])
928+
->setConstructorArgs([['driver' => $driver]])
929+
->getMock();
928930
$connection->expects($this->at(0))->method('begin');
929931
$connection->expects($this->at(1))->method('rollback');
930932
$connection->expects($this->never())->method('commit');
@@ -946,11 +948,10 @@ public function testTransactionalFail()
946948
public function testTransactionalWithException()
947949
{
948950
$driver = $this->getMockFormDriver();
949-
$connection = $this->getMock(
950-
'\Cake\Database\Connection',
951-
['connect', 'commit', 'begin', 'rollback'],
952-
[['driver' => $driver]]
953-
);
951+
$connection = $this->getMockBuilder('\Cake\Database\Connection')
952+
->setMethods(['connect', 'commit', 'begin', 'rollback'])
953+
->setConstructorArgs([['driver' => $driver]])
954+
->getMock();
954955
$connection->expects($this->at(0))->method('begin');
955956
$connection->expects($this->at(1))->method('rollback');
956957
$connection->expects($this->never())->method('commit');
@@ -968,16 +969,17 @@ public function testTransactionalWithException()
968969
public function testSchemaCollection()
969970
{
970971
$driver = $this->getMockFormDriver();
971-
$connection = $this->getMock(
972-
'\Cake\Database\Connection',
973-
['connect'],
974-
[['driver' => $driver]]
975-
);
972+
$connection = $this->getMockBuilder('\Cake\Database\Connection')
973+
->setMethods(['connect'])
974+
->setConstructorArgs([['driver' => $driver]])
975+
->getMock();
976976

977977
$schema = $connection->schemaCollection();
978978
$this->assertInstanceOf('Cake\Database\Schema\Collection', $schema);
979979

980-
$schema = $this->getMock('Cake\Database\Schema\Collection', [], [$connection]);
980+
$schema = $this->getMockBuilder('Cake\Database\Schema\Collection')
981+
->setConstructorArgs([$connection])
982+
->getMock();
981983
$connection->schemaCollection($schema);
982984
$this->assertSame($schema, $connection->schemaCollection());
983985
}

tests/TestCase/Database/Driver/MysqlTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
namespace Cake\Test\TestCase\Database\Driver;
1616

17-
use Cake\Core\Configure;
1817
use Cake\Datasource\ConnectionManager;
1918
use Cake\TestSuite\TestCase;
2019
use \PDO;
@@ -45,7 +44,9 @@ public function setup()
4544
*/
4645
public function testConnectionConfigDefault()
4746
{
48-
$driver = $this->getMock('Cake\Database\Driver\Mysql', ['_connect', 'connection']);
47+
$driver = $this->getMockBuilder('Cake\Database\Driver\Mysql')
48+
->setMethods(['_connect', 'connection'])
49+
->getMock();
4950
$dsn = 'mysql:host=localhost;port=3306;dbname=cake;charset=utf8';
5051
$expected = [
5152
'persistent' => true,
@@ -65,7 +66,9 @@ public function testConnectionConfigDefault()
6566
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
6667
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
6768
];
68-
$connection = $this->getMock('StdClass', ['exec']);
69+
$connection = $this->getMockBuilder('StdClass')
70+
->setMethods(['exec'])
71+
->getMock();
6972

7073
$driver->expects($this->once())->method('_connect')
7174
->with($dsn, $expected);
@@ -98,11 +101,10 @@ public function testConnectionConfigCustom()
98101
'this too',
99102
]
100103
];
101-
$driver = $this->getMock(
102-
'Cake\Database\Driver\Mysql',
103-
['_connect', 'connection'],
104-
[$config]
105-
);
104+
$driver = $this->getMockBuilder('Cake\Database\Driver\Mysql')
105+
->setMethods(['_connect', 'connection'])
106+
->setConstructorArgs([$config])
107+
->getMock();
106108
$dsn = 'mysql:host=foo;port=3440;dbname=bar;charset=a-language';
107109
$expected = $config;
108110
$expected['init'][] = "SET time_zone = 'Antartica'";
@@ -113,7 +115,9 @@ public function testConnectionConfigCustom()
113115
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
114116
];
115117

116-
$connection = $this->getMock('StdClass', ['exec']);
118+
$connection = $this->getMockBuilder('StdClass')
119+
->setMethods(['exec'])
120+
->getMock();
117121
$connection->expects($this->at(0))->method('exec')->with('Execute this');
118122
$connection->expects($this->at(1))->method('exec')->with('this too');
119123
$connection->expects($this->at(2))->method('exec')->with("SET time_zone = 'Antartica'");

tests/TestCase/Database/Driver/PostgresTest.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
namespace Cake\Test\TestCase\Database\Driver;
1616

17-
use Cake\Core\Configure;
1817
use Cake\TestSuite\TestCase;
1918
use \PDO;
2019

@@ -31,7 +30,9 @@ class PostgresTest extends TestCase
3130
*/
3231
public function testConnectionConfigDefault()
3332
{
34-
$driver = $this->getMock('Cake\Database\Driver\Postgres', ['_connect', 'connection']);
33+
$driver = $this->getMockBuilder('Cake\Database\Driver\Postgres')
34+
->setMethods(['_connect', 'connection'])
35+
->getMock();
3536
$dsn = 'pgsql:host=localhost;port=5432;dbname=cake';
3637
$expected = [
3738
'persistent' => true,
@@ -53,7 +54,9 @@ public function testConnectionConfigDefault()
5354
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
5455
];
5556

56-
$connection = $this->getMock('stdClass', ['exec', 'quote']);
57+
$connection = $this->getMockBuilder('stdClass')
58+
->setMethods(['exec', 'quote'])
59+
->getMock();
5760
$connection->expects($this->any())
5861
->method('quote')
5962
->will($this->onConsecutiveCalls(
@@ -94,11 +97,10 @@ public function testConnectionConfigCustom()
9497
'schema' => 'fooblic',
9598
'init' => ['Execute this', 'this too']
9699
];
97-
$driver = $this->getMock(
98-
'Cake\Database\Driver\Postgres',
99-
['_connect', 'connection'],
100-
[$config]
101-
);
100+
$driver = $this->getMockBuilder('Cake\Database\Driver\Postgres')
101+
->setMethods(['_connect', 'connection'])
102+
->setConstructorArgs([$config])
103+
->getMock();
102104
$dsn = 'pgsql:host=foo;port=3440;dbname=bar';
103105

104106
$expected = $config;
@@ -108,7 +110,9 @@ public function testConnectionConfigCustom()
108110
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
109111
];
110112

111-
$connection = $this->getMock('stdClass', ['exec', 'quote']);
113+
$connection = $this->getMockBuilder('stdClass')
114+
->setMethods(['exec', 'quote'])
115+
->getMock();
112116
$connection->expects($this->any())
113117
->method('quote')
114118
->will($this->onConsecutiveCalls(
@@ -141,11 +145,10 @@ public function testConnectionConfigCustom()
141145
*/
142146
public function testInsertReturning()
143147
{
144-
$driver = $this->getMock(
145-
'Cake\Database\Driver\Postgres',
146-
['_connect', 'connection'],
147-
[[]]
148-
);
148+
$driver = $this->getMockBuilder('Cake\Database\Driver\Postgres')
149+
->setMethods(['_connect', 'connection'])
150+
->setConstructorArgs([[]])
151+
->getMock();
149152
$connection = $this
150153
->getMockBuilder('\Cake\Database\Connection')
151154
->setMethods(['connect'])

tests/TestCase/Database/Driver/SqliteTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
*/
1515
namespace Cake\Test\TestCase\Database\Driver;
1616

17-
use Cake\Core\Configure;
1817
use Cake\Database\Driver\Sqlite;
19-
use Cake\Testsuite\TestCase;
18+
use Cake\TestSuite\TestCase;
2019
use \PDO;
2120

2221
/**
@@ -32,7 +31,9 @@ class SqliteTest extends TestCase
3231
*/
3332
public function testConnectionConfigDefault()
3433
{
35-
$driver = $this->getMock('Cake\Database\Driver\Sqlite', ['_connect']);
34+
$driver = $this->getMockBuilder('Cake\Database\Driver\Sqlite')
35+
->setMethods(['_connect'])
36+
->getMock();
3637
$dsn = 'sqlite::memory:';
3738
$expected = [
3839
'persistent' => false,
@@ -69,11 +70,10 @@ public function testConnectionConfigCustom()
6970
'encoding' => 'a-language',
7071
'init' => ['Execute this', 'this too']
7172
];
72-
$driver = $this->getMock(
73-
'Cake\Database\driver\Sqlite',
74-
['_connect', 'connection'],
75-
[$config]
76-
);
73+
$driver = $this->getMockBuilder('Cake\Database\driver\Sqlite')
74+
->setMethods(['_connect', 'connection'])
75+
->setConstructorArgs([$config])
76+
->getMock();
7777
$dsn = 'sqlite:bar.db';
7878

7979
$expected = $config;
@@ -84,7 +84,9 @@ public function testConnectionConfigCustom()
8484
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
8585
];
8686

87-
$connection = $this->getMock('StdClass', ['exec']);
87+
$connection = $this->getMockBuilder('StdClass')
88+
->setMethods(['exec'])
89+
->getMock();
8890
$connection->expects($this->at(0))->method('exec')->with('Execute this');
8991
$connection->expects($this->at(1))->method('exec')->with('this too');
9092
$connection->expects($this->exactly(2))->method('exec');
@@ -125,7 +127,9 @@ public static function schemaValueProvider()
125127
public function testSchemaValue($input, $expected)
126128
{
127129
$driver = new Sqlite();
128-
$mock = $this->getMock('FakePdo', ['quote', 'quoteIdentifier']);
130+
$mock = $this->getMockBuilder('FakePdo')
131+
->setMethods(['quote', 'quoteIdentifier'])
132+
->getMock();
129133
$mock->expects($this->any())
130134
->method('quote')
131135
->will($this->returnCallback(function ($value) {

0 commit comments

Comments
 (0)