Skip to content

Commit

Permalink
Added pestphp/pest component (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia authored Apr 10, 2024
1 parent 4957bdd commit 08edc64
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 10 deletions.
12 changes: 7 additions & 5 deletions installer/OptionalPackages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions installer/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@
'hyperf/service-governance' => [
'version' => '~3.1.0',
],
'pestphp/pest' => [
'version' => '^2.34',
],
],
'require-dev' => [
'pestphp/pest',
],
'questions' => [
'database' => [
Expand Down Expand Up @@ -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',
],
],
],
],
],
];
5 changes: 5 additions & 0 deletions installer/resources/pest/Feature/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

test('example', function () {
expect(true)->toBeTrue();
});
45 changes: 45 additions & 0 deletions installer/resources/pest/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/

// uses(Tests\TestCase::class)->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()
{
// ..
}
10 changes: 10 additions & 0 deletions installer/resources/pest/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
//
}
5 changes: 5 additions & 0 deletions installer/resources/pest/Unit/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

test('example', function () {
expect(true)->toBeTrue();
});
12 changes: 7 additions & 5 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
* @contact [email protected]
* @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);

0 comments on commit 08edc64

Please sign in to comment.