Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#35 - streamline package config #48

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"require": {
"php": "^8.3",
"behat/behat": "^3.14",
"illuminate/console": "^10.0|^11.0",
"phpunit/phpunit": "^10.1|^11.0.1",
"symfony/css-selector": "^6.2|^7.1",
"symfony/dom-crawler": "^6.2|^7.1"
Expand Down
27 changes: 22 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ BLT for PHP developers: Behat+Laravel toolbox
> Package is still under development.

### Usage
Use Composer to get package from the Packagist repository:
To start using package if you don't already have Behat initialized in your project:
```
composer require blumilksfotware/blt --dev
php artisan blt:init
```

To use the package you need to have behat installed in your project:
### Or if you want to do that manually:
Use Composer to get package from the Packagist repository:
```
php composer.phar require --dev behat/behat
composer require blumilksfotware/blt --dev
```
Create .env.behat file in your project root directory and set up your environment variables for Behat.
```
Expand All @@ -24,7 +25,7 @@ Initialize Behat in your project:
php vendor/bin/behat --init
```
To learn more about Behat visit [Behat documentation](https://docs.behat.org/en/latest/).

### To use in your tests:
Bootstrap BLT in your FeatureContext file:
```
public function __construct()
Expand All @@ -33,6 +34,22 @@ Bootstrap BLT in your FeatureContext file:
$bootstrapper->boot();
}
```
If you want to include all suite of features, you can use:
```
use Blumilk\BLT\Features\Toolbox;
class FeatureContext extends Toolbox implements Context
{...}
```
Or to use selected traits:
```
use Blumilk\BLT\Features\Traits\Eloquent;
class FeatureContext implements Context
{
use Eloquent;
...
}
```

Example usage in tests is available in the [docs](docs).
### Development
There are scripts available for package codestyle checking and testing:
Expand Down
4 changes: 4 additions & 0 deletions src/BLTServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

namespace Blumilk\BLT;

use Blumilk\BLT\Console\Commands\BLTInit;
use Illuminate\Support\ServiceProvider;

class BLTServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->commands([
BLTInit::class,
]);
$this->publishes([
__DIR__ . "/../config/blt.php" => config_path("blt.php"),
], "config");
Expand Down
49 changes: 49 additions & 0 deletions src/Console/Commands/BLTInit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Blumilk\BLT\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

class BLTInit extends Command
{
protected $signature = "blt:init";
protected $description = "Initialize BLT in your project";

public function handle(): void
{
$this->info("Configuring BLT package...");

if (!is_dir("features")) {
$this->initializeBehat();
}

if (!file_exists(".env.behat")) {
$this->copyEnvFile();
}

$this->info("Behat configured successfully with BLT");
}

protected function initializeBehat(): void
{
$process = new Process(["vendor/bin/behat", "--init"]);
$process->run();

if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}

$this->info($process->getOutput());
}

protected function copyEnvFile(): void
{
if (!copy(".env.example", ".env.behat")) {
$this->error("Failed to copy .env.example to .env.behat");
}
}
}
Loading