Skip to content

Commit

Permalink
Fix getMock() deprecations in TestSuite.
Browse files Browse the repository at this point in the history
Only the ORM remains.
  • Loading branch information
markstory committed Jun 6, 2016
1 parent 49906d8 commit 494c848
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 25 deletions.
71 changes: 50 additions & 21 deletions tests/TestCase/TestSuite/TestFixtureTest.php
Expand Up @@ -299,7 +299,10 @@ public function testInitNoImportNoFields()
$fixture->init();
$this->assertEquals(['id', 'letter'], $fixture->schema()->columns());

$db = $this->getMock('Cake\Database\Connection', ['prepare', 'execute'], [], '', false);
$db = $this->getMockBuilder('Cake\Database\Connection')
->setMethods(['prepare', 'execute'])
->disableOriginalConstructor()
->getMock();
$db->expects($this->never())
->method('prepare');
$db->expects($this->never())
Expand All @@ -316,15 +319,19 @@ public function testInitNoImportNoFields()
public function testCreate()
{
$fixture = new ArticlesFixture();
$db = $this->getMock('Cake\Database\Connection', [], [], '', false);
$table = $this->getMock('Cake\Database\Schema\Table', [], ['articles']);
$db = $this->createMock('Cake\Database\Connection');
$table = $this->getMockBuilder('Cake\Database\Schema\Table')
->setConstructorArgs(['articles'])
->getMock();
$table->expects($this->once())
->method('createSql')
->with($db)
->will($this->returnValue(['sql', 'sql']));
$fixture->schema($table);

$statement = $this->getMock('\PDOStatement', ['execute', 'closeCursor']);
$statement = $this->getMockBuilder('\PDOStatement')
->setMethods(['execute', 'closeCursor'])
->getMock();
$statement->expects($this->atLeastOnce())->method('closeCursor');
$statement->expects($this->atLeastOnce())->method('execute');
$db->expects($this->exactly(2))
Expand All @@ -342,8 +349,10 @@ public function testCreate()
public function testCreateError()
{
$fixture = new ArticlesFixture();
$db = $this->getMock('Cake\Database\Connection', [], [], '', false);
$table = $this->getMock('Cake\Database\Schema\Table', [], ['articles']);
$db = $this->createMock('Cake\Database\Connection');
$table = $this->getMockBuilder('Cake\Database\Schema\Table')
->setConstructorArgs(['articles'])
->getMock();
$table->expects($this->once())
->method('createSql')
->with($db)
Expand All @@ -362,8 +371,10 @@ public function testInsert()
{
$fixture = new ArticlesFixture();

$db = $this->getMock('Cake\Database\Connection', [], [], '', false);
$query = $this->getMock('Cake\Database\Query', [], [$db]);
$db = $this->createMock('Cake\Database\Connection');
$query = $this->getMockBuilder('Cake\Database\Query')
->setConstructorArgs([$db])
->getMock();
$db->expects($this->once())
->method('newQuery')
->will($this->returnValue($query));
Expand Down Expand Up @@ -396,7 +407,9 @@ public function testInsert()
->with($expected[2])
->will($this->returnSelf());

$statement = $this->getMock('\PDOStatement', ['closeCursor']);
$statement = $this->getMockBuilder('\PDOStatement')
->setMethods(['closeCursor'])
->getMock();
$statement->expects($this->once())->method('closeCursor');
$query->expects($this->once())
->method('execute')
Expand All @@ -414,8 +427,10 @@ public function testInsertImport()
{
$fixture = new ImportsFixture();

$db = $this->getMock('Cake\Database\Connection', [], [], '', false);
$query = $this->getMock('Cake\Database\Query', [], [$db]);
$db = $this->createMock('Cake\Database\Connection');
$query = $this->getMockBuilder('Cake\Database\Query')
->setConstructorArgs([$db])
->getMock();
$db->expects($this->once())
->method('newQuery')
->will($this->returnValue($query));
Expand All @@ -438,7 +453,9 @@ public function testInsertImport()
->with($expected[0])
->will($this->returnSelf());

$statement = $this->getMock('\PDOStatement', ['closeCursor']);
$statement = $this->getMockBuilder('\PDOStatement')
->setMethods(['closeCursor'])
->getMock();
$statement->expects($this->once())->method('closeCursor');
$query->expects($this->once())
->method('execute')
Expand All @@ -456,8 +473,10 @@ public function testInsertStrings()
{
$fixture = new StringsTestsFixture();

$db = $this->getMock('Cake\Database\Connection', [], [], '', false);
$query = $this->getMock('Cake\Database\Query', [], [$db]);
$db = $this->createMock('Cake\Database\Connection');
$query = $this->getMockBuilder('Cake\Database\Query')
->setConstructorArgs([$db])
->getMock();
$db->expects($this->once())
->method('newQuery')
->will($this->returnValue($query));
Expand Down Expand Up @@ -490,7 +509,9 @@ public function testInsertStrings()
->with($expected[2])
->will($this->returnSelf());

$statement = $this->getMock('\PDOStatement', ['closeCursor']);
$statement = $this->getMockBuilder('\PDOStatement')
->setMethods(['closeCursor'])
->getMock();
$statement->expects($this->once())->method('closeCursor');
$query->expects($this->once())
->method('execute')
Expand All @@ -508,14 +529,18 @@ public function testDrop()
{
$fixture = new ArticlesFixture();

$db = $this->getMock('Cake\Database\Connection', [], [], '', false);
$statement = $this->getMock('\PDOStatement', ['closeCursor']);
$db = $this->createMock('Cake\Database\Connection');
$statement = $this->getMockBuilder('\PDOStatement')
->setMethods(['closeCursor'])
->getMock();
$statement->expects($this->once())->method('closeCursor');
$db->expects($this->once())->method('execute')
->with('sql')
->will($this->returnValue($statement));

$table = $this->getMock('Cake\Database\Schema\Table', [], ['articles']);
$table = $this->getMockBuilder('Cake\Database\Schema\Table')
->setConstructorArgs(['articles'])
->getMock();
$table->expects($this->once())
->method('dropSql')
->with($db)
Expand All @@ -534,14 +559,18 @@ public function testTruncate()
{
$fixture = new ArticlesFixture();

$db = $this->getMock('Cake\Database\Connection', [], [], '', false);
$statement = $this->getMock('\PDOStatement', ['closeCursor']);
$db = $this->createMock('Cake\Database\Connection');
$statement = $this->getMockBuilder('\PDOStatement')
->setMethods(['closeCursor'])
->getMock();
$statement->expects($this->once())->method('closeCursor');
$db->expects($this->once())->method('execute')
->with('sql')
->will($this->returnValue($statement));

$table = $this->getMock('Cake\Database\Schema\Table', [], ['articles']);
$table = $this->getMockBuilder('Cake\Database\Schema\Table')
->setConstructorArgs(['articles'])
->getMock();
$table->expects($this->once())
->method('truncateSql')
->with($db)
Expand Down
16 changes: 12 additions & 4 deletions tests/TestCase/TestSuite/TestSuiteTest.php
Expand Up @@ -34,7 +34,9 @@ public function testAddTestDirectory()
$testFolder = CORE_TEST_CASES . DS . 'TestSuite';
$count = count(glob($testFolder . DS . '*Test.php'));

$suite = $this->getMock('Cake\TestSuite\TestSuite', ['addTestFile']);
$suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
->setMethods(['addTestFile'])
->getMock();
$suite
->expects($this->exactly($count))
->method('addTestFile');
Expand All @@ -53,7 +55,9 @@ public function testAddTestDirectoryRecursive()
$count = count(glob($testFolder . DS . '*Test.php'));
$count += count(glob($testFolder . DS . 'Engine/*Test.php'));

$suite = $this->getMock('Cake\TestSuite\TestSuite', ['addTestFile']);
$suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
->setMethods(['addTestFile'])
->getMock();
$suite
->expects($this->exactly($count))
->method('addTestFile');
Expand All @@ -76,7 +80,9 @@ public function testAddTestDirectoryRecursiveWithHidden()
touch($Folder->path . DS . 'NotHiddenTest.php');
touch($Folder->path . DS . '.HiddenTest.php');

$suite = $this->getMock('Cake\TestSuite\TestSuite', ['addTestFile']);
$suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
->setMethods(['addTestFile'])
->getMock();
$suite
->expects($this->exactly(1))
->method('addTestFile');
Expand All @@ -100,7 +106,9 @@ public function testAddTestDirectoryRecursiveWithNonPhp()
touch($Folder->path . DS . 'SomeNotesTest.txt');
touch($Folder->path . DS . 'NotHiddenTest.php');

$suite = $this->getMock('Cake\TestSuite\TestSuite', ['addTestFile']);
$suite = $this->getMockBuilder('Cake\TestSuite\TestSuite')
->setMethods(['addTestFile'])
->getMock();
$suite
->expects($this->exactly(1))
->method('addTestFile');
Expand Down

0 comments on commit 494c848

Please sign in to comment.