mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Moves Laravel stuff to plugin
This commit is contained in:
@ -50,9 +50,6 @@
|
||||
]
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/console": "^9.30.1",
|
||||
"illuminate/support": "^9.30.1",
|
||||
"laravel/dusk": "^7.0.1",
|
||||
"pestphp/pest-dev-tools": "^2.0.0"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
@ -83,9 +80,6 @@
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-next": "2.x-dev"
|
||||
},
|
||||
"pest": {
|
||||
"plugins": [
|
||||
"Pest\\Plugins\\Coverage",
|
||||
@ -97,11 +91,6 @@
|
||||
"Pest\\Plugins\\Retry",
|
||||
"Pest\\Plugins\\Version"
|
||||
]
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Pest\\Laravel\\PestServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Laravel\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use function Pest\testDirectory;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class PestDatasetCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The Console Command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'pest:dataset {name : The name of the dataset}
|
||||
{--test-directory=tests : The name of the tests directory}';
|
||||
|
||||
/**
|
||||
* The Console Command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new dataset file';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||
|
||||
/** @var string $name */
|
||||
$name = $this->argument('name');
|
||||
|
||||
$relativePath = sprintf(testDirectory('DatasetsRepository/%s.php'), ucfirst($name));
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$target = base_path($relativePath);
|
||||
|
||||
if (File::exists($target)) {
|
||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
||||
}
|
||||
|
||||
if (! File::exists(dirname($relativePath))) {
|
||||
File::makeDirectory(dirname($relativePath));
|
||||
}
|
||||
|
||||
$contents = File::get(implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 3),
|
||||
'stubs',
|
||||
'Dataset.php',
|
||||
]));
|
||||
|
||||
$name = mb_strtolower($name);
|
||||
$contents = str_replace('{dataset_name}', $name, $contents);
|
||||
|
||||
$element = Str::singular($name);
|
||||
$contents = str_replace('{dataset_element}', $element, $contents);
|
||||
File::put($target, str_replace('{dataset_name}', $name, $contents));
|
||||
$message = sprintf('`%s` created successfully.', $relativePath);
|
||||
|
||||
$this->output->success($message);
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Laravel\Commands;
|
||||
|
||||
use Laravel\Dusk\Console\DuskCommand;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class PestDuskCommand extends DuskCommand
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'pest:dusk
|
||||
{--browse : Open a browser instead of using headless mode}
|
||||
{--without-tty : Disable output to TTY}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Run the Dusk tests for the application with Pest';
|
||||
|
||||
/**
|
||||
* Get the PHP binary to execute.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
protected function binary(): array
|
||||
{
|
||||
if ('phpdbg' === PHP_SAPI) {
|
||||
return [PHP_BINARY, '-qrr', 'vendor/pestphp/pest/bin/pest'];
|
||||
}
|
||||
|
||||
return [PHP_BINARY, 'vendor/pestphp/pest/bin/pest'];
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Laravel\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Pest\Console\Thanks;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use function Pest\testDirectory;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class PestInstallCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'pest:install {--test-directory=tests : The name of the tests directory}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Creates Pest resources in your current PHPUnit test suite';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const STUBS = 'stubs/Laravel';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$pest = base_path(testDirectory('Pest.php'));
|
||||
|
||||
if (File::exists($pest)) {
|
||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $pest));
|
||||
}
|
||||
|
||||
File::copy(implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 3),
|
||||
self::STUBS,
|
||||
'Pest.php',
|
||||
]), $pest);
|
||||
|
||||
$this->output->success('`tests/Pest.php` created successfully.');
|
||||
|
||||
if (! (bool) $this->option('no-interaction')) {
|
||||
(new Thanks($this->output))();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Laravel\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Pest\Exceptions\InvalidConsoleArgument;
|
||||
use Pest\Support\Str;
|
||||
use function Pest\testDirectory;
|
||||
use Pest\TestSuite;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class PestTestCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'pest:test {name : The name of the file} {--unit : Create a unit test} {--dusk : Create a Dusk test} {--test-directory=tests : The name of the tests directory} {--force : Overwrite the existing test file with the same name}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new test file';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
TestSuite::getInstance(base_path(), $this->option('test-directory'));
|
||||
|
||||
/** @var string $name */
|
||||
$name = $this->argument('name');
|
||||
|
||||
$type = ((bool) $this->option('unit')) ? 'Unit' : (((bool) $this->option('dusk')) ? 'Browser' : 'Feature');
|
||||
|
||||
$relativePath = sprintf(
|
||||
testDirectory('%s/%s.php'),
|
||||
$type,
|
||||
ucfirst($name)
|
||||
);
|
||||
|
||||
/* @phpstan-ignore-next-line */
|
||||
$target = base_path($relativePath);
|
||||
|
||||
if (! File::isDirectory(dirname((string) $target))) {
|
||||
File::makeDirectory(dirname((string) $target), 0777, true, true);
|
||||
}
|
||||
|
||||
if (File::exists($target) && ! (bool) $this->option('force')) {
|
||||
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
|
||||
}
|
||||
|
||||
$contents = File::get(implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 3),
|
||||
'stubs',
|
||||
sprintf('%s.php', $type),
|
||||
]));
|
||||
|
||||
$name = mb_strtolower($name);
|
||||
$name = Str::endsWith($name, 'test') ? mb_substr($name, 0, -4) : $name;
|
||||
|
||||
File::put($target, str_replace('{name}', $name, $contents));
|
||||
$message = sprintf('`%s` created successfully.', $relativePath);
|
||||
|
||||
$this->output->success($message);
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Laravel;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Dusk\Console\DuskCommand;
|
||||
use Pest\Laravel\Commands\PestDatasetCommand;
|
||||
use Pest\Laravel\Commands\PestDuskCommand;
|
||||
use Pest\Laravel\Commands\PestInstallCommand;
|
||||
use Pest\Laravel\Commands\PestTestCommand;
|
||||
|
||||
final class PestServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register Artisan Commands.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->commands([
|
||||
PestInstallCommand::class,
|
||||
PestTestCommand::class,
|
||||
PestDatasetCommand::class,
|
||||
]);
|
||||
|
||||
if (class_exists(DuskCommand::class)) {
|
||||
$this->commands([
|
||||
PestDuskCommand::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,9 +5,10 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
it('passes', function ($value) {
|
||||
expect($value)->toHaveLength(9);
|
||||
})->with([
|
||||
'Fortaleza', 'Sollefteå', 'Ιεράπετρα',
|
||||
'Fortaleza',
|
||||
'Sollefteå',
|
||||
'Ιεράπετρα',
|
||||
(object) [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
collect([1, 2, 3, 4, 5, 6, 7, 8, 9]),
|
||||
]);
|
||||
|
||||
it('passes with array', function () {
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
uses(Macroable::class);
|
||||
|
||||
beforeEach()->macro('bar', function () {
|
||||
expect($this)->toBeInstanceOf(TestCase::class);
|
||||
});
|
||||
|
||||
it('can call chained macro method')->bar();
|
||||
|
||||
it('will throw exception from call if no macro exists')
|
||||
->throws(BadMethodCallException::class)
|
||||
->foo();
|
||||
Reference in New Issue
Block a user