Skip to content
Permalink
Browse files

Remove use of TestCase::getMock() from "Database" namepace tests.

  • Loading branch information...
ADmad committed Jun 5, 2016
1 parent 3c8d034 commit a6f8945561c7570fbbe82e73c5ba378846059a81
@@ -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());
}
@@ -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'");
@@ -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'])
@@ -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) {
Oops, something went wrong.

0 comments on commit a6f8945

Please sign in to comment.
You can’t perform that action at this time.