mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Add support for installing Pest into a Lumen application
This entails creating Laravel and Lumen-specific stubs, and ensuring that the appropriate stubs are copied as part of the pest install.
This commit is contained in:
@ -7,6 +7,7 @@ namespace Pest\Laravel\Commands;
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Pest\Exceptions\InvalidConsoleArgument;
|
use Pest\Exceptions\InvalidConsoleArgument;
|
||||||
|
use Pest\Support\Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -36,6 +37,8 @@ final class PestInstallCommand extends Command
|
|||||||
$pest = base_path('tests/Pest.php');
|
$pest = base_path('tests/Pest.php');
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
$helpers = base_path('tests/Helpers.php');
|
$helpers = base_path('tests/Helpers.php');
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
|
$stubs = $this->isLumen() ? 'stubs/Lumen' : 'stubs/Laravel';
|
||||||
|
|
||||||
foreach ([$pest, $helpers] as $file) {
|
foreach ([$pest, $helpers] as $file) {
|
||||||
if (File::exists($file)) {
|
if (File::exists($file)) {
|
||||||
@ -45,17 +48,25 @@ final class PestInstallCommand extends Command
|
|||||||
|
|
||||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
File::copy(implode(DIRECTORY_SEPARATOR, [
|
||||||
dirname(__DIR__, 3),
|
dirname(__DIR__, 3),
|
||||||
'stubs',
|
$stubs,
|
||||||
'Pest.php',
|
'Pest.php',
|
||||||
]), $pest);
|
]), $pest);
|
||||||
|
|
||||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
File::copy(implode(DIRECTORY_SEPARATOR, [
|
||||||
dirname(__DIR__, 3),
|
dirname(__DIR__, 3),
|
||||||
'stubs',
|
$stubs,
|
||||||
'Helpers.php',
|
'Helpers.php',
|
||||||
]), $helpers);
|
]), $helpers);
|
||||||
|
|
||||||
$this->output->success('`tests/Pest.php` created successfully.');
|
$this->output->success('`tests/Pest.php` created successfully.');
|
||||||
$this->output->success('`tests/Helpers.php` created successfully.');
|
$this->output->success('`tests/Helpers.php` created successfully.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if this is a Lumen application.
|
||||||
|
*/
|
||||||
|
protected function isLumen(): bool
|
||||||
|
{
|
||||||
|
return Str::startsWith(app()->version(), 'Lumen');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
stubs/Lumen/Helpers.php
Normal file
11
stubs/Lumen/Helpers.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the currently logged in user for the application.
|
||||||
|
*/
|
||||||
|
function actingAs(Authenticatable $user, string $driver = null): TestCase
|
||||||
|
{
|
||||||
|
return test()->actingAs($user, $driver);
|
||||||
|
}
|
||||||
3
stubs/Lumen/Pest.php
Normal file
3
stubs/Lumen/Pest.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
uses(TestCase::class);
|
||||||
17
stubs/Lumen/phpunit.xml
Normal file
17
stubs/Lumen/phpunit.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
colors="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Application Test Suite">
|
||||||
|
<directory suffix="Test.php">./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory suffix=".php">./app</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
||||||
Reference in New Issue
Block a user