Skip to content

Commit 87c8fa2

Browse files
authored
Fixed Tests (#104)
1 parent 5b5010d commit 87c8fa2

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

.github/workflows/run-tests.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
2020
- laravel: 10.*
21-
testbench: 8.*
22-
carbon: ^2.63
21+
testbench: ^8.18
22+
carbon: ^2.67
2323

2424
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2525

@@ -42,10 +42,18 @@ jobs:
4242
- name: Install dependencies
4343
run: |
4444
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
45-
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
45+
composer update --${{ matrix.stability }} --no-interaction
4646
4747
- name: List Installed Dependencies
4848
run: composer show -D
4949

50-
- name: Execute tests
50+
- name: Show pest version
51+
run: vendor/bin/pest --version
52+
53+
- name: Execute tests on Linux
54+
if: matrix.os == 'ubuntu-latest'
55+
run: Xvfb :99 & DISPLAY=:99 vendor/bin/pest
56+
57+
- name: Execute tests on Windows
58+
if: matrix.os == 'windows-latest'
5159
run: vendor/bin/pest

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"nunomaduro/collision": "^7.9",
4040
"nunomaduro/larastan": "^2.0.1",
4141
"orchestra/testbench": "^8.18",
42-
"pestphp/pest": "^2.0",
42+
"pestphp/pest": "^2.7",
4343
"pestphp/pest-plugin-arch": "^2.0",
4444
"pestphp/pest-plugin-laravel": "^2.0",
4545
"phpstan/extension-installer": "^1.1",

src/Commands/DevelopCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function handle(): void
3939

4040
$this->installIcon();
4141

42-
$this->runDeveloper(installer: $this->option('installer'), skip_queue: $this->option('no-queue'));
42+
$this->runDeveloper(installer: $this->option('installer'), skip_queue: $this->option('no-queue'), withoutInteraction: $this->option('no-interaction'));
4343
}
4444

4545
/**

src/Traits/Developer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ trait Developer
88
{
99
use ExecuteCommand;
1010

11-
protected function runDeveloper(string $installer, bool $skip_queue): void
11+
protected function runDeveloper(string $installer, bool $skip_queue, bool $withoutInteraction = false): void
1212
{
1313
[$installer, $command] = $this->getInstallerAndCommand(installer: $installer, type: 'dev');
1414

1515
note("Running the dev script with {$installer}...");
16-
$this->executeCommand(command: $command, type: 'serve', skip_queue: $skip_queue);
16+
$this->executeCommand(command: $command, skip_queue: $skip_queue, type: 'serve', withoutInteraction: $withoutInteraction);
1717
}
1818
}

tests/ExampleTest.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
<?php
22

3-
use Illuminate\Support\Facades\Process;
3+
use PHPUnit\Framework\ExpectationFailedException;
44

55
use function Orchestra\Testbench\remote;
66

77
it('can boot up the app', function () {
8-
$process = remote('native:serve');
9-
$process->setTty(true)->start(function ($type, $line) {
10-
echo $line;
8+
$output = '';
9+
10+
$process = remote('native:serve --no-dependencies --no-interaction');
11+
$process->start(function ($type, $line) use (&$output) {
12+
$output .= $line;
1113
});
1214

1315
try {
14-
retry(12, function () {
16+
retry(20, function () use ($output) {
1517
// Wait until port 8100 is open
1618
dump('Waiting for port 8100 to open...');
19+
1720
$fp = @fsockopen('localhost', 8100, $errno, $errstr, 1);
1821
if ($fp === false) {
19-
throw new Exception('Port 8100 is not open yet');
22+
throw new Exception(sprintf(
23+
'Port 8100 is not open yet. Output: "%s"',
24+
$output,
25+
));
2026
}
2127
}, 5000);
22-
} catch (Exception $e) {
23-
Process::run('pkill -9 -P '.$process->getPid());
24-
throw $e;
28+
} finally {
29+
$process->stop();
2530
}
2631

27-
Process::run('pkill -9 -P '.$process->getPid());
28-
29-
expect(true)->toBeTrue();
32+
try {
33+
expect($output)->toContain('Running the dev script with npm');
34+
} catch (ExpectationFailedException) {
35+
throw new ExpectationFailedException(sprintf(
36+
'"%s" does not match the expected output.',
37+
$output,
38+
));
39+
}
3040
});

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ protected function setUp(): void
1616
{
1717
parent::setUp();
1818

19-
Artisan::call('native:install', ['--force' => true]);
19+
Artisan::call('native:install', ['--force' => true, '--no-interaction' => true]);
2020
}
2121
}

0 commit comments

Comments
 (0)