diff --git a/tests/TestCase/Database/ConnectionTest.php b/tests/TestCase/Database/ConnectionTest.php index d3427314b67..eb8208249a2 100644 --- a/tests/TestCase/Database/ConnectionTest.php +++ b/tests/TestCase/Database/ConnectionTest.php @@ -112,7 +112,10 @@ public function testMissingDriver() */ public function testDisabledDriver() { - $mock = $this->getMock('\Cake\Database\Connection\Driver', ['enabled'], [], 'DriverMock'); + $mock = $this->getMockBuilder('\Cake\Database\Connection\Driver') + ->setMethods(['enabled']) + ->setMockClassName('DriverMock') + ->getMock(); $connection = new Connection(['driver' => $mock]); } @@ -686,7 +689,9 @@ public function testQuote() */ public function testQuoteIdentifier() { - $driver = $this->getMock('Cake\Database\Driver\Sqlite', ['enabled']); + $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlite') + ->setMethods(['enabled']) + ->getMock(); $driver->expects($this->once()) ->method('enabled') ->will($this->returnValue(true)); @@ -869,11 +874,10 @@ public function testLogBeginRollbackTransaction() public function testLogCommitTransaction() { $driver = $this->getMockFormDriver(); - $connection = $this->getMock( - '\Cake\Database\Connection', - ['connect'], - [['driver' => $driver]] - ); + $connection = $this->getMockBuilder('\Cake\Database\Connection') + ->setMethods(['connect']) + ->setConstructorArgs([['driver' => $driver]]) + ->getMock(); $logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger')->getMock(); $connection->logger($logger); @@ -897,11 +901,10 @@ public function testLogCommitTransaction() public function testTransactionalSuccess() { $driver = $this->getMockFormDriver(); - $connection = $this->getMock( - '\Cake\Database\Connection', - ['connect', 'commit', 'begin'], - [['driver' => $driver]] - ); + $connection = $this->getMockBuilder('\Cake\Database\Connection') + ->setMethods(['connect', 'commit', 'begin']) + ->setConstructorArgs([['driver' => $driver]]) + ->getMock(); $connection->expects($this->at(0))->method('begin'); $connection->expects($this->at(1))->method('commit'); $result = $connection->transactional(function ($conn) use ($connection) { @@ -920,11 +923,10 @@ public function testTransactionalSuccess() public function testTransactionalFail() { $driver = $this->getMockFormDriver(); - $connection = $this->getMock( - '\Cake\Database\Connection', - ['connect', 'commit', 'begin', 'rollback'], - [['driver' => $driver]] - ); + $connection = $this->getMockBuilder('\Cake\Database\Connection') + ->setMethods(['connect', 'commit', 'begin', 'rollback']) + ->setConstructorArgs([['driver' => $driver]]) + ->getMock(); $connection->expects($this->at(0))->method('begin'); $connection->expects($this->at(1))->method('rollback'); $connection->expects($this->never())->method('commit'); @@ -946,11 +948,10 @@ public function testTransactionalFail() public function testTransactionalWithException() { $driver = $this->getMockFormDriver(); - $connection = $this->getMock( - '\Cake\Database\Connection', - ['connect', 'commit', 'begin', 'rollback'], - [['driver' => $driver]] - ); + $connection = $this->getMockBuilder('\Cake\Database\Connection') + ->setMethods(['connect', 'commit', 'begin', 'rollback']) + ->setConstructorArgs([['driver' => $driver]]) + ->getMock(); $connection->expects($this->at(0))->method('begin'); $connection->expects($this->at(1))->method('rollback'); $connection->expects($this->never())->method('commit'); @@ -968,16 +969,17 @@ public function testTransactionalWithException() public function testSchemaCollection() { $driver = $this->getMockFormDriver(); - $connection = $this->getMock( - '\Cake\Database\Connection', - ['connect'], - [['driver' => $driver]] - ); + $connection = $this->getMockBuilder('\Cake\Database\Connection') + ->setMethods(['connect']) + ->setConstructorArgs([['driver' => $driver]]) + ->getMock(); $schema = $connection->schemaCollection(); $this->assertInstanceOf('Cake\Database\Schema\Collection', $schema); - $schema = $this->getMock('Cake\Database\Schema\Collection', [], [$connection]); + $schema = $this->getMockBuilder('Cake\Database\Schema\Collection') + ->setConstructorArgs([$connection]) + ->getMock(); $connection->schemaCollection($schema); $this->assertSame($schema, $connection->schemaCollection()); } diff --git a/tests/TestCase/Database/Driver/MysqlTest.php b/tests/TestCase/Database/Driver/MysqlTest.php index a2d3afdada8..b82efe45846 100644 --- a/tests/TestCase/Database/Driver/MysqlTest.php +++ b/tests/TestCase/Database/Driver/MysqlTest.php @@ -14,7 +14,6 @@ */ namespace Cake\Test\TestCase\Database\Driver; -use Cake\Core\Configure; use Cake\Datasource\ConnectionManager; use Cake\TestSuite\TestCase; use \PDO; @@ -45,7 +44,9 @@ public function setup() */ public function testConnectionConfigDefault() { - $driver = $this->getMock('Cake\Database\Driver\Mysql', ['_connect', 'connection']); + $driver = $this->getMockBuilder('Cake\Database\Driver\Mysql') + ->setMethods(['_connect', 'connection']) + ->getMock(); $dsn = 'mysql:host=localhost;port=3306;dbname=cake;charset=utf8'; $expected = [ 'persistent' => true, @@ -65,7 +66,9 @@ public function testConnectionConfigDefault() PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]; - $connection = $this->getMock('StdClass', ['exec']); + $connection = $this->getMockBuilder('StdClass') + ->setMethods(['exec']) + ->getMock(); $driver->expects($this->once())->method('_connect') ->with($dsn, $expected); @@ -98,11 +101,10 @@ public function testConnectionConfigCustom() 'this too', ] ]; - $driver = $this->getMock( - 'Cake\Database\Driver\Mysql', - ['_connect', 'connection'], - [$config] - ); + $driver = $this->getMockBuilder('Cake\Database\Driver\Mysql') + ->setMethods(['_connect', 'connection']) + ->setConstructorArgs([$config]) + ->getMock(); $dsn = 'mysql:host=foo;port=3440;dbname=bar;charset=a-language'; $expected = $config; $expected['init'][] = "SET time_zone = 'Antartica'"; @@ -113,7 +115,9 @@ public function testConnectionConfigCustom() PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]; - $connection = $this->getMock('StdClass', ['exec']); + $connection = $this->getMockBuilder('StdClass') + ->setMethods(['exec']) + ->getMock(); $connection->expects($this->at(0))->method('exec')->with('Execute this'); $connection->expects($this->at(1))->method('exec')->with('this too'); $connection->expects($this->at(2))->method('exec')->with("SET time_zone = 'Antartica'"); diff --git a/tests/TestCase/Database/Driver/PostgresTest.php b/tests/TestCase/Database/Driver/PostgresTest.php index 147252792be..30f9aad48ce 100644 --- a/tests/TestCase/Database/Driver/PostgresTest.php +++ b/tests/TestCase/Database/Driver/PostgresTest.php @@ -14,7 +14,6 @@ */ namespace Cake\Test\TestCase\Database\Driver; -use Cake\Core\Configure; use Cake\TestSuite\TestCase; use \PDO; @@ -31,7 +30,9 @@ class PostgresTest extends TestCase */ public function testConnectionConfigDefault() { - $driver = $this->getMock('Cake\Database\Driver\Postgres', ['_connect', 'connection']); + $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres') + ->setMethods(['_connect', 'connection']) + ->getMock(); $dsn = 'pgsql:host=localhost;port=5432;dbname=cake'; $expected = [ 'persistent' => true, @@ -53,7 +54,9 @@ public function testConnectionConfigDefault() PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]; - $connection = $this->getMock('stdClass', ['exec', 'quote']); + $connection = $this->getMockBuilder('stdClass') + ->setMethods(['exec', 'quote']) + ->getMock(); $connection->expects($this->any()) ->method('quote') ->will($this->onConsecutiveCalls( @@ -94,11 +97,10 @@ public function testConnectionConfigCustom() 'schema' => 'fooblic', 'init' => ['Execute this', 'this too'] ]; - $driver = $this->getMock( - 'Cake\Database\Driver\Postgres', - ['_connect', 'connection'], - [$config] - ); + $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres') + ->setMethods(['_connect', 'connection']) + ->setConstructorArgs([$config]) + ->getMock(); $dsn = 'pgsql:host=foo;port=3440;dbname=bar'; $expected = $config; @@ -108,7 +110,9 @@ public function testConnectionConfigCustom() PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]; - $connection = $this->getMock('stdClass', ['exec', 'quote']); + $connection = $this->getMockBuilder('stdClass') + ->setMethods(['exec', 'quote']) + ->getMock(); $connection->expects($this->any()) ->method('quote') ->will($this->onConsecutiveCalls( @@ -141,11 +145,10 @@ public function testConnectionConfigCustom() */ public function testInsertReturning() { - $driver = $this->getMock( - 'Cake\Database\Driver\Postgres', - ['_connect', 'connection'], - [[]] - ); + $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres') + ->setMethods(['_connect', 'connection']) + ->setConstructorArgs([[]]) + ->getMock(); $connection = $this ->getMockBuilder('\Cake\Database\Connection') ->setMethods(['connect']) diff --git a/tests/TestCase/Database/Driver/SqliteTest.php b/tests/TestCase/Database/Driver/SqliteTest.php index 6767baa0f51..da8ab9beb78 100644 --- a/tests/TestCase/Database/Driver/SqliteTest.php +++ b/tests/TestCase/Database/Driver/SqliteTest.php @@ -14,9 +14,8 @@ */ namespace Cake\Test\TestCase\Database\Driver; -use Cake\Core\Configure; use Cake\Database\Driver\Sqlite; -use Cake\Testsuite\TestCase; +use Cake\TestSuite\TestCase; use \PDO; /** @@ -32,7 +31,9 @@ class SqliteTest extends TestCase */ public function testConnectionConfigDefault() { - $driver = $this->getMock('Cake\Database\Driver\Sqlite', ['_connect']); + $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlite') + ->setMethods(['_connect']) + ->getMock(); $dsn = 'sqlite::memory:'; $expected = [ 'persistent' => false, @@ -69,11 +70,10 @@ public function testConnectionConfigCustom() 'encoding' => 'a-language', 'init' => ['Execute this', 'this too'] ]; - $driver = $this->getMock( - 'Cake\Database\driver\Sqlite', - ['_connect', 'connection'], - [$config] - ); + $driver = $this->getMockBuilder('Cake\Database\driver\Sqlite') + ->setMethods(['_connect', 'connection']) + ->setConstructorArgs([$config]) + ->getMock(); $dsn = 'sqlite:bar.db'; $expected = $config; @@ -84,7 +84,9 @@ public function testConnectionConfigCustom() PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]; - $connection = $this->getMock('StdClass', ['exec']); + $connection = $this->getMockBuilder('StdClass') + ->setMethods(['exec']) + ->getMock(); $connection->expects($this->at(0))->method('exec')->with('Execute this'); $connection->expects($this->at(1))->method('exec')->with('this too'); $connection->expects($this->exactly(2))->method('exec'); @@ -125,7 +127,9 @@ public static function schemaValueProvider() public function testSchemaValue($input, $expected) { $driver = new Sqlite(); - $mock = $this->getMock('FakePdo', ['quote', 'quoteIdentifier']); + $mock = $this->getMockBuilder('FakePdo') + ->setMethods(['quote', 'quoteIdentifier']) + ->getMock(); $mock->expects($this->any()) ->method('quote') ->will($this->returnCallback(function ($value) { diff --git a/tests/TestCase/Database/Driver/SqlserverTest.php b/tests/TestCase/Database/Driver/SqlserverTest.php index da3ec828441..1417140ce1a 100644 --- a/tests/TestCase/Database/Driver/SqlserverTest.php +++ b/tests/TestCase/Database/Driver/SqlserverTest.php @@ -54,11 +54,10 @@ public function testConnectionConfigCustom() 'init' => ['Execute this', 'this too'], 'settings' => ['config1' => 'value1', 'config2' => 'value2'], ]; - $driver = $this->getMock( - 'Cake\Database\Driver\Sqlserver', - ['_connect', 'connection'], - [$config] - ); + $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') + ->setMethods(['_connect', 'connection']) + ->setConstructorArgs([$config]) + ->getMock(); $dsn = 'sqlsrv:Server=foo;Database=bar;MultipleActiveResultSets=false'; $expected = $config; @@ -69,7 +68,9 @@ public function testConnectionConfigCustom() PDO::SQLSRV_ATTR_ENCODING => 'a-language' ]; - $connection = $this->getMock('stdClass', ['exec', 'quote']); + $connection = $this->getMockBuilder('stdClass') + ->setMethods(['exec', 'quote']) + ->getMock(); $connection->expects($this->any()) ->method('quote') ->will($this->onConsecutiveCalls( @@ -100,21 +101,19 @@ public function testConnectionConfigCustom() */ public function testSelectLimitVersion12() { - $driver = $this->getMock( - 'Cake\Database\Driver\Sqlserver', - ['_connect', 'connection', '_version'], - [[]] - ); + $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') + ->setMethods(['_connect', 'connection', '_version']) + ->setConstructorArgs([[]]) + ->getMock(); $driver ->expects($this->any()) ->method('_version') ->will($this->returnValue(12)); - $connection = $this->getMock( - '\Cake\Database\Connection', - ['connect', 'driver'], - [['log' => false]] - ); + $connection = $this->getMockBuilder('\Cake\Database\Connection') + ->setMethods(['connect', 'driver']) + ->setConstructorArgs([['log' => false]]) + ->getMock(); $connection ->expects($this->any()) ->method('driver') @@ -155,21 +154,19 @@ public function testSelectLimitVersion12() */ public function testSelectLimitOldServer() { - $driver = $this->getMock( - 'Cake\Database\Driver\Sqlserver', - ['_connect', 'connection', '_version'], - [[]] - ); + $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') + ->setMethods(['_connect', 'connection', '_version']) + ->setConstructorArgs([[]]) + ->getMock(); $driver ->expects($this->any()) ->method('_version') ->will($this->returnValue(8)); - $connection = $this->getMock( - '\Cake\Database\Connection', - ['connect', 'driver'], - [['log' => false]] - ); + $connection = $this->getMockBuilder('\Cake\Database\Connection') + ->setMethods(['connect', 'driver']) + ->setConstructorArgs([['log' => false]]) + ->getMock(); $connection ->expects($this->any()) ->method('driver') @@ -221,16 +218,14 @@ public function testSelectLimitOldServer() */ public function testInsertUsesOutput() { - $driver = $this->getMock( - 'Cake\Database\Driver\Sqlserver', - ['_connect', 'connection'], - [[]] - ); - $connection = $this->getMock( - '\Cake\Database\Connection', - ['connect', 'driver'], - [['log' => false]] - ); + $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') + ->setMethods(['_connect', 'connection']) + ->setConstructorArgs([[]]) + ->getMock(); + $connection = $this->getMockBuilder('\Cake\Database\Connection') + ->setMethods(['connect', 'driver']) + ->setConstructorArgs([['log' => false]]) + ->getMock(); $connection ->expects($this->any()) ->method('driver') diff --git a/tests/TestCase/Database/Log/QueryLoggerTest.php b/tests/TestCase/Database/Log/QueryLoggerTest.php index 0a2ceb41e0a..36b1cb8345b 100644 --- a/tests/TestCase/Database/Log/QueryLoggerTest.php +++ b/tests/TestCase/Database/Log/QueryLoggerTest.php @@ -55,7 +55,9 @@ public function tearDown() */ public function testStringInterpolation() { - $logger = $this->getMock('\Cake\Database\Log\QueryLogger', ['_log']); + $logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger') + ->setMethods(['_log']) + ->getMock(); $query = new LoggedQuery; $query->query = 'SELECT a FROM b where a = :p1 AND b = :p2 AND c = :p3 AND d = :p4 AND e = :p5 AND f = :p6'; $query->params = ['p1' => 'string', 'p3' => null, 'p2' => 3, 'p4' => true, 'p5' => false, 'p6' => 0]; @@ -73,7 +75,9 @@ public function testStringInterpolation() */ public function testStringInterpolation2() { - $logger = $this->getMock('\Cake\Database\Log\QueryLogger', ['_log']); + $logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger') + ->setMethods(['_log']) + ->getMock(); $query = new LoggedQuery; $query->query = 'SELECT a FROM b where a = ? AND b = ? AND c = ? AND d = ? AND e = ? AND f = ?'; $query->params = ['string', '3', null, true, false, 0]; @@ -91,7 +95,9 @@ public function testStringInterpolation2() */ public function testStringInterpolation3() { - $logger = $this->getMock('\Cake\Database\Log\QueryLogger', ['_log']); + $logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger') + ->setMethods(['_log']) + ->getMock(); $query = new LoggedQuery; $query->query = 'SELECT a FROM b where a = :p1 AND b = :p1 AND c = :p2 AND d = :p2'; $query->params = ['p1' => 'string', 'p2' => 3]; @@ -109,7 +115,9 @@ public function testStringInterpolation3() */ public function testStringInterpolationNamed() { - $logger = $this->getMock('\Cake\Database\Log\QueryLogger', ['_log']); + $logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger') + ->setMethods(['_log']) + ->getMock(); $query = new LoggedQuery; $query->query = 'SELECT a FROM b where a = :p1 AND b = :p11 AND c = :p20 AND d = :p2'; $query->params = ['p11' => 'test', 'p1' => 'string', 'p2' => 3, 'p20' => 5]; @@ -133,10 +141,16 @@ public function testLogFunction() $query->query = 'SELECT a FROM b where a = ? AND b = ? AND c = ?'; $query->params = ['string', '3', null]; - $engine = $this->getMock('\Cake\Log\Engine\BaseLog', ['log'], ['scopes' => ['queriesLog']]); + $engine = $this->getMockBuilder('\Cake\Log\Engine\BaseLog') + ->setMethods(['log']) + ->setConstructorArgs(['scopes' => ['queriesLog']]) + ->getMock(); Log::engine('queryLoggerTest'); - $engine2 = $this->getMock('\Cake\Log\Engine\BaseLog', ['log'], ['scopes' => ['foo']]); + $engine2 = $this->getMockBuilder('\Cake\Log\Engine\BaseLog') + ->setMethods(['log']) + ->setConstructorArgs(['scopes' => ['foo']]) + ->getMock(); Log::engine('queryLoggerTest2'); $engine2->expects($this->never())->method('log'); diff --git a/tests/TestCase/Database/Schema/MysqlSchemaTest.php b/tests/TestCase/Database/Schema/MysqlSchemaTest.php index f3d33805196..171b07590c8 100644 --- a/tests/TestCase/Database/Schema/MysqlSchemaTest.php +++ b/tests/TestCase/Database/Schema/MysqlSchemaTest.php @@ -14,7 +14,6 @@ */ namespace Cake\Test\TestCase\Database\Schema; -use Cake\Core\Configure; use Cake\Database\Schema\Collection as SchemaCollection; use Cake\Database\Schema\MysqlSchema; use Cake\Database\Schema\Table; @@ -195,7 +194,9 @@ public function testConvertColumn($type, $expected) $driver = $this->getMockBuilder('Cake\Database\Driver\Mysql')->getMock(); $dialect = new MysqlSchema($driver); - $table = $this->getMock('Cake\Database\Schema\Table', [], ['table']); + $table = $this->getMockBuilder('Cake\Database\Schema\Table') + ->setConstructorArgs(['table']) + ->getMock(); $table->expects($this->at(0))->method('addColumn')->with('field', $expected); $dialect->convertColumnDescription($table, $field); @@ -776,7 +777,9 @@ public function testIndexSql($name, $data, $expected) public function testAddConstraintSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -825,7 +828,9 @@ public function testAddConstraintSql() public function testDropConstraintSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -909,7 +914,9 @@ public function testColumnSqlPrimaryKey() public function testCreateSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -959,7 +966,9 @@ public function testCreateSql() public function testCreateTemporary() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); $table = (new Table('schema_articles'))->addColumn('id', [ @@ -979,7 +988,9 @@ public function testCreateTemporary() public function testCreateSqlCompositeIntegerKey() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -1043,7 +1054,9 @@ public function testCreateSqlCompositeIntegerKey() public function testDropSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -1061,7 +1074,9 @@ public function testDropSql() public function testTruncateSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -1092,7 +1107,9 @@ public function testConstructConnectsDriver() protected function _getMockedDriver() { $driver = new \Cake\Database\Driver\Mysql(); - $mock = $this->getMock('FakePdo', ['quote']); + $mock = $this->getMockBuilder('FakePdo') + ->setMethods(['quote']) + ->getMock(); $mock->expects($this->any()) ->method('quote') ->will($this->returnCallback(function ($value) { diff --git a/tests/TestCase/Database/Schema/PostgresSchemaTest.php b/tests/TestCase/Database/Schema/PostgresSchemaTest.php index 6777f6f4d32..69316dee161 100644 --- a/tests/TestCase/Database/Schema/PostgresSchemaTest.php +++ b/tests/TestCase/Database/Schema/PostgresSchemaTest.php @@ -14,9 +14,7 @@ */ namespace Cake\Test\TestCase\Database\Schema; -use Cake\Core\Configure; use Cake\Database\Schema\Collection as SchemaCollection; -use Cake\Database\Schema\MysqlSchema; use Cake\Database\Schema\PostgresSchema; use Cake\Database\Schema\Table; use Cake\Datasource\ConnectionManager; @@ -229,7 +227,9 @@ public function testConvertColumn($type, $expected) $driver = $this->getMockBuilder('Cake\Database\Driver\Postgres')->getMock(); $dialect = new PostgresSchema($driver); - $table = $this->getMock('Cake\Database\Schema\Table', [], ['table']); + $table = $this->getMockBuilder('Cake\Database\Schema\Table') + ->setConstructorArgs(['table']) + ->getMock(); $table->expects($this->at(0))->method('addColumn')->with('field', $expected); $dialect->convertColumnDescription($table, $field); @@ -863,7 +863,9 @@ public function testConstraintSql($name, $data, $expected) public function testAddConstraintSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -912,7 +914,9 @@ public function testAddConstraintSql() public function testDropConstraintSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -961,7 +965,9 @@ public function testDropConstraintSql() public function testCreateSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -1016,7 +1022,9 @@ public function testCreateSql() public function testCreateTemporary() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); $table = (new Table('schema_articles'))->addColumn('id', [ @@ -1036,7 +1044,9 @@ public function testCreateTemporary() public function testCreateSqlCompositeIntegerKey() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -1100,7 +1110,9 @@ public function testCreateSqlCompositeIntegerKey() public function testDropSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -1118,7 +1130,9 @@ public function testDropSql() public function testTruncateSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -1136,12 +1150,14 @@ public function testTruncateSql() /** * Get a schema instance with a mocked driver/pdo instances * - * @return Driver + * @return \Cake\Database\Driver */ protected function _getMockedDriver() { $driver = new \Cake\Database\Driver\Postgres(); - $mock = $this->getMock('FakePdo', ['quote']); + $mock = $this->getMockBuilder('FakePdo') + ->setMethods(['quote']) + ->getMock(); $mock->expects($this->any()) ->method('quote') ->will($this->returnCallback(function ($value) { diff --git a/tests/TestCase/Database/Schema/SqliteSchemaTest.php b/tests/TestCase/Database/Schema/SqliteSchemaTest.php index 31960c03811..f9340e7422c 100644 --- a/tests/TestCase/Database/Schema/SqliteSchemaTest.php +++ b/tests/TestCase/Database/Schema/SqliteSchemaTest.php @@ -14,7 +14,6 @@ */ namespace Cake\Test\TestCase\Database\Schema; -use Cake\Core\Configure; use Cake\Database\Schema\Collection as SchemaCollection; use Cake\Database\Schema\SqliteSchema; use Cake\Database\Schema\Table; @@ -152,7 +151,9 @@ public function testConvertColumn($type, $expected) $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlite')->getMock(); $dialect = new SqliteSchema($driver); - $table = $this->getMock('Cake\Database\Schema\Table', [], ['table']); + $table = $this->getMockBuilder('Cake\Database\Schema\Table') + ->setConstructorArgs(['table']) + ->getMock(); $table->expects($this->at(1))->method('addColumn')->with('field', $expected); $dialect->convertColumnDescription($table, $field); @@ -193,7 +194,7 @@ public function testConvertCompositePrimaryKey() /** * Creates tables for testing listTables/describe() * - * @param Connection $connection + * @param \Cake\Database\Connection $connection * @return void */ protected function _createTables($connection) @@ -587,7 +588,9 @@ public static function columnSqlProvider() public function testAddConstraintSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -605,7 +608,9 @@ public function testAddConstraintSql() public function testDropConstraintSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -798,7 +803,9 @@ public function testIndexSql($name, $data, $expected) public function testCreateSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -846,7 +853,9 @@ public function testCreateSql() public function testCreateTemporary() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); $table = (new Table('schema_articles'))->addColumn('id', [ @@ -866,7 +875,9 @@ public function testCreateTemporary() public function testCreateSqlCompositeIntegerKey() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -932,7 +943,9 @@ public function testCreateSqlCompositeIntegerKey() public function testDropSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -950,14 +963,15 @@ public function testDropSql() public function testTruncateSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); - $statement = $this->getMock( - '\PDOStatement', - ['execute', 'rowCount', 'closeCursor', 'fetch'] - ); + $statement = $this->getMockBuilder('\PDOStatement') + ->setMethods(['execute', 'rowCount', 'closeCursor', 'fetch']) + ->getMock(); $driver->connection()->expects($this->once())->method('prepare') ->with('SELECT 1 FROM sqlite_master WHERE name = "sqlite_sequence"') ->will($this->returnValue($statement)); @@ -981,14 +995,15 @@ public function testTruncateSql() public function testTruncateSqlNoSequences() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); - $statement = $this->getMock( - '\PDOStatement', - ['execute', 'rowCount', 'closeCursor', 'fetch'] - ); + $statement = $this->getMockBuilder('\PDOStatement') + ->setMethods(['execute', 'rowCount', 'closeCursor', 'fetch']) + ->getMock(); $driver->connection()->expects($this->once())->method('prepare') ->with('SELECT 1 FROM sqlite_master WHERE name = "sqlite_sequence"') ->will($this->returnValue($statement)); @@ -1004,12 +1019,14 @@ public function testTruncateSqlNoSequences() /** * Get a schema instance with a mocked driver/pdo instances * - * @return Driver + * @return \Cake\Database\Driver */ protected function _getMockedDriver() { $driver = new \Cake\Database\Driver\Sqlite(); - $mock = $this->getMock('FakePdo', ['quote', 'prepare']); + $mock = $this->getMockBuilder('FakePdo') + ->setMethods(['quote', 'prepare']) + ->getMock(); $mock->expects($this->any()) ->method('quote') ->will($this->returnCallback(function ($value) { diff --git a/tests/TestCase/Database/Schema/SqlserverSchemaTest.php b/tests/TestCase/Database/Schema/SqlserverSchemaTest.php index 816500dd75e..65083452b0b 100644 --- a/tests/TestCase/Database/Schema/SqlserverSchemaTest.php +++ b/tests/TestCase/Database/Schema/SqlserverSchemaTest.php @@ -14,7 +14,6 @@ */ namespace Cake\Test\TestCase\Database\Schema; -use Cake\Core\Configure; use Cake\Database\Schema\Collection as SchemaCollection; use Cake\Database\Schema\SqlserverSchema; use Cake\Database\Schema\Table; @@ -248,7 +247,9 @@ public function testConvertColumn($type, $length, $precision, $scale, $expected) $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver')->getMock(); $dialect = new SqlserverSchema($driver); - $table = $this->getMock('Cake\Database\Schema\Table', [], ['table']); + $table = $this->getMockBuilder('Cake\Database\Schema\Table') + ->setConstructorArgs(['table']) + ->getMock(); $table->expects($this->at(0))->method('addColumn')->with('field', $expected); $dialect->convertColumnDescription($table, $field); @@ -722,7 +723,9 @@ public function testConstraintSql($name, $data, $expected) public function testAddConstraintSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -771,7 +774,9 @@ public function testAddConstraintSql() public function testDropConstraintSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -820,7 +825,9 @@ public function testDropConstraintSql() public function testCreateSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -870,7 +877,9 @@ public function testCreateSql() public function testDropSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -888,7 +897,9 @@ public function testDropSql() public function testTruncateSql() { $driver = $this->_getMockedDriver(); - $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection = $this->getMockBuilder('Cake\Database\Connection') + ->disableOriginalConstructor() + ->getMock(); $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); @@ -907,12 +918,14 @@ public function testTruncateSql() /** * Get a schema instance with a mocked driver/pdo instances * - * @return Driver + * @return \Cake\Database\Driver */ protected function _getMockedDriver() { $driver = new \Cake\Database\Driver\Sqlserver(); - $mock = $this->getMock('FakePdo', ['quote']); + $mock = $this->getMockBuilder('FakePdo') + ->setMethods(['quote']) + ->getMock(); $mock->expects($this->any()) ->method('quote') ->will($this->returnCallback(function ($value) { diff --git a/tests/TestCase/Database/Type/BinaryTypeTest.php b/tests/TestCase/Database/Type/BinaryTypeTest.php index 25862b397b0..7cb3aab6412 100644 --- a/tests/TestCase/Database/Type/BinaryTypeTest.php +++ b/tests/TestCase/Database/Type/BinaryTypeTest.php @@ -62,7 +62,9 @@ public function testToPHP() */ public function testToPHPSqlserver() { - $driver = $this->getMock('Cake\Database\Driver\Sqlserver', [], [], '', false); + $driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver') + ->disableOriginalConstructor() + ->getMock(); $result = $this->type->toPHP('536F6D652076616C7565', $driver); $this->assertInternalType('resource', $result); $this->assertSame('Some value', stream_get_contents($result)); diff --git a/tests/TestCase/Database/Type/StringTypeTest.php b/tests/TestCase/Database/Type/StringTypeTest.php index 560cccd7aea..ed1dddffdcf 100644 --- a/tests/TestCase/Database/Type/StringTypeTest.php +++ b/tests/TestCase/Database/Type/StringTypeTest.php @@ -55,7 +55,9 @@ public function testToPHP() */ public function testToDatabase() { - $obj = $this->getMock('StdClass', ['__toString']); + $obj = $this->getMockBuilder('StdClass') + ->setMethods(['__toString']) + ->getMock(); $obj->method('__toString')->will($this->returnValue('toString called')); $this->assertNull($this->type->toDatabase(null, $this->driver));