From b48821374e3c5a59348398e05b51c71a832da639 Mon Sep 17 00:00:00 2001 From: JakubKermes Date: Fri, 7 Jun 2024 13:20:35 +0200 Subject: [PATCH 1/5] Added simple init command --- src/BltServiceProvider.php | 18 ++++++++ src/Console/Commands/BltInit.php | 79 ++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/BltServiceProvider.php create mode 100644 src/Console/Commands/BltInit.php diff --git a/src/BltServiceProvider.php b/src/BltServiceProvider.php new file mode 100644 index 0000000..0a6211a --- /dev/null +++ b/src/BltServiceProvider.php @@ -0,0 +1,18 @@ +commands([ + BltInit::class, + ]); + } +} diff --git a/src/Console/Commands/BltInit.php b/src/Console/Commands/BltInit.php new file mode 100644 index 0000000..985cfe6 --- /dev/null +++ b/src/Console/Commands/BltInit.php @@ -0,0 +1,79 @@ +info("Configuring BLT package..."); + + if (!is_dir("features")) { + shell_exec("vendor/bin/behat --init"); + + if (file_exists($featureContextPath)) { + try { + $this->insertAfterLine($featureContextPath, 5, "use Blumilk\BLT\Bootstrapping\LaravelBootstrapper;"); + $this->insertAfterLine($featureContextPath, 6, "use Blumilk\BLT\Features\Toolbox;"); + $this->replaceLine($featureContextPath, 12, "class FeatureContext extends Toolbox implements Context"); + $this->insertAfterLine($featureContextPath, 22, " \$bootstrapper = new LaravelBootstrapper();\n \$bootstrapper->boot();"); + } catch (Exception $e) { + $this->error("Error configuring FeatureContext: " . $e->getMessage()); + + return; + } + } + } + + if (!file_exists(".env.behat")) { + if (!copy(".env.example", ".env.behat")) { + $this->error("Failed to copy .env.example to .env.behat"); + + return; + } + } + + $this->info("Behat configured successfully with BLT"); + } + + protected function insertAfterLine(string $filePath, int $lineNumber, string $text): void + { + $lines = file($filePath, FILE_IGNORE_NEW_LINES); + + if ($lines === false) { + throw new Exception("Failed to read file: $filePath"); + } + array_splice($lines, $lineNumber, 0, $text); + + if (file_put_contents($filePath, implode(PHP_EOL, $lines)) === false) { + throw new Exception("Failed to write to file: $filePath"); + } + } + + protected function replaceLine(string $filePath, int $lineNumber, string $text): void + { + $lines = file($filePath, FILE_IGNORE_NEW_LINES); + + if ($lines === false) { + throw new Exception("Failed to read file: $filePath"); + } + + if (!isset($lines[$lineNumber - 1])) { + throw new Exception("Line number $lineNumber does not exist in file: $filePath"); + } + $lines[$lineNumber - 1] = $text; + + if (file_put_contents($filePath, implode(PHP_EOL, $lines)) === false) { + throw new Exception("Failed to write to file: $filePath"); + } + } +} From fff6dd2452a6352b719d7afb90f2a6879cce2344 Mon Sep 17 00:00:00 2001 From: JakubKermes Date: Mon, 10 Jun 2024 18:05:20 +0200 Subject: [PATCH 2/5] Update handling commands --- composer.json | 31 +++++++++++------- src/Console/Commands/BltInit.php | 56 ++++++++------------------------ 2 files changed, 33 insertions(+), 54 deletions(-) diff --git a/composer.json b/composer.json index 64fc761..2d94556 100644 --- a/composer.json +++ b/composer.json @@ -10,18 +10,19 @@ } ], "require": { - "php": "^8.1", - "behat/behat": "^3.12", - "phpunit/phpunit": "^9.5", - "symfony/css-selector": "^6.2", - "symfony/dom-crawler": "^6.2" + "php": "^8.3", + "behat/behat": "^3.14", + "phpunit/phpunit": "^10.1|^11.0.1", + "symfony/css-selector": "^6.2|^7.1", + "symfony/dom-crawler": "^6.2|^7.1", + "illuminate/console": "v11.10.0" }, "require-dev": { - "blumilksoftware/codestyle": "^1.10", - "illuminate/contracts": "^9.1|^10.0", - "illuminate/http": "^9.1|^10.0", - "illuminate/support": "^9.1|^10.0", - "symfony/http-foundation": "^6.0" + "blumilksoftware/codestyle": "^3.1.0", + "illuminate/contracts": "^10.0|11.0", + "illuminate/http": "^10.0|11.0", + "illuminate/support": "^10.0|11.0", + "symfony/http-foundation": "^6.2|^7.1" }, "autoload": { "psr-4": { @@ -37,5 +38,13 @@ "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "Blumilk\\BLT\\BltServiceProvider" + ] + } } -} + +} \ No newline at end of file diff --git a/src/Console/Commands/BltInit.php b/src/Console/Commands/BltInit.php index 985cfe6..342500f 100644 --- a/src/Console/Commands/BltInit.php +++ b/src/Console/Commands/BltInit.php @@ -4,8 +4,9 @@ namespace Blumilk\BLT\Console\Commands; -use Exception; use Illuminate\Console\Command; +use Symfony\Component\Process\Exception\ProcessFailedException; +use Symfony\Component\Process\Process; class BltInit extends Command { @@ -14,66 +15,35 @@ class BltInit extends Command public function handle(): void { - $featureContextPath = "features/bootstrap/FeatureContext.php"; $this->info("Configuring BLT package..."); if (!is_dir("features")) { - shell_exec("vendor/bin/behat --init"); - - if (file_exists($featureContextPath)) { - try { - $this->insertAfterLine($featureContextPath, 5, "use Blumilk\BLT\Bootstrapping\LaravelBootstrapper;"); - $this->insertAfterLine($featureContextPath, 6, "use Blumilk\BLT\Features\Toolbox;"); - $this->replaceLine($featureContextPath, 12, "class FeatureContext extends Toolbox implements Context"); - $this->insertAfterLine($featureContextPath, 22, " \$bootstrapper = new LaravelBootstrapper();\n \$bootstrapper->boot();"); - } catch (Exception $e) { - $this->error("Error configuring FeatureContext: " . $e->getMessage()); - - return; - } - } + $this->initializeBehat(); } if (!file_exists(".env.behat")) { - if (!copy(".env.example", ".env.behat")) { - $this->error("Failed to copy .env.example to .env.behat"); - - return; - } + $this->copyEnvFile(); } $this->info("Behat configured successfully with BLT"); } - protected function insertAfterLine(string $filePath, int $lineNumber, string $text): void + protected function initializeBehat(): void { - $lines = file($filePath, FILE_IGNORE_NEW_LINES); + $process = new Process(["vendor/bin/behat", "--init"]); + $process->run(); - if ($lines === false) { - throw new Exception("Failed to read file: $filePath"); + if (!$process->isSuccessful()) { + throw new ProcessFailedException($process); } - array_splice($lines, $lineNumber, 0, $text); - if (file_put_contents($filePath, implode(PHP_EOL, $lines)) === false) { - throw new Exception("Failed to write to file: $filePath"); - } + $this->info($process->getOutput()); } - protected function replaceLine(string $filePath, int $lineNumber, string $text): void + protected function copyEnvFile(): void { - $lines = file($filePath, FILE_IGNORE_NEW_LINES); - - if ($lines === false) { - throw new Exception("Failed to read file: $filePath"); - } - - if (!isset($lines[$lineNumber - 1])) { - throw new Exception("Line number $lineNumber does not exist in file: $filePath"); - } - $lines[$lineNumber - 1] = $text; - - if (file_put_contents($filePath, implode(PHP_EOL, $lines)) === false) { - throw new Exception("Failed to write to file: $filePath"); + if (!copy(".env.example", ".env.behat")) { + $this->error("Failed to copy .env.example to .env.behat"); } } } From 6cc8ddbb6d4cad824ede2b24a359f2887f3b1182 Mon Sep 17 00:00:00 2001 From: JakubKermes Date: Mon, 10 Jun 2024 19:41:33 +0200 Subject: [PATCH 3/5] Update readme --- readme.md | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 4f4deb8..6b21bc1 100644 --- a/readme.md +++ b/readme.md @@ -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. ``` @@ -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() @@ -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: From c6e747cc3a316bab624f9b2cfdc8da7c650c636f Mon Sep 17 00:00:00 2001 From: JakubKermes Date: Tue, 11 Jun 2024 08:00:39 +0200 Subject: [PATCH 4/5] Update composer.json --- composer.json | 8 ++++++++ src/{BltServiceProvider.php => BLTServiceProvider.php} | 6 +++--- src/Console/Commands/{BltInit.php => BLTInit.php} | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) rename src/{BltServiceProvider.php => BLTServiceProvider.php} (60%) rename src/Console/Commands/{BltInit.php => BLTInit.php} (97%) diff --git a/composer.json b/composer.json index c89bc63..e5227ec 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "require": { "php": "^8.3", "behat/behat": "^3.14", + "illuminate/console": "^11.10", "phpunit/phpunit": "^10.1|^11.0.1", "symfony/css-selector": "^6.2|^7.1", "symfony/dom-crawler": "^6.2|^7.1" @@ -37,5 +38,12 @@ "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "Blumilk\\BLT\\BLTServiceProvider" + ] + } } } diff --git a/src/BltServiceProvider.php b/src/BLTServiceProvider.php similarity index 60% rename from src/BltServiceProvider.php rename to src/BLTServiceProvider.php index 0a6211a..a39696d 100644 --- a/src/BltServiceProvider.php +++ b/src/BLTServiceProvider.php @@ -4,15 +4,15 @@ namespace Blumilk\BLT; -use Blumilk\BLT\Console\Commands\BltInit; +use Blumilk\BLT\Console\Commands\BLTInit; use Illuminate\Support\ServiceProvider; -class BltServiceProvider extends ServiceProvider +class BLTServiceProvider extends ServiceProvider { public function boot(): void { $this->commands([ - BltInit::class, + BLTInit::class, ]); } } diff --git a/src/Console/Commands/BltInit.php b/src/Console/Commands/BLTInit.php similarity index 97% rename from src/Console/Commands/BltInit.php rename to src/Console/Commands/BLTInit.php index 342500f..aa88977 100644 --- a/src/Console/Commands/BltInit.php +++ b/src/Console/Commands/BLTInit.php @@ -8,7 +8,7 @@ use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; -class BltInit extends Command +class BLTInit extends Command { protected $signature = "blt:init"; protected $description = "Initialize BLT in your project"; From c7c9cf4ca04193d4d2cdde78a420d3aec5d7b9d6 Mon Sep 17 00:00:00 2001 From: JakubKermes Date: Sat, 15 Jun 2024 14:32:27 +0200 Subject: [PATCH 5/5] Update versioning --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e5227ec..8fc0794 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": "^8.3", "behat/behat": "^3.14", - "illuminate/console": "^11.10", + "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"