From fc33cc247a53edaf49db63fe259ee0f14cb1218e Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Fri, 21 Sep 2018 12:26:10 -0700 Subject: [PATCH] Support and use HackTest v1.0 - depend-dev on hacktest v1 - migration uses new `HackTest` class instead of v0.x `HackTestCase` - migration will also migrate `HackTestCase` to `HackTest` --- composer.json | 2 +- composer.lock | 24 +++++++++---------- src/Migrations/PHPUnitToHackTestMigration.php | 22 ++++++++++------- src/__Private/MigrationCLI.php | 3 +-- tests/TestCase.php | 2 +- .../dataprovider_and_comment.php.expect | 2 +- .../new_name_no_ns.php.expect | 4 ++-- .../new_name_no_ns_with_use.php.expect | 4 ++-- .../new_name_ns_direct.php.expect | 2 +- .../old_name_no_ns.php.expect | 2 +- .../old_name_ns_direct.php.expect | 2 +- .../old_name_ns_with_use.php.expect | 4 ++-- 12 files changed, 38 insertions(+), 35 deletions(-) diff --git a/composer.json b/composer.json index f180b822e..78f3ecf22 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 30d3e71fd..4dda773c8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7427be72aab80b699c9a4a89e64941be", + "content-hash": "6b85dba13d9ee62daaeaff05e7d5f02a", "packages": [ { "name": "facebook/difflib", @@ -247,16 +247,16 @@ }, { "name": "facebook/fbexpect", - "version": "v2.1.1", + "version": "v2.1.2", "source": { "type": "git", "url": "https://github.com/hhvm/fbexpect.git", - "reference": "99f029651078432112154a099ce9f3c4cbb4c46b" + "reference": "59fec5457ddfd38f4431f4a29089244c07b9d780" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hhvm/fbexpect/zipball/99f029651078432112154a099ce9f3c4cbb4c46b", - "reference": "99f029651078432112154a099ce9f3c4cbb4c46b", + "url": "https://api.github.com/repos/hhvm/fbexpect/zipball/59fec5457ddfd38f4431f4a29089244c07b9d780", + "reference": "59fec5457ddfd38f4431f4a29089244c07b9d780", "shasum": "" }, "require": { @@ -266,7 +266,7 @@ "hhvm/hsl": "^3.26" }, "require-dev": { - "hhvm/hacktest": "^0.2" + "hhvm/hacktest": "^1.0" }, "type": "library", "notification-url": "https://packagist.org/downloads/", @@ -274,7 +274,7 @@ "MIT" ], "description": "Unit test helpers for Facebook projects", - "time": "2018-09-13T17:56:12+00:00" + "time": "2018-09-21T19:19:49+00:00" }, { "name": "facebook/fbmarkdown", @@ -406,16 +406,16 @@ }, { "name": "hhvm/hacktest", - "version": "0.2", + "version": "v1.0", "source": { "type": "git", "url": "https://github.com/hhvm/hacktest.git", - "reference": "f03361f1b5f3b376a764ab860661c4e8b96e8d7c" + "reference": "36708c4b05912aa57d1639bfd26608d05d6064a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hhvm/hacktest/zipball/f03361f1b5f3b376a764ab860661c4e8b96e8d7c", - "reference": "f03361f1b5f3b376a764ab860661c4e8b96e8d7c", + "url": "https://api.github.com/repos/hhvm/hacktest/zipball/36708c4b05912aa57d1639bfd26608d05d6064a6", + "reference": "36708c4b05912aa57d1639bfd26608d05d6064a6", "shasum": "" }, "require": { @@ -441,7 +441,7 @@ "MIT" ], "description": "The Hack Test Library", - "time": "2018-08-24T23:45:22+00:00" + "time": "2018-09-19T02:15:14+00:00" } ], "aliases": [], diff --git a/src/Migrations/PHPUnitToHackTestMigration.php b/src/Migrations/PHPUnitToHackTestMigration.php index 955a995ae..18751622c 100644 --- a/src/Migrations/PHPUnitToHackTestMigration.php +++ b/src/Migrations/PHPUnitToHackTestMigration.php @@ -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; } @@ -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"), ], ); @@ -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; @@ -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( @@ -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"), ], ), ); @@ -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) { @@ -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( diff --git a/src/__Private/MigrationCLI.php b/src/__Private/MigrationCLI.php index ada939777..166a4ead6 100644 --- a/src/__Private/MigrationCLI.php +++ b/src/__Private/MigrationCLI.php @@ -101,8 +101,7 @@ protected function getSupportedOptions(): vec { ), 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( diff --git a/tests/TestCase.php b/tests/TestCase.php index 4f8e36f78..d4909e6ed 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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) { diff --git a/tests/fixtures/migrations/PHPUnitToHackTest/dataprovider_and_comment.php.expect b/tests/fixtures/migrations/PHPUnitToHackTest/dataprovider_and_comment.php.expect index 93b4fee50..c97b6c20c 100644 --- a/tests/fixtures/migrations/PHPUnitToHackTest/dataprovider_and_comment.php.expect +++ b/tests/fixtures/migrations/PHPUnitToHackTest/dataprovider_and_comment.php.expect @@ -13,7 +13,7 @@ namespace MyNS; -final class FooTest extends \Facebook\HackTest\HackTestCase { +final class FooTest extends \Facebook\HackTest\HackTest { public function provideFoo(): array> { return [['abc']]; } diff --git a/tests/fixtures/migrations/PHPUnitToHackTest/new_name_no_ns.php.expect b/tests/fixtures/migrations/PHPUnitToHackTest/new_name_no_ns.php.expect index 855445427..09568ee2a 100644 --- a/tests/fixtures/migrations/PHPUnitToHackTest/new_name_no_ns.php.expect +++ b/tests/fixtures/migrations/PHPUnitToHackTest/new_name_no_ns.php.expect @@ -11,7 +11,7 @@ * */ -final class FooTest extends Facebook\HackTest\HackTestCase { +final class FooTest extends Facebook\HackTest\HackTest { public function provideFoo(): array> { return [['abc']]; } @@ -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 { } diff --git a/tests/fixtures/migrations/PHPUnitToHackTest/new_name_no_ns_with_use.php.expect b/tests/fixtures/migrations/PHPUnitToHackTest/new_name_no_ns_with_use.php.expect index d86c52895..b7e5f519a 100644 --- a/tests/fixtures/migrations/PHPUnitToHackTest/new_name_no_ns_with_use.php.expect +++ b/tests/fixtures/migrations/PHPUnitToHackTest/new_name_no_ns_with_use.php.expect @@ -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> { return [['abc']]; } diff --git a/tests/fixtures/migrations/PHPUnitToHackTest/new_name_ns_direct.php.expect b/tests/fixtures/migrations/PHPUnitToHackTest/new_name_ns_direct.php.expect index d7ff0f738..061ed76b9 100644 --- a/tests/fixtures/migrations/PHPUnitToHackTest/new_name_ns_direct.php.expect +++ b/tests/fixtures/migrations/PHPUnitToHackTest/new_name_ns_direct.php.expect @@ -13,7 +13,7 @@ namespace MyNS; -final class FooTest extends \Facebook\HackTest\HackTestCase { +final class FooTest extends \Facebook\HackTest\HackTest { public function provideFoo(): array> { return [['abc']]; } diff --git a/tests/fixtures/migrations/PHPUnitToHackTest/old_name_no_ns.php.expect b/tests/fixtures/migrations/PHPUnitToHackTest/old_name_no_ns.php.expect index 7172227b3..ee0b74277 100644 --- a/tests/fixtures/migrations/PHPUnitToHackTest/old_name_no_ns.php.expect +++ b/tests/fixtures/migrations/PHPUnitToHackTest/old_name_no_ns.php.expect @@ -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 { } diff --git a/tests/fixtures/migrations/PHPUnitToHackTest/old_name_ns_direct.php.expect b/tests/fixtures/migrations/PHPUnitToHackTest/old_name_ns_direct.php.expect index 7734cccc8..d4300cb72 100644 --- a/tests/fixtures/migrations/PHPUnitToHackTest/old_name_ns_direct.php.expect +++ b/tests/fixtures/migrations/PHPUnitToHackTest/old_name_ns_direct.php.expect @@ -13,7 +13,7 @@ namespace MyNS; -final class FooTest extends \Facebook\HackTest\HackTestCase { +final class FooTest extends \Facebook\HackTest\HackTest { public function provideFoo(): array> { return [['abc']]; } diff --git a/tests/fixtures/migrations/PHPUnitToHackTest/old_name_ns_with_use.php.expect b/tests/fixtures/migrations/PHPUnitToHackTest/old_name_ns_with_use.php.expect index d86c52895..b7e5f519a 100644 --- a/tests/fixtures/migrations/PHPUnitToHackTest/old_name_ns_with_use.php.expect +++ b/tests/fixtures/migrations/PHPUnitToHackTest/old_name_ns_with_use.php.expect @@ -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> { return [['abc']]; }