Skip to content

Commit dfde805

Browse files
committed
PHPUnit 10 fixes
1 parent a0e06e4 commit dfde805

File tree

7 files changed

+34
-10
lines changed

7 files changed

+34
-10
lines changed

tests/DatabaseMigration/AbstractDatabaseAwareTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function assertTableEmpty($table_name)
6969
*/
7070
protected function assertTableContent($table_name, array $expected_content)
7171
{
72-
$this->assertSame(
72+
$this->assertEquals(
7373
$expected_content,
7474
$this->_dumpTable($table_name),
7575
'Table "' . $table_name . '" content isn\'t correct.'

tests/DatabaseMigration/AbstractMigrationRunnerTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use ConsoleHelpers\DatabaseMigration\AbstractMigrationRunner;
1515
use Prophecy\Prophecy\ObjectProphecy;
16+
use Aura\Sql\ExtendedPdoInterface;
17+
use ConsoleHelpers\DatabaseMigration\MigrationContext;
1618

1719
abstract class AbstractMigrationRunnerTestCase extends AbstractTestCase
1820
{
@@ -44,9 +46,9 @@ abstract class AbstractMigrationRunnerTestCase extends AbstractTestCase
4446
*/
4547
protected function setupTest()
4648
{
47-
$this->database = $this->prophesize('Aura\Sql\ExtendedPdoInterface');
49+
$this->database = $this->prophesize(ExtendedPdoInterface::class);
4850

49-
$this->context = $this->prophesize('ConsoleHelpers\DatabaseMigration\MigrationContext');
51+
$this->context = $this->prophesize(MigrationContext::class);
5052
$this->context->getDatabase()->willReturn($this->database);
5153

5254
$this->runner = $this->createMigrationRunner();

tests/DatabaseMigration/AbstractTestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,21 @@
1717
abstract class AbstractTestCase extends TestCase
1818
{
1919
use ProphecyTrait;
20+
21+
/**
22+
* Returns a test name.
23+
*
24+
* @return string
25+
*/
26+
protected function getTestName()
27+
{
28+
if ( method_exists($this, 'getName') ) {
29+
// PHPUnit 9-.
30+
return $this->getName(false);
31+
}
32+
33+
// PHPUnit 10+.
34+
return $this->name();
35+
}
36+
2037
}

tests/DatabaseMigration/MigrationContextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MigrationContextTest extends AbstractTestCase
4444
*/
4545
protected function setupTest()
4646
{
47-
$this->database = $this->prophesize('Aura\Sql\ExtendedPdoInterface')->reveal();
47+
$this->database = $this->prophesize(ExtendedPdoInterface::class)->reveal();
4848
$this->container = $this->prophesize('ArrayAccess')->reveal();
4949

5050
$this->context = new MigrationContext($this->database);

tests/DatabaseMigration/MigrationManagerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Prophecy\Argument;
1919
use Prophecy\Prophecy\ObjectProphecy;
2020
use Tests\ConsoleHelpers\DatabaseMigration\ProphecyToken\RegExToken;
21+
use ConsoleHelpers\DatabaseMigration\AbstractMigrationRunner;
2122

2223
class MigrationManagerTest extends AbstractDatabaseAwareTestCase
2324
{
@@ -54,7 +55,7 @@ protected function setupTest()
5455
*/
5556
protected function tearDownTest()
5657
{
57-
if ( strpos($this->getName(false), 'testCreateMigration') === 0 ) {
58+
if ( strpos($this->getTestName(), 'testCreateMigration') === 0 ) {
5859
$this->deleteTempMigrations();
5960
}
6061
}
@@ -110,7 +111,7 @@ public function testCreateMigrationWithInvalidName($migration_name)
110111
$manager->createMigration($migration_name, 'one');
111112
}
112113

113-
public function createMigrationWithInvalidNameDataProvider()
114+
public static function createMigrationWithInvalidNameDataProvider()
114115
{
115116
return array(
116117
array(' '),
@@ -292,7 +293,7 @@ public function testRunRemovedMigrationsAreDeleted()
292293

293294
public function testRunSetsContainerToContext()
294295
{
295-
$context = $this->prophesize('ConsoleHelpers\DatabaseMigration\MigrationContext');
296+
$context = $this->prophesize(MigrationContext::class);
296297
$context->setContainer($this->container)->shouldBeCalled();
297298
$context->getDatabase()->willReturn($this->database)->shouldBeCalled();
298299

@@ -340,7 +341,7 @@ protected function deleteTempMigrations()
340341
*/
341342
protected function createMigrationRunnerMock($file_extension)
342343
{
343-
$runner = $this->prophesize('ConsoleHelpers\DatabaseMigration\AbstractMigrationRunner');
344+
$runner = $this->prophesize(AbstractMigrationRunner::class);
344345
$runner->getFileExtension()->willReturn($file_extension)->shouldBeCalled();
345346

346347
return $runner;

tests/DatabaseMigration/PhpMigrationRunnerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function testRunMalformedPHPMigration()
3232

3333
public function testRun()
3434
{
35-
$this->database->perform('test')->shouldBeCalled();
35+
$pdo_statement = $this->prophesize(\PDOStatement::class)->reveal();
36+
$this->database->perform('test')->willReturn($pdo_statement)->shouldBeCalled();
3637

3738
$this->runner->run($this->getFixture('non-empty-migration.php'), $this->context->reveal());
3839
}

tests/DatabaseMigration/SqlMigrationRunnerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ public function testRunEmptySQLMigration()
3434
public function testRun()
3535
{
3636
$sequence = array();
37+
$pdo_statement = $this->prophesize(\PDOStatement::class)->reveal();
3738

3839
$this->database
3940
->perform(Argument::any())
40-
->will(function (array $args) use (&$sequence) {
41+
->will(function (array $args) use (&$sequence, $pdo_statement) {
4142
$sequence[] = $args[0];
43+
44+
return $pdo_statement;
4245
})
4346
->shouldBeCalled();
4447

0 commit comments

Comments
 (0)