Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
leeovery committed Jan 27, 2023
2 parents 168d3b7 + 5b0db71 commit 3b03356
Show file tree
Hide file tree
Showing 22 changed files with 731 additions and 196 deletions.
99 changes: 50 additions & 49 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
{
"name": "leeovery/laravel-playwright",
"description": "Backend stuff for Playwright e2e tests",
"keywords": [
"leeovery",
"laravel-playwright"
],
"homepage": "https://github.com/leeovery/laravel-playwright",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Lee Overy",
"email": "me@leeovery.com",
"role": "Developer"
}
],
"require": {
"php": "^8.1",
"illuminate/support": "^v9.0.2",
"spatie/laravel-package-tools": "^1.13"
},
"require-dev": {
"laravel/pint": "^1.3",
"orchestra/testbench": "^v7.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"Leeovery\\LaravelPlaywright\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Leeovery\\LaravelPlaywright\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Leeovery\\LaravelPlaywright\\LaravelPlaywrightServiceProvider"
]
}
"name": "leeovery/laravel-playwright",
"description": "Backend stuff for Playwright e2e tests",
"keywords": [
"leeovery",
"laravel-playwright"
],
"homepage": "https://github.com/leeovery/laravel-playwright",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Lee Overy",
"email": "me@leeovery.com",
"role": "Developer"
}
],
"require": {
"php": "^8.2",
"illuminate/support": "^v9.0.2|^10.0",
"spatie/laravel-package-tools": "^1.14",
"ext-pdo": "*"
},
"require-dev": {
"laravel/pint": "^1.4",
"orchestra/testbench": "^v7.0|v8.0",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
"Leeovery\\LaravelPlaywright\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Leeovery\\LaravelPlaywright\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Leeovery\\LaravelPlaywright\\LaravelPlaywrightServiceProvider"
]
}
}
}
115 changes: 110 additions & 5 deletions config/laravel-playwright.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

