Skip to content

Commit

Permalink
add ContextHelper.php
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes committed Jun 27, 2024
1 parent b71387e commit 3e8dfd7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
6 changes: 6 additions & 0 deletions config/blt.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
"default" => "App\\",
"types" => [],
],
"helpers" => [
"array" => "Blumilk\BLT\Helpers\ArrayHelper",
"class" => "Blumilk\BLT\Helpers\ClassHelper",
"context" => "Blumilk\BLT\Helpers\ContextHelper",
"nullable" => "Blumilk\BLT\Helpers\NullableHelper",
]
];
8 changes: 4 additions & 4 deletions src/Features/Traits/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Blumilk\BLT\Features\Traits;

use Behat\Gherkin\Node\TableNode;
use Blumilk\BLT\Helpers\RecognizeClassHelper;
use Blumilk\BLT\Helpers\ClassHelper;
use Blumilk\BLT\Helpers\TypesEnum;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
use Illuminate\Contracts\Container\BindingResolutionException;
Expand Down Expand Up @@ -61,7 +61,7 @@ public function dispatchObject(string $objectName, ?TableNode $table = null, int
}
}

$objectClass = RecognizeClassHelper::recognizeObjectClass($objectName);
$objectClass = ClassHelper::recognizeObjectClass($objectName);

$object = new $objectClass(...$parameters);

Expand All @@ -80,14 +80,14 @@ public function dispatchObject(string $objectName, ?TableNode $table = null, int
*/
public function assertDispatched(string $objectName, int $count = 1): void
{
$objectClass = RecognizeClassHelper::recognizeObjectClass($objectName);
$objectClass = ClassHelper::recognizeObjectClass($objectName);

$this->resolveFaker($objectName)->assertDispatched($objectClass, $count);
}

protected function resolveFaker(string $objectName): BusFake|EventFake
{
$objectType = RecognizeClassHelper::guessType($objectName);
$objectType = ClassHelper::guessType($objectName);

return match ($objectType) {
TypesEnum::Job->value => $this->busFake,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Support\Str;

class RecognizeClassHelper
class ClassHelper
{
public static function recognizeObjectClass(string $objectName): string
{
Expand Down
16 changes: 16 additions & 0 deletions src/Helpers/ContextHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Blumilk\BLT\Helpers;

use Illuminate\Support\Str;

class ContextHelper
{
public static function get(
string $helper,
) {
return config("blt.helpers.$helper") ?? "Blumilk\BLT\Helpers\\" . Str::ucfirst($helper) . "Helper";
}
}

0 comments on commit 3e8dfd7

Please sign in to comment.