Skip to content

Commit

Permalink
Add basic console tools
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes committed Jun 5, 2024
1 parent e4b1e45 commit 2a1037d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Features/Console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Blumilk\BLT\Features;

use Behat\Behat\Context\Context;
use Blumilk\BLT\Features\Traits\Console as ConsoleTrait;

class Console implements Context
{
use ConsoleTrait;
}
2 changes: 2 additions & 0 deletions src/Features/Toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Behat\Behat\Context\Context;
use Blumilk\BLT\Features\Traits\Application;
use Blumilk\BLT\Features\Traits\Authentication;
use Blumilk\BLT\Features\Traits\Console;
use Blumilk\BLT\Features\Traits\Database;
use Blumilk\BLT\Features\Traits\Dispatcher;
use Blumilk\BLT\Features\Traits\Eloquent;
Expand All @@ -21,6 +22,7 @@ class Toolbox implements Context
{
use Application;
use Authentication;
use Console;
use Database;
use Dispatcher;
use Eloquent;
Expand Down
62 changes: 62 additions & 0 deletions src/Features/Traits/Console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Blumilk\BLT\Features\Traits;

use Illuminate\Support\Facades\Artisan;
use PHPUnit\Framework\Assert;

trait Console
{
use Application;

private $consoleOutput = "";

/**
* @Given I run :command command
* @Given I run :command in console
*/
public function runCommand(string $command): void
{
$this->consoleOutput = "";
Artisan::call($command);
$this->consoleOutput = Artisan::output();
}

/**
* @Given I run :command command with arguments :arguments
* @Given I run :command command with argument :arguments
* @Given I run :command command with options :arguments
* @Given I run :command command with option :arguments
*/
public function runCommandWithArguments(string $command, string $arguments): void
{
$this->runCommand("$command $arguments");
}

/**
* @Then I see :output in console
* @Then I should see :output in console
*/
public function seeInConsole(string $output): void
{
Assert::assertStringContainsString($output, $this->consoleOutput);
}

/**
* @Then Console output is not empty
*/
public function consoleOutputIsNotEmpty(): void
{
Assert::assertNotEmpty($this->consoleOutput);
}

/**
* @Then Console output is empty
*/
public function consoleOutputIsEmpty(): void
{
Assert::assertEmpty($this->consoleOutput);
}
}

0 comments on commit 2a1037d

Please sign in to comment.