Skip to content

Commit

Permalink
Merge pull request #2435 from deeky666/fix-phpunit-deprecations
Browse files Browse the repository at this point in the history
Refactor deprecated PHPUnit_Framework_TestCase::getMock() calls
  • Loading branch information
Ocramius authored Jul 7, 2016
2 parents 97f423a + 1e67141 commit 8e8c5a1
Show file tree
Hide file tree
Showing 30 changed files with 136 additions and 113 deletions.
50 changes: 26 additions & 24 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ public function testGetEventManager()

public function testConnectDispatchEvent()
{
$listenerMock = $this->getMock('ConnectDispatchEventListener', array('postConnect'));
$listenerMock = $this->getMockBuilder('ConnectDispatchEventListener')
->setMethods(array('postConnect'))
->getMock();
$listenerMock->expects($this->once())->method('postConnect');

$eventManager = new EventManager();
$eventManager->addEventListener(array(Events::postConnect), $listenerMock);

$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');
$driverMock->expects(($this->at(0)))
->method('connect');
$platform = new Mocks\MockPlatform();
Expand Down Expand Up @@ -200,7 +202,7 @@ public function testSetAutoCommit()
*/
public function testConnectStartsTransactionInNoAutoCommitMode()
{
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(new DriverConnectionMock()));
Expand All @@ -220,7 +222,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode()
*/
public function testCommitStartsTransactionInNoAutoCommitMode()
{
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(new DriverConnectionMock()));
Expand All @@ -238,7 +240,7 @@ public function testCommitStartsTransactionInNoAutoCommitMode()
*/
public function testRollBackStartsTransactionInNoAutoCommitMode()
{
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(new DriverConnectionMock()));
Expand All @@ -256,7 +258,7 @@ public function testRollBackStartsTransactionInNoAutoCommitMode()
*/
public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions()
{
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(new DriverConnectionMock()));
Expand All @@ -278,7 +280,7 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions()

public function testEmptyInsert()
{
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');

$driverMock->expects($this->any())
->method('connect')
Expand All @@ -303,13 +305,13 @@ public function testFetchAssoc()
$types = array(\PDO::PARAM_INT);
$result = array();

$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');

$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(new DriverConnectionMock()));

$driverStatementMock = $this->getMock('Doctrine\Tests\Mocks\DriverStatementMock');
$driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock');

$driverStatementMock->expects($this->once())
->method('fetch')
Expand Down Expand Up @@ -337,13 +339,13 @@ public function testFetchArray()
$types = array(\PDO::PARAM_INT);
$result = array();

$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');

$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(new DriverConnectionMock()));

$driverStatementMock = $this->getMock('Doctrine\Tests\Mocks\DriverStatementMock');
$driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock');

$driverStatementMock->expects($this->once())
->method('fetch')
Expand Down Expand Up @@ -372,13 +374,13 @@ public function testFetchColumn()
$column = 0;
$result = array();

$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');

$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(new DriverConnectionMock()));

$driverStatementMock = $this->getMock('Doctrine\Tests\Mocks\DriverStatementMock');
$driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock');

$driverStatementMock->expects($this->once())
->method('fetchColumn')
Expand Down Expand Up @@ -429,13 +431,13 @@ public function testFetchAll()
$types = array(\PDO::PARAM_INT);
$result = array();

$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');

$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(new DriverConnectionMock()));

$driverStatementMock = $this->getMock('Doctrine\Tests\Mocks\DriverStatementMock');
$driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock');

