Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Support and use HackTest v1.0
Browse files Browse the repository at this point in the history
- depend-dev on hacktest v1
- migration uses new `HackTest` class instead of v0.x `HackTestCase`
- migration will also migrate `HackTestCase` to `HackTest`
  • Loading branch information
fredemmott committed Sep 21, 2018
1 parent 110922d commit fc33cc2
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"facebook/fbexpect": "^2.1.1",
"facebook/hack-codegen": "~3.2.1",
"hhvm/hhvm-autoload": "^1.5",
"hhvm/hacktest": "^0.2.0"
"hhvm/hacktest": "^1.0"
},
"require": {
"hhvm": "^3.28.0",
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions src/Migrations/PHPUnitToHackTestMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ private function replaceQualifiedName(
$name !== "\\PHPUnit_Framework_TestCase" &&
$name !== "\\PHPUnit\\Framework\\TestCase" &&
$name !== "PHPUnit_Framework_TestCase" &&
$name !== "PHPUnit\\Framework\\TestCase"
$name !== "PHPUnit\\Framework\\TestCase" &&
$name !== "Facebook\\HackTest\\HackTestCase" &&
$name !== "\\Facebook\\HackTest\\HackTestCase"
) {
return $in;
}
Expand All @@ -38,7 +40,7 @@ private function replaceQualifiedName(
new HHAST\BackslashToken($m, $m),
new HHAST\NameToken($m, $m, "HackTest"),
new HHAST\BackslashToken($m, $m),
new HHAST\NameToken($m, $m, "HackTestCase"),
new HHAST\NameToken($m, $m, "HackTest"),
],
);

Expand Down Expand Up @@ -218,7 +220,8 @@ final private function replaceUsedTypes(HHAST\Script $script): HHAST\Script {
|> Dict\filter(
$$,
$resolved ==> $resolved === 'PHPUnit_Framework_TestCase' ||
$resolved === 'PHPUnit\\Framework\\TestCase',
$resolved === 'PHPUnit\\Framework\\TestCase' ||
$resolved === 'Facebook\\HackTest\\HackTestCase'
);
if (C\is_empty($uses)) {
return $script;
Expand Down Expand Up @@ -251,12 +254,12 @@ final private function replaceUsedTypes(HHAST\Script $script): HHAST\Script {
return $node;
}

return $node->replace($extends, $extends->withText('HackTestCase'));
return $node->replace($extends, $extends->withText('HackTest'));
},
);
}

private function getQualifiedNameForHackTestCase(): HHAST\QualifiedName {
private function getQualifiedNameForHackTest(): HHAST\QualifiedName {
$m = HHAST\Missing();
return new HHAST\QualifiedName(
new HHAST\EditableList(
Expand All @@ -265,7 +268,7 @@ private function getQualifiedNameForHackTestCase(): HHAST\QualifiedName {
new HHAST\BackslashToken($m, $m),
new HHAST\NameToken($m, $m, "HackTest"),
new HHAST\BackslashToken($m, $m),
new HHAST\NameToken($m, $m, "HackTestCase"),
new HHAST\NameToken($m, $m, "HackTest"),
],
),
);
Expand All @@ -280,7 +283,7 @@ private function replaceUseClause(
if ($what->getText() !== "PHPUnit_Framework_TestCase") {
return $node;
}
return $node->withName($this->getQualifiedNameForHackTestCase());
return $node->withName($this->getQualifiedNameForHackTest());
}

if (!$what is HHAST\QualifiedName) {
Expand All @@ -293,11 +296,12 @@ private function replaceUseClause(
|> Str\strip_prefix($$, '\\');
if (
$text !== 'PHPUnit_Framework_TestCase' &&
$text !== 'PHPUnit\\Framework\\TestCase'
$text !== 'PHPUnit\\Framework\\TestCase' &&
$text !== 'Facebook\\HackTest\\HackTestCase'
) {
return $node;
}
return $node->withName($this->getQualifiedNameForHackTestCase());
return $node->withName($this->getQualifiedNameForHackTest());
}

private function renameSetUpTearDownFunctions(
Expand Down
3 changes: 1 addition & 2 deletions src/__Private/MigrationCLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ protected function getSupportedOptions(): vec<CLIOptions\CLIOption> {
),
CLIOptions\flag(
() ==> { $this->migrations[] = PHPUnitToHackTestMigration::class; },
'Migrate from PHPUnit to HackTest. You may need to run '.
'--assert-to-expect first.',
'Migrate from PHPUnit to HackTest',
'--phpunit-to-hacktest',
),
CLIOptions\flag(
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use namespace HH\Lib\C;

abstract class TestCase extends \Facebook\HackTest\HackTestCase {
abstract class TestCase extends \Facebook\HackTest\HackTest {
protected static function getNodeAndParents(
string $code,
): (EditableNode, vec<EditableNode>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace MyNS;

final class FooTest extends \Facebook\HackTest\HackTestCase {
final class FooTest extends \Facebook\HackTest\HackTest {
public function provideFoo(): array<array<string>> {
return [['abc']];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
*/

final class FooTest extends Facebook\HackTest\HackTestCase {
final class FooTest extends Facebook\HackTest\HackTest {
public function provideFoo(): array<array<string>> {
return [['abc']];
}
Expand All @@ -21,5 +21,5 @@ final class FooTest extends Facebook\HackTest\HackTestCase {
}
}

final class BarTest extends \Facebook\HackTest\HackTestCase {
final class BarTest extends \Facebook\HackTest\HackTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*
*/

use type Facebook\HackTest\HackTestCase;
use type Facebook\HackTest\HackTest;

final class FooTest extends HackTestCase {
final class FooTest extends HackTest {
public function provideFoo(): array<array<string>> {
return [['abc']];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace MyNS;

final class FooTest extends \Facebook\HackTest\HackTestCase {
final class FooTest extends \Facebook\HackTest\HackTest {
public function provideFoo(): array<array<string>> {
return [['abc']];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ final class FooTest extends PHPUnit_Framework_TestCase {
}
}

final class BarTest extends \Facebook\HackTest\HackTestCase {
final class BarTest extends \Facebook\HackTest\HackTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace MyNS;

final class FooTest extends \Facebook\HackTest\HackTestCase {
final class FooTest extends \Facebook\HackTest\HackTest {
public function provideFoo(): array<array<string>> {
return [['abc']];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*
*/

use type Facebook\HackTest\HackTestCase;
use type Facebook\HackTest\HackTest;

final class FooTest extends HackTestCase {
final class FooTest extends HackTest {
public function provideFoo(): array<array<string>> {
return [['abc']];
}
Expand Down

0 comments on commit fc33cc2

Please sign in to comment.