Skip to content

Commit

Permalink
Fixed Tests (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertWesner committed Sep 8, 2024
1 parent 5b5010d commit 87c8fa2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
testbench: ^8.18
carbon: ^2.67

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

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

- name: Execute tests
- name: Show pest version
run: vendor/bin/pest --version

- name: Execute tests on Linux
if: matrix.os == 'ubuntu-latest'
run: Xvfb :99 & DISPLAY=:99 vendor/bin/pest

- name: Execute tests on Windows
if: matrix.os == 'windows-latest'
run: vendor/bin/pest
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"nunomaduro/collision": "^7.9",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.18",
"pestphp/pest": "^2.0",
"pestphp/pest": "^2.7",
"pestphp/pest-plugin-arch": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DevelopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function handle(): void

$this->installIcon();

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

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Developer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ trait Developer
{
use ExecuteCommand;

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

note("Running the dev script with {$installer}...");
$this->executeCommand(command: $command, type: 'serve', skip_queue: $skip_queue);
$this->executeCommand(command: $command, skip_queue: $skip_queue, type: 'serve', withoutInteraction: $withoutInteraction);
}
}
34 changes: 22 additions & 12 deletions tests/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
<?php

use Illuminate\Support\Facades\Process;
use PHPUnit\Framework\ExpectationFailedException;

use function Orchestra\Testbench\remote;

it('can boot up the app', function () {
$process = remote('native:serve');
$process->setTty(true)->start(function ($type, $line) {
echo $line;
$output = '';

$process = remote('native:serve --no-dependencies --no-interaction');
$process->start(function ($type, $line) use (&$output) {
$output .= $line;
});

try {
retry(12, function () {
retry(20, function () use ($output) {
// Wait until port 8100 is open
dump('Waiting for port 8100 to open...');

$fp = @fsockopen('localhost', 8100, $errno, $errstr, 1);
if ($fp === false) {
throw new Exception('Port 8100 is not open yet');
throw new Exception(sprintf(
'Port 8100 is not open yet. Output: "%s"',
$output,
));
}
}, 5000);
} catch (Exception $e) {
Process::run('pkill -9 -P '.$process->getPid());
throw $e;
} finally {
$process->stop();
}

Process::run('pkill -9 -P '.$process->getPid());

expect(true)->toBeTrue();
try {
expect($output)->toContain('Running the dev script with npm');
} catch (ExpectationFailedException) {
throw new ExpectationFailedException(sprintf(
'"%s" does not match the expected output.',
$output,
));
}
});
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ protected function setUp(): void
{
parent::setUp();

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

0 comments on commit 87c8fa2

Please sign in to comment.