$driverStatementMock->expects($this->once())
->method('fetchAll')
Expand All @@ -459,7 +461,7 @@ public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO()
{
$params['pdo'] = new \stdClass();

$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');

$conn = new Connection($params, $driverMock);

Expand All @@ -470,7 +472,7 @@ public function testPassingExternalPDOMeansConnectionIsConnected()
{
$params['pdo'] = new \stdClass();

$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');

$conn = new Connection($params, $driverMock);

Expand All @@ -480,8 +482,8 @@ public function testPassingExternalPDOMeansConnectionIsConnected()
public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException()
{
/* @var $driver \Doctrine\DBAL\Driver */
$driver = $this->getMock('Doctrine\DBAL\Driver');
$pdoMock = $this->getMock('Doctrine\DBAL\Driver\Connection');
$driver = $this->createMock('Doctrine\DBAL\Driver');
$pdoMock = $this->createMock('Doctrine\DBAL\Driver\Connection');

// should never execute queries with invalid arguments
$pdoMock->expects($this->never())->method('exec');
Expand Down Expand Up @@ -509,10 +511,10 @@ public function dataCallConnectOnce()
*/
public function testCallConnectOnce($method, $params)
{
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$pdoMock = $this->getMock('Doctrine\DBAL\Driver\Connection');
$driverMock = $this->createMock('Doctrine\DBAL\Driver');
$pdoMock = $this->createMock('Doctrine\DBAL\Driver\Connection');
$platformMock = new Mocks\MockPlatform();
$stmtMock = $this->getMock('Doctrine\DBAL\Driver\Statement');
$stmtMock = $this->createMock('Doctrine\DBAL\Driver\Statement');

$pdoMock->expects($this->any())
->method('prepare')
Expand All @@ -534,10 +536,10 @@ public function testCallConnectOnce($method, $params)
public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform()
{
/** @var \Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock|\PHPUnit_Framework_MockObject_MockObject $driverMock */
$driverMock = $this->getMock('Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock');
$driverMock = $this->createMock('Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock');

/** @var \Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock|\PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */
$driverConnectionMock = $this->getMock('Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock');
$driverConnectionMock = $this->createMock('Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock');

/** @var \Doctrine\DBAL\Platforms\AbstractPlatform|\PHPUnit_Framework_MockObject_MockObject $platformMock */
$platformMock = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform');
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class DBALExceptionTest extends \Doctrine\Tests\DbalTestCase
{
public function testDriverExceptionDuringQueryAcceptsBinaryData()
{
$driver = $this->getMock('\Doctrine\DBAL\Driver');
$driver = $this->createMock('\Doctrine\DBAL\Driver');
$e = DBALException::driverExceptionDuringQuery($driver, new \Exception, '', array('ABC', chr(128)));
$this->assertContains('with params ["ABC", "\x80"]', $e->getMessage());
}

public function testAvoidOverWrappingOnDriverException()
{
$driver = $this->getMock('\Doctrine\DBAL\Driver');
$ex = new DriverException('', $this->getMock('\Doctrine\DBAL\Driver\DriverException'));
$driver = $this->createMock('\Doctrine\DBAL\Driver');
$ex = new DriverException('', $this->createMock('\Doctrine\DBAL\Driver\DriverException'));
$e = DBALException::driverExceptionDuringQuery($driver, $ex, '');
$this->assertSame($ex, $e);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testConvertsException()
);
}

$driverException = $this->getMock('Doctrine\DBAL\Driver\DriverException');
$driverException = $this->createMock('Doctrine\DBAL\Driver\DriverException');

$driverException->expects($this->any())
->method('getErrorCode')
Expand Down Expand Up @@ -209,7 +209,7 @@ private function getExceptionConversions()

foreach ($this->getExceptionConversionData() as $convertedExceptionClassName => $errors) {
foreach ($errors as $error) {
$driverException = $this->getMock('Doctrine\DBAL\Driver\DriverException');
$driverException = $this->createMock('Doctrine\DBAL\Driver\DriverException');

$driverException->expects($this->any())
->method('getErrorCode')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testReturnsDatabaseName()
'password' => 'bar',
);

$statement = $this->getMock('Doctrine\Tests\Mocks\DriverResultStatementMock');
$statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock');

$statement->expects($this->once())
->method('fetchColumn')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testReturnsDatabaseName()
'password' => 'bar',
);

$statement = $this->getMock('Doctrine\Tests\Mocks\DriverResultStatementMock');
$statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock');

$statement->expects($this->once())
->method('fetchColumn')
Expand Down
12 changes: 8 additions & 4 deletions tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ protected function setUp()
*/
public function testExecute(array $params)
{
$statement = $this->getMock('\Doctrine\DBAL\Driver\OCI8\OCI8Statement',
array('bindValue', 'errorInfo'),
array(), '', false);
$statement = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Statement')
->setMethods(array('bindValue', 'errorInfo'))
->disableOriginalConstructor()
->getMock();

$statement->expects($this->at(0))
->method('bindValue')
Expand All @@ -52,7 +53,10 @@ public function testExecute(array $params)

// can't pass to constructor since we don't have a real database handle,
// but execute must check the connection for the executeMode
$conn = $this->getMock('\Doctrine\DBAL\Driver\OCI8\OCI8Connection', array('getExecuteMode'), array(), '', false);
$conn = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Connection')
->setMethods(array('getExecuteMode'))
->disableOriginalConstructor()
->getMock();
$conn->expects($this->once())
->method('getExecuteMode');

Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MysqlSessionInitTest extends DbalTestCase
{
public function testPostConnect()
{
$connectionMock = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
$connectionMock = $this->createMock('Doctrine\DBAL\Connection');
$connectionMock->expects($this->once())
->method('executeUpdate')
->with($this->equalTo("SET NAMES foo COLLATE bar"));
Expand All @@ -28,4 +28,4 @@ public function testGetSubscribedEvents()
$listener = new MysqlSessionInit();
$this->assertEquals(array(Events::postConnect), $listener->getSubscribedEvents());
}
}
}
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OracleSessionInitTest extends DbalTestCase
{
public function testPostConnect()
{
$connectionMock = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
$connectionMock = $this->createMock('Doctrine\DBAL\Connection');
$connectionMock->expects($this->once())
->method('executeUpdate')
->with($this->isType('string'));
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SQLSessionInitTest extends DbalTestCase
{
public function testPostConnect()
{
$connectionMock = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
$connectionMock = $this->createMock('Doctrine\DBAL\Connection');
$connectionMock->expects($this->once())
->method('exec')
->with($this->equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'"));
Expand All @@ -30,4 +30,4 @@ public function testGetSubscribedEvents()
$listener = new SQLSessionInit("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'");
$this->assertEquals(array(Events::postConnect), $listener->getSubscribedEvents());
}
}
}
8 changes: 4 additions & 4 deletions tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function testLogExecuteQuery()
{
$sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL();

$logMock = $this->getMock('Doctrine\DBAL\Logging\SQLLogger');
$logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger');
$logMock->expects($this->at(0))
->method('startQuery')
->with($this->equalTo($sql), $this->equalTo(array()), $this->equalTo(array()));
Expand All @@ -24,7 +24,7 @@ public function testLogExecuteUpdate()

$sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL();

$logMock = $this->getMock('Doctrine\DBAL\Logging\SQLLogger');
$logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger');
$logMock->expects($this->at(0))
->method('startQuery')
->with($this->equalTo($sql), $this->equalTo(array()), $this->equalTo(array()));
Expand All @@ -38,7 +38,7 @@ public function testLogPrepareExecute()
{
$sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL();

$logMock = $this->getMock('Doctrine\DBAL\Logging\SQLLogger');
$logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger');
$logMock->expects($this->once())
->method('startQuery')
->with($this->equalTo($sql), $this->equalTo(array()));
Expand All @@ -49,4 +49,4 @@ public function testLogPrepareExecute()
$stmt = $this->_conn->prepare($sql);
$stmt->execute();
}
}
}
4 changes: 3 additions & 1 deletion tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public function testPortabilitySqlServer()
'portability' => $portability
);

$driverMock = $this->getMock('Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Driver', array('connect'));
$driverMock = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Driver')
->setMethods(array('connect'))
->getMock();

$driverMock->expects($this->once())
->method('connect')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DBAL461Test extends \PHPUnit_Framework_TestCase
{
public function testIssue()
{
$conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
$conn = $this->createMock('Doctrine\DBAL\Connection');
$platform = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform');
$platform->registerDoctrineTypeMapping('numeric', 'decimal');

Expand Down
12 changes: 9 additions & 3 deletions tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ public function testGetCustomColumnDeclarationSql()

public function testGetCreateTableSqlDispatchEvent()
{
$listenerMock = $this->getMock('GetCreateTableSqlDispatchEvenListener', array('onSchemaCreateTable', 'onSchemaCreateTableColumn'));
$listenerMock = $this->getMockBuilder('GetCreateTableSqlDispatchEvenListener')
->setMethods(array('onSchemaCreateTable', 'onSchemaCreateTableColumn'))
->getMock();
$listenerMock
->expects($this->once())
->method('onSchemaCreateTable');
Expand All @@ -340,7 +342,9 @@ public function testGetCreateTableSqlDispatchEvent()

public function testGetDropTableSqlDispatchEvent()
{
$listenerMock = $this->getMock('GetDropTableSqlDispatchEventListener', array('onSchemaDropTable'));
$listenerMock = $this->getMockBuilder('GetDropTableSqlDispatchEventListener')
->setMethods(array('onSchemaDropTable'))
->getMock();
$listenerMock
->expects($this->once())
->method('onSchemaDropTable');
Expand All @@ -363,7 +367,9 @@ public function testGetAlterTableSqlDispatchEvent()
'onSchemaAlterTableRenameColumn'
);

$listenerMock = $this->getMock('GetAlterTableSqlDispatchEvenListener', $events);
$listenerMock = $this->getMockBuilder('GetAlterTableSqlDispatchEvenListener')
->setMethods($events)
->getMock();
$listenerMock
->expects($this->once())
->method('onSchemaAlterTable');
Expand Down
Loading

0 comments on commit 8e8c5a1

Please sign in to comment.