diff --git a/installer/OptionalPackages.php b/installer/OptionalPackages.php index ea2cec50..8f79928d 100644 --- a/installer/OptionalPackages.php +++ b/installer/OptionalPackages.php @@ -103,7 +103,7 @@ class OptionalPackages */ private $stabilityFlags; - public function __construct(IOInterface $io, Composer $composer, string $projectRoot = null) + public function __construct(IOInterface $io, Composer $composer, ?string $projectRoot = null) { $this->io = $io; $this->composer = $composer; @@ -139,11 +139,13 @@ function ($value) { 'n' ); - if ($answer != 'n') { - $content = file_get_contents($this->installerSource . '/resources/bin/hyperf.stub'); - $content = str_replace('%TIME_ZONE%', $answer, $content); - file_put_contents($this->projectRoot . '/bin/hyperf.php', $content); + if ($answer == 'n') { + $answer = date_default_timezone_get(); } + + $content = file_get_contents($this->installerSource . '/resources/bin/hyperf.stub'); + $content = str_replace('%TIME_ZONE%', $answer, $content); + file_put_contents($this->projectRoot . '/bin/hyperf.php', $content); } /** diff --git a/installer/config.php b/installer/config.php index a3a3b975..5003e2f7 100644 --- a/installer/config.php +++ b/installer/config.php @@ -71,8 +71,12 @@ 'hyperf/service-governance' => [ 'version' => '~3.1.0', ], + 'pestphp/pest' => [ + 'version' => '^2.34', + ], ], 'require-dev' => [ + 'pestphp/pest', ], 'questions' => [ 'database' => [ @@ -310,5 +314,27 @@ ], ], ], + 'pest' => [ + 'question' => 'Do you want to use pestphp/pest component ? (Pest is a testing framework with a focus on simplicity, + meticulously designed to bring back the joy of testing in PHP.)', + 'default' => 'n', + 'required' => false, + 'force' => true, + 'custom-package' => true, + 'options' => [ + 'y' => [ + 'name' => 'yes', + 'packages' => [ + 'pestphp/pest', + ], + 'resources' => [ + 'resources/pest/Feature/ExampleTest.php' => 'test/Feature/ExampleTest.php', + 'resources/pest/Unit/ExampleTest.php' => 'test/Unit/ExampleTest.php', + 'resources/pest/Pest.php' => 'test/Pest.php', + 'resources/pest/TestCase.php' => 'test/TestCase.php', + ], + ], + ], + ], ], ]; diff --git a/installer/resources/pest/Feature/ExampleTest.php b/installer/resources/pest/Feature/ExampleTest.php new file mode 100644 index 00000000..61cd84c3 --- /dev/null +++ b/installer/resources/pest/Feature/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/installer/resources/pest/Pest.php b/installer/resources/pest/Pest.php new file mode 100644 index 00000000..5949c617 --- /dev/null +++ b/installer/resources/pest/Pest.php @@ -0,0 +1,45 @@ +in('Feature'); + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +| +| When you're writing tests, you often need to check that values meet certain conditions. The +| "expect()" function gives you access to a set of "expectations" methods that you can use +| to assert different things. Of course, you may extend the Expectation API at any time. +| +*/ + +expect()->extend('toBeOne', function () { + return $this->toBe(1); +}); + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +| +| While Pest is very powerful out-of-the-box, you may have some testing code specific to your +| project that you don't want to repeat in every file. Here you can also expose helpers as +| global functions to help you to reduce the number of lines of code in your test files. +| +*/ + +function something() +{ + // .. +} diff --git a/installer/resources/pest/TestCase.php b/installer/resources/pest/TestCase.php new file mode 100644 index 00000000..cfb05b6d --- /dev/null +++ b/installer/resources/pest/TestCase.php @@ -0,0 +1,10 @@ +toBeTrue(); +}); diff --git a/test/bootstrap.php b/test/bootstrap.php index 818d1d8d..85f2886b 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -9,22 +9,24 @@ * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ +use Hyperf\Contract\ApplicationInterface; +use Hyperf\Di\ClassLoader; +use Hyperf\Engine\DefaultOption; + ini_set('display_errors', 'on'); ini_set('display_startup_errors', 'on'); error_reporting(E_ALL); date_default_timezone_set('Asia/Shanghai'); -Swoole\Runtime::enableCoroutine(true); - ! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1)); require BASE_PATH . '/vendor/autoload.php'; -! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', Hyperf\Engine\DefaultOption::hookFlags()); +! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', DefaultOption::hookFlags()); -Hyperf\Di\ClassLoader::init(); +ClassLoader::init(); $container = require BASE_PATH . '/config/container.php'; -$container->get(Hyperf\Contract\ApplicationInterface::class); +$container->get(ApplicationInterface::class);