Skip to content

Commit

Permalink
Merge branch 'master' of github.com:caendesilva/hyde-global
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 2, 2023
2 parents b8c75bb + d4a46cc commit ce6d94c
Show file tree
Hide file tree
Showing 19 changed files with 2,983 additions and 200 deletions.
75 changes: 0 additions & 75 deletions .github/workflows/run-tests.yml

This file was deleted.

79 changes: 79 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Test Suite

on:
push:
branches: [ "master", "develop" ]
pull_request:
branches: [ "master", "develop" ]

jobs:
coverage-tests:
runs-on: ubuntu-latest
name: Run tests with coverage

steps:
- uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
coverage: xdebug
extensions:
fileinfo

- uses: actions/checkout@v3

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --no-interaction --no-progress --no-suggest --prefer-dist

- name: Execute tests (Unit and Feature tests) via Pest
run: vendor/bin/pest --coverage-clover ./coverage.xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

matrix-tests:
if: contains(github.event.pull_request.labels.*.name, 'halt-matrix-tests') != true
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
php: [8.1, 8.2, 8.3]

runs-on: ${{ matrix.os }}
name: Run tests - ${{ matrix.os }} ${{ matrix.php }}

steps:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: fileinfo

- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --no-interaction --no-progress --no-suggest --prefer-dist

- name: Execute tests (Unit and Feature tests) via Pest
run: vendor/bin/pest
40 changes: 32 additions & 8 deletions app/Commands/PharServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Commands;

use Illuminate\Support\Facades\File;
use Hyde\Console\Commands\ServeCommand;
use Illuminate\Support\Arr;

Expand All @@ -14,14 +15,14 @@ class PharServeCommand extends ServeCommand
{
protected function getExecutablePath(): string
{
if (! \Phar::running()) {
if (! $this->isPharRunning()) {
// We're running from the source code, so we need to use the server.php file
return __DIR__.'/../../bin/test-server.php';
}

$default = parent::getExecutablePath();

if (file_exists($default)) {
if (File::exists($default)) {
return $default;
}

Expand All @@ -33,24 +34,47 @@ protected function createPharServer(): string
// Create a temporary (cached) file to store the extracted server.php file
$path = HYDE_TEMP_DIR.'/bin/server.php';

if (file_exists($path)) {
if (File::exists($path)) {
return $path;
}

$phar = \Phar::running();
$phar = new \Phar($phar);
$phar->extractTo(HYDE_TEMP_DIR, 'bin/server.php');
$this->extractServerFromPhar();

return $path;
}

protected function getEnvironmentVariables(): array
{
return Arr::whereNotNull(array_merge(parent::getEnvironmentVariables(), [
'HYDE_PHAR_PATH' => \Phar::running(false) ?: 'false',
'HYDE_BOOTSTRAP_PATH' => \Phar::running() ? 'phar://hyde.phar/app/anonymous-bootstrap.php' : realpath(__DIR__.'/../anonymous-bootstrap.php'),
'HYDE_PHAR_PATH' => $this->getPharPath() ?: 'false',
'HYDE_BOOTSTRAP_PATH' => $this->isPharRunning() ? 'phar://hyde.phar/app/anonymous-bootstrap.php' : realpath(__DIR__.'/../anonymous-bootstrap.php'),
'HYDE_WORKING_DIR' => HYDE_WORKING_DIR,
'HYDE_TEMP_DIR' => HYDE_TEMP_DIR,
]));
}

/** @internal */
protected function getPharUrl(): string
{
return \Phar::running();
}

/** @internal */
protected function getPharPath(): string
{
return \Phar::running(false);
}

/** @internal */
protected function isPharRunning(): bool
{
return $this->getPharUrl() !== '';
}

/** @codeCoverageIgnore as tests are run from source code */
protected function extractServerFromPhar(): void
{
$phar = new \Phar($this->getPharUrl());
$phar->extractTo(HYDE_TEMP_DIR, 'bin/server.php');
}
}
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,9 @@
"prefer-stable": true,
"bin": [
"hyde"
]
],
"require-dev": {
"mockery/mockery": "^1.6",
"pestphp/pest": "^2.26"
}
}
Loading

0 comments on commit ce6d94c

Please sign in to comment.