Skip to content

Commit 08edc64

Browse files
authored
Added pestphp/pest component (#121)
1 parent 4957bdd commit 08edc64

File tree

7 files changed

+105
-10
lines changed

7 files changed

+105
-10
lines changed

installer/OptionalPackages.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class OptionalPackages
103103
*/
104104
private $stabilityFlags;
105105

106-
public function __construct(IOInterface $io, Composer $composer, string $projectRoot = null)
106+
public function __construct(IOInterface $io, Composer $composer, ?string $projectRoot = null)
107107
{
108108
$this->io = $io;
109109
$this->composer = $composer;
@@ -139,11 +139,13 @@ function ($value) {
139139
'n'
140140
);
141141

142-
if ($answer != 'n') {
143-
$content = file_get_contents($this->installerSource . '/resources/bin/hyperf.stub');
144-
$content = str_replace('%TIME_ZONE%', $answer, $content);
145-
file_put_contents($this->projectRoot . '/bin/hyperf.php', $content);
142+
if ($answer == 'n') {
143+
$answer = date_default_timezone_get();
146144
}
145+
146+
$content = file_get_contents($this->installerSource . '/resources/bin/hyperf.stub');
147+
$content = str_replace('%TIME_ZONE%', $answer, $content);
148+
file_put_contents($this->projectRoot . '/bin/hyperf.php', $content);
147149
}
148150

149151
/**

installer/config.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@
7171
'hyperf/service-governance' => [
7272
'version' => '~3.1.0',
7373
],
74+
'pestphp/pest' => [
75+
'version' => '^2.34',
76+
],
7477
],
7578
'require-dev' => [
79+
'pestphp/pest',
7680
],
7781
'questions' => [
7882
'database' => [
@@ -310,5 +314,27 @@
310314
],
311315
],
312316
],
317+
'pest' => [
318+
'question' => 'Do you want to use pestphp/pest component ? (Pest is a testing framework with a focus on simplicity,
319+
meticulously designed to bring back the joy of testing in PHP.)',
320+
'default' => 'n',
321+
'required' => false,
322+
'force' => true,
323+
'custom-package' => true,
324+
'options' => [
325+
'y' => [
326+
'name' => 'yes',
327+
'packages' => [
328+
'pestphp/pest',
329+
],
330+
'resources' => [
331+
'resources/pest/Feature/ExampleTest.php' => 'test/Feature/ExampleTest.php',
332+
'resources/pest/Unit/ExampleTest.php' => 'test/Unit/ExampleTest.php',
333+
'resources/pest/Pest.php' => 'test/Pest.php',
334+
'resources/pest/TestCase.php' => 'test/TestCase.php',
335+
],
336+
],
337+
],
338+
],
313339
],
314340
];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
test('example', function () {
4+
expect(true)->toBeTrue();
5+
});

installer/resources/pest/Pest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Test Case
6+
|--------------------------------------------------------------------------
7+
|
8+
| The closure you provide to your test functions is always bound to a specific PHPUnit test
9+
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
10+
| need to change it using the "uses()" function to bind a different classes or traits.
11+
|
12+
*/
13+
14+
// uses(Tests\TestCase::class)->in('Feature');
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Expectations
19+
|--------------------------------------------------------------------------
20+
|
21+
| When you're writing tests, you often need to check that values meet certain conditions. The
22+
| "expect()" function gives you access to a set of "expectations" methods that you can use
23+
| to assert different things. Of course, you may extend the Expectation API at any time.
24+
|
25+
*/
26+
27+
expect()->extend('toBeOne', function () {
28+
return $this->toBe(1);
29+
});
30+
31+
/*
32+
|--------------------------------------------------------------------------
33+
| Functions
34+
|--------------------------------------------------------------------------
35+
|
36+
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
37+
| project that you don't want to repeat in every file. Here you can also expose helpers as
38+
| global functions to help you to reduce the number of lines of code in your test files.
39+
|
40+
*/
41+
42+
function something()
43+
{
44+
// ..
45+
}

installer/resources/pest/TestCase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use PHPUnit\Framework\TestCase as BaseTestCase;
6+
7+
abstract class TestCase extends BaseTestCase
8+
{
9+
//
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
test('example', function () {
4+
expect(true)->toBeTrue();
5+
});

test/bootstrap.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@
99
* @contact [email protected]
1010
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
1111
*/
12+
use Hyperf\Contract\ApplicationInterface;
13+
use Hyperf\Di\ClassLoader;
14+
use Hyperf\Engine\DefaultOption;
15+
1216
ini_set('display_errors', 'on');
1317
ini_set('display_startup_errors', 'on');
1418

1519
error_reporting(E_ALL);
1620
date_default_timezone_set('Asia/Shanghai');
1721

18-
Swoole\Runtime::enableCoroutine(true);
19-
2022
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
2123

2224
require BASE_PATH . '/vendor/autoload.php';
2325

24-
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', Hyperf\Engine\DefaultOption::hookFlags());
26+
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', DefaultOption::hookFlags());
2527

26-
Hyperf\Di\ClassLoader::init();
28+
ClassLoader::init();
2729

2830
$container = require BASE_PATH . '/config/container.php';
2931

30-
$container->get(Hyperf\Contract\ApplicationInterface::class);
32+
$container->get(ApplicationInterface::class);

0 commit comments

Comments
 (0)