return [

/**
* Comma seperated list of valid environments which you want the Laravel Playwright
* routes exposed for. Any requests made to the routes in an environment which is
* not in this list will be rejected.
*/
'environments' => env('LARAVEL_PLAYWRIGHT_PERMITTED_ENVIRONMENTS', 'local,testing,playwright'),

'route' => [

/**
Expand Down Expand Up @@ -52,12 +59,110 @@
'user' => 'App\\Models\\User',

/**
* You can optionally register aliases for your domain models rather than having
* to provide the fully namespaced class name, you can then provide the alias
* when creating entities via the factory endpoint.
* When passing state values to the factory, you can include a FQCN or class alias (see
* below) along with a value and column, or params (if param_alias). This is handy for
* when the state method on the factory expects an object as the parameter(s). The
* separator config values defined below will be used as the detectors and
* separators to split the class/alias from the passed options/params.
*
* When passing a model or model alias, you should prefix the model definition with
* 'model.' (can be changed as desired below) so that we can differentiate it from
* a param alias.
*
* ** To fetch a model and pass to the state method: **
*
* This will trigger the "first" eloquent method to execute with a "where" clause for
* the user with an `id` of 100. This fetched and hydrated `User` will then be passed
* to your "createdBy" method on the defined factory.
*
* $state = [
* 'createdBy' => [
* ['model.User:100,id'],
* ],
* ]
*
* Alternatively you could have passed the FQCN rather than the alias and left off the
* 'id' column because that's the default. As follows:
*
* $state = [
* 'createdBy' => [
* ['model.\\App\\Models\\User:100'],
* ],
* ]
*
* ** To construct an object with params to be passed to the state method: **
*
* This will use a `param_alias` (defined below) to resolve the param for the `endsAt`
* state method on the factory as a Carbon instance with the value to the right of the
* separator. You can also pass multiple parameters to the state method that resolve using
* aliases as defined below. Parameters for the param_alias should be wrapped in
* parentheses as shown below.
*
* This example will use the `Carbon` alias (defined below - commented out) to make a
* `Carbon` instance with the value `2023-12-25 23:59:59`, and will be passed to the
* `endsAt` method on the factory:
* $state = [
* 'endsAt' => [
* ['Carbon(2023-12-25 23:59:59)'],
* ],
* ]
*
* This example will use the Carbon alias to make 2 instances, each with the date values
* as shown, and both instances will then be passed, in the order they are defined, to the `liveBetween` method on the factory class:
* $state = [
* 'liveBetween' => [
* ['Carbon(2023-01-01 00:00:00)', 'Carbon(2023-12-25 23:59:59)'],
* ],
* ]
*
* This example will use the collect alias to make a Collection with 2 items as defined.
* The Collection instance will then be passed to the comments method on the factory:
* $state = [
* 'comments' => [
* ['collect(hello,goodbye)'],
* ],
* ]
*/

/**
* Used to tell the package you want a model created, either from the passed FQCN or
* from the model_alias as defined below.
*/
'models' => [
// 'user' => 'App\\Models\\User',
'model_designator' => 'model.',

/**
* Used to separate the model from any other passed options.
*/
'model_separator' => ':',

/**
* If you wish to resolve a model from the DB, you can optionally pass the column to compare
* the value to in a where clause. The default column used is `id`. Use this separator to
* separate the desired column from the rest of the passed options.
*/
'column_separator' => ',',

/**
* If passing multiple params to be passed into an alias' callable, you can separate
* them using this option.
*/
'param_separator' => ',',

/**
* You can optionally register aliases for models or other objects, rather than having
* to provide the fully namespaced class name. You can then provide the alias
* when creating entities via the factory endpoint. You can also define here a function
* to instruct Laravel-Playwright how to construct an object with the parameters sent
* from your Playwright test suite.
*/
'model_aliases' => [
// 'User' => 'App\\Models\\User',
// 'Post' => 'App\\Models\\Post',
],

'param_aliases' => [
// 'Carbon' => fn($date) => \Carbon\Carbon::create($date),
// 'collect' => fn($items) => collect(...$items),
],

],
Expand Down
12 changes: 11 additions & 1 deletion routes/playwright.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

use Illuminate\Support\Facades\Route;
use Leeovery\LaravelPlaywright\Http\Controllers\LaravelPlaywrightController;
use Leeovery\LaravelPlaywright\Http\Middleware\PreventInNonPermittedEnvironment;

Route::prefix(config('laravel-playwright.route.prefix'))
->middleware(config('laravel-playwright.route.middleware'))
->middleware([
PreventInNonPermittedEnvironment::class,
config('laravel-playwright.route.middleware'),
])
->group(function () {
Route::post('/env-setup', [LaravelPlaywrightController::class, 'setupEnv'])
->name('playwright.setup-env');
Route::post('/env-teardown', [LaravelPlaywrightController::class, 'tearDownEnv'])
->name('playwright.tear-down-env');
Route::post('/migrate', [LaravelPlaywrightController::class, 'migrate'])
->name('playwright.migrate');
Route::post('/create-database', [LaravelPlaywrightController::class, 'createDatabase'])
->name('playwright.create-database');
Route::post('/drop-database', [LaravelPlaywrightController::class, 'dropDatabase'])
->name('playwright.drop-database');
Route::post('/truncate', [LaravelPlaywrightController::class, 'truncate'])
->name('playwright.truncate');
Route::post('/factory', [LaravelPlaywrightController::class, 'factory'])
->name('playwright.factory');
Route::post('/login', [LaravelPlaywrightController::class, 'login'])
Expand Down
47 changes: 0 additions & 47 deletions src/Actions/BaseEnvAction.php

This file was deleted.

19 changes: 0 additions & 19 deletions src/Actions/EnvSetupAction.php

This file was deleted.

14 changes: 0 additions & 14 deletions src/Actions/EnvTeardownAction.php

This file was deleted.

55 changes: 55 additions & 0 deletions src/Commands/Database/AbstractDatabaseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Leeovery\LaravelPlaywright\Commands\Database;

use Illuminate\Console\Command;
use Leeovery\LaravelPlaywright\Commands\Database\Connectors\Connector;
use Leeovery\LaravelPlaywright\Commands\Database\Connectors\DryRunConnector;
use Leeovery\LaravelPlaywright\Commands\Database\Connectors\PDOConnector;
use Leeovery\LaravelPlaywright\Commands\Database\Schema\Builder;
use Leeovery\LaravelPlaywright\Commands\Database\Schema\GrammarFactory;

abstract class AbstractDatabaseCommand extends Command
{
protected array $config = [];

protected function showIfPretendMode()
{
if ($this->isPretendRunMode()) {
$this->info('[PRETENDING] Running in pretend mode.');
}
}

protected function isPretendRunMode(): bool
{
return (bool) $this->option('pretend');
}

protected function createBuilder(): Builder
{
return new Builder(
$this->makeConnector(),
resolve(GrammarFactory::class)
);
}

protected function makeConnector(): Connector
{
if ($this->isPretendRunMode()) {
return new DryRunConnector($this->output);
}

return PDOConnector::make($this->getConfig());
}

protected function getConfig(string $key = null): mixed
{
if (! $this->config) {
$connection = $this->option('connection') ?? config('database.default');
$this->config = config(sprintf('database.connections.%s', $connection));
$this->config['database'] = $this->option('database') ?? $this->config['database'];
}

return $key ? $this->config[$key] : $this->config;
}
}
Loading

0 comments on commit 3b03356

Please sign in to comment.