This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds VoidReturnType migration - for PHPUnit 8
- Loading branch information
1 parent
512cc14
commit 69468af
Showing
8 changed files
with
179 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webimpress\PHPUnitMigration\Migration; | ||
|
||
use function implode; | ||
use function preg_replace; | ||
use function version_compare; | ||
|
||
class VoidReturnTypeMigration extends AbstractMigration | ||
{ | ||
public const PHPUNIT_VERSION_REQUIRED = '8.0'; | ||
|
||
private const FUNCTION_NAME = [ | ||
'setUp', | ||
'tearDown', | ||
'setUpBeforeClass', | ||
'tearDownAfterClass', | ||
'assertPreConditions', | ||
'assertPostConditions', | ||
'onNotSuccessfulTest', | ||
]; | ||
|
||
public function migrate(string $content) : string | ||
{ | ||
$content = preg_replace( | ||
'/(function\s+(' . implode('|', self::FUNCTION_NAME) . ')\s*\([^)]*\))([^:{]*{)/i', | ||
'\\1 : void\\3', | ||
$content | ||
); | ||
|
||
return $content; | ||
} | ||
|
||
public function canBeExecuted(string $phpUnitVersion, ?string $phpVersion) : bool | ||
{ | ||
return version_compare($phpVersion, '7.0') >= 0 | ||
|| parent::canBeExecuted($phpUnitVersion, $phpVersion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace WebimpressTest\PHPUnitMigration\Migration\TestAsset; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class VoidReturnTypeMigration extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
} | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
} | ||
|
||
public static function tearDownAfterClass() | ||
{ | ||
} | ||
|
||
protected function assertPreConditions() {} | ||
|
||
protected function assertPostConditions() {} | ||
|
||
protected function onNotSuccessfulTest(\Throwable $t) {} | ||
} |
30 changes: 30 additions & 0 deletions
30
test/Migration/TestAsset/VoidReturnTypeMigration.1.inc.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace WebimpressTest\PHPUnitMigration\Migration\TestAsset; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class VoidReturnTypeMigration extends TestCase | ||
{ | ||
public function setUp() : void | ||
{ | ||
} | ||
|
||
protected function tearDown() : void | ||
{ | ||
} | ||
|
||
public static function setUpBeforeClass() : void | ||
{ | ||
} | ||
|
||
public static function tearDownAfterClass() : void | ||
{ | ||
} | ||
|
||
protected function assertPreConditions() : void {} | ||
|
||
protected function assertPostConditions() : void {} | ||
|
||
protected function onNotSuccessfulTest(\Throwable $t) : void {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace WebimpressTest\PHPUnitMigration\Migration\TestAsset; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class VoidReturnTypeMigration extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
} | ||
|
||
protected function tearDown() // comment | ||
{ | ||
} | ||
|
||
public static function setUpBeforeClass() | ||
: void | ||
{ | ||
} | ||
|
||
public static function tearDownAfterClass() | ||
// comment | ||
{ | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
test/Migration/TestAsset/VoidReturnTypeMigration.2.inc.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace WebimpressTest\PHPUnitMigration\Migration\TestAsset; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class VoidReturnTypeMigration extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
} | ||
|
||
protected function tearDown() : void // comment | ||
{ | ||
} | ||
|
||
public static function setUpBeforeClass() | ||
: void | ||
{ | ||
} | ||
|
||
public static function tearDownAfterClass() : void | ||
// comment | ||
{ | ||
} | ||
} |