Skip to content

Commit

Permalink
typos
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Apr 9, 2022
1 parent e4082c0 commit 855db74
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/Interfaces/JobInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
interface JobInterface
{
/** ${job:key} */
public const REGEX_JOB_RESPONSE_REFERENCE = '/^\${([\w-]*)\:([\w-]*)}$/';
public const REGEX_JOB_RESPONSE_REFERENCE = '/^\${([\w]*)\:([\w-]*)}$/';

/**
* @throws InvalidArgumentException
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/WorkflowInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
interface WorkflowInterface extends Countable
{
/** ${key} */
public const REGEX_VARIABLE_REFERENCE = '/^\${([\w-]*)}$/';
public const REGEX_VARIABLE_REFERENCE = '/^\${([\w]*)}$/';

public function __construct(JobsInterface $jobs);

Expand Down
10 changes: 5 additions & 5 deletions src/Interfaces/WorkflowRunInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
use Chevere\Throwable\Errors\ArgumentCountError;

/**
* Describes the component in charge of defining a workflow run, with the arguments returned for each task.
* Describes the component in charge of defining a workflow run, with arguments returned for each job.
*/
interface WorkflowRunInterface
{
/**
* @param mixed $namedVariables
* @param mixed ...$vars Workflow variables.
*/
public function __construct(WorkflowInterface $workflow, mixed ...$namedVariables);
public function __construct(WorkflowInterface $workflow, mixed ...$vars);

/**
* Provides access to workflow uuid V4 (RFC 4122).
Expand All @@ -34,12 +34,12 @@ public function __construct(WorkflowInterface $workflow, mixed ...$namedVariable
public function uuid(): string;

/**
* Provides access to the WorkflowInterface instance.
* Provides access to the workflow instance.
*/
public function workflow(): WorkflowInterface;

/**
* Provides access to the ArgumentsInterface instance.
* Provides access to the arguments instance.
*/
public function arguments(): ArgumentsInterface;

Expand Down
9 changes: 6 additions & 3 deletions src/Interfaces/WorkflowRunnerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
use Psr\Container\ContainerInterface;

/**
* Describes the component in charge of doing.
* Describes the component in charge of running the workflow.
*/
interface WorkflowRunnerInterface
{
public function __construct(WorkflowRunInterface $workflowRun);
public function __construct(
WorkflowRunInterface $workflowRun,
ContainerInterface $container
);

public function workflowRun(): WorkflowRunInterface;

public function withRun(ContainerInterface $container): WorkflowRunnerInterface;
public function withRun(): WorkflowRunnerInterface;

public function runJob(string $name): void;
}
4 changes: 2 additions & 2 deletions src/WorkflowRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ final class WorkflowRun implements WorkflowRunInterface

private ArgumentsInterface $arguments;

public function __construct(private WorkflowInterface $workflow, mixed ...$namedVariables)
public function __construct(private WorkflowInterface $workflow, mixed ...$vars)
{
$this->uuid = Uuid::uuid4()->toString();
$this->arguments = new Arguments($workflow->parameters(), ...$namedVariables);
$this->arguments = new Arguments($workflow->parameters(), ...$vars);
$this->jobs = new Map();
}

Expand Down
27 changes: 12 additions & 15 deletions src/WorkflowRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@

final class WorkflowRunner implements WorkflowRunnerInterface
{
private ContainerInterface $container;

public function __construct(
private WorkflowRunInterface $workflowRun
private WorkflowRunInterface $workflowRun,
private ContainerInterface $container
) {
}

Expand All @@ -42,10 +41,9 @@ public function workflowRun(): WorkflowRunInterface
return $this->workflowRun;
}

public function withRun(ContainerInterface $container): WorkflowRunnerInterface
public function withRun(): WorkflowRunnerInterface
{
$new = clone $this;
$new->container = $container;
$jobs = $new->workflowRun->workflow()->jobs();
$promises = [];
foreach ($jobs->getGraph() as $jobs) {
Expand All @@ -65,17 +63,16 @@ public function withRun(ContainerInterface $container): WorkflowRunnerInterface

public function runJob(string $name): void
{
$job = $this->workflowRun()->workflow()->jobs()->get($name);
$actionName = $job->action();
/** @var ActionInterface $action */
$action = new $actionName();
$action = $action->withContainer($this->container);
$arguments = $this->getJobArguments($job);
$response = $this->getActionResponse($action, $arguments);
deepCopy($response);
$this->addJob($name, $response);

try {
$job = $this->workflowRun()->workflow()->jobs()->get($name);
$actionName = $job->action();
/** @var ActionInterface $action */
$action = new $actionName();
$action = $action->withContainer($this->container);
$arguments = $this->getJobArguments($job);
$response = $this->getActionResponse($action, $arguments);
deepCopy($response);
$this->addJob($name, $response);
}
// @codeCoverageIgnoreStart
catch (Throwable $e) {
Expand Down
11 changes: 7 additions & 4 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ function workflowRunner(

function workflowRun(
WorkflowInterface $workflow,
array $arguments = [],
array $vars = [],
?ContainerInterface $container = null
): WorkflowRunInterface {
$workflowRun = new WorkflowRun($workflow, ...$arguments);
$workflowRun = new WorkflowRun($workflow, ...$vars);

return (new WorkflowRunner($workflowRun))
->withRun($container ?? new Container())
return (new WorkflowRunner(
$workflowRun,
$container ?? new Container()
))
->withRun()
->workflowRun();
}
6 changes: 3 additions & 3 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function testFunctionWorkflow(): void
$this->assertEquals(new Workflow(new Jobs()), $workflow);
}

public function testFunctionStep(): void
public function testFunctionJob(): void
{
$args = ['action' => TestAction::class];
$step = job(...$args);
$this->assertEquals(new Job(...$args), $step);
$job = job(...$args);
$this->assertEquals(new Job(...$args), $job);
}
}
10 changes: 5 additions & 5 deletions tests/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Chevere\Tests;

use Chevere\Tests\_resources\src\TaskTestStep0;
use Chevere\Tests\_resources\src\TaskTestStep1;
use Chevere\Tests\_resources\src\TaskTestJob0;
use Chevere\Tests\_resources\src\TaskTestJob1;
use Chevere\Tests\_resources\src\TestAction;
use Chevere\Tests\_resources\src\WorkflowTestJob2;
use Chevere\Throwable\Errors\ArgumentCountError;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function testArgumentCountError(): void
{
$this->expectException(ArgumentCountError::class);
new Job(
TaskTestStep0::class,
TaskTestJob0::class,
foo: 'foo',
bar: 'invalid extra argument'
);
Expand All @@ -53,15 +53,15 @@ public function testWithArgumentCountError(): void
{
$this->expectException(ArgumentCountError::class);
new Job(
TaskTestStep0::class,
TaskTestJob0::class,
foo: 'foo',
bar: 'invalid extra argument'
);
}

public function testConstruct(): void
{
$action = TaskTestStep1::class;
$action = TaskTestJob1::class;
$arguments = [
'foo' => '1',
'bar' => 123,
Expand Down
16 changes: 8 additions & 8 deletions tests/WorkflowRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace Chevere\Tests;

use Chevere\Container\Container;
use Chevere\Tests\_resources\src\WorkflowRunnerTestStep1;
use Chevere\Tests\_resources\src\WorkflowRunnerTestStep2;
use Chevere\Tests\_resources\src\WorkflowRunnerTestJob1;
use Chevere\Tests\_resources\src\WorkflowRunnerTestJob2;
use function Chevere\Workflow\job;
use function Chevere\Workflow\workflow;
use function Chevere\Workflow\workflowRun;
Expand All @@ -31,11 +31,11 @@ public function testWorkflowRunner(): void
$bar = 'mundo';
$workflow = workflow(
step1: job(
WorkflowRunnerTestStep1::class,
WorkflowRunnerTestJob1::class,
foo: '${foo}'
),
step2: job(
WorkflowRunnerTestStep2::class,
WorkflowRunnerTestJob2::class,
foo: '${step1:response1}',
bar: '${bar}'
)->withDepends('step1')
Expand All @@ -45,13 +45,13 @@ public function testWorkflowRunner(): void
'bar' => $bar,
];
$workflowRun = new WorkflowRun($workflow, ...$arguments);
$workflowRunner = (new WorkflowRunner($workflowRun))
->withRun(new Container());
$workflowRunner = (new WorkflowRunner($workflowRun, new Container()))
->withRun();
$workflowRun = $workflowRunner->workflowRun();
$this->assertSame($workflowRun, $workflowRunner->workflowRun());
$workflowRunFunction = workflowRun($workflow, $arguments);
$this->assertEquals($workflowRunFunction->workflow(), $workflowRunner->workflowRun()->workflow());
$action1 = new WorkflowRunnerTestStep1();
$action1 = new WorkflowRunnerTestJob1();
$this->assertSame(
$action1->run(
...$action1->getArguments(...[
Expand All @@ -61,7 +61,7 @@ public function testWorkflowRunner(): void
$workflowRun->get('step1')->data()
);
$foo = $workflowRun->get('step1')->data()['response1'];
$action2 = new WorkflowRunnerTestStep2();
$action2 = new WorkflowRunnerTestJob2();
$this->assertSame(
$action2
->run(
Expand Down
26 changes: 13 additions & 13 deletions tests/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

namespace Chevere\Tests;

use Chevere\Tests\_resources\src\WorkflowTestJob0;
use Chevere\Tests\_resources\src\WorkflowTestJob1;
use Chevere\Tests\_resources\src\WorkflowTestJob2;
use Chevere\Tests\_resources\src\WorkflowTestStep0;
use Chevere\Tests\_resources\src\WorkflowTestStep1;
use Chevere\Tests\_resources\src\WorkflowTestStep2Conflict;
use Chevere\Tests\_resources\src\WorkflowTestJob2Conflict;
use Chevere\Throwable\Exceptions\BadMethodCallException;
use Chevere\Throwable\Exceptions\InvalidArgumentException;
use Chevere\Throwable\Exceptions\OutOfBoundsException;
Expand All @@ -40,7 +40,7 @@ public function testConstructEmpty(): void

public function testConstruct(): void
{
$step = new Job(WorkflowTestStep0::class);
$step = new Job(WorkflowTestJob0::class);
$steps = new Jobs(step: $step);
$workflow = new Workflow($steps);
$this->assertCount(1, $workflow);
Expand All @@ -50,7 +50,7 @@ public function testConstruct(): void

public function testWithAdded(): void
{
$step = new Job(WorkflowTestStep0::class);
$step = new Job(WorkflowTestJob0::class);
$steps = new Jobs(step: $step);
$workflow = new Workflow($steps);
$workflowWithAddedStep = $workflow->withAddedJob(step2: $step);
Expand All @@ -66,7 +66,7 @@ public function testWithAdded(): void
public function testWithAddedStepWithArguments(): void
{
$step = new Job(
WorkflowTestStep1::class,
WorkflowTestJob1::class,
foo: 'foo'
);
$workflow = (new Workflow(new Jobs(step: $step)))
Expand All @@ -79,7 +79,7 @@ public function testWithReferencedParameters(): void
$workflow = new Workflow(
new Jobs(
step1: new Job(
WorkflowTestStep1::class,
WorkflowTestJob1::class,
foo: '${foo}'
)
)
Expand All @@ -104,7 +104,7 @@ public function testWithReferencedParameters(): void
$this->expectException(InvalidArgumentException::class);
$workflow->withAddedJob(
step: new Job(
WorkflowTestStep1::class,
WorkflowTestJob1::class,
foo: '${not:found}'
)
);
Expand All @@ -115,11 +115,11 @@ public function testConflictingParameterType(): void
$this->expectException(BadMethodCallException::class);
workflow(
step1: job(
WorkflowTestStep1::class,
WorkflowTestJob1::class,
foo: '${foo}'
),
step2: job(
WorkflowTestStep2Conflict::class,
WorkflowTestJob2Conflict::class,
baz: '${foo}',
bar: 'test'
)->withDepends('step1')
Expand All @@ -131,7 +131,7 @@ public function testWithConflictingReferencedParameters(): void
$this->expectException(InvalidArgumentException::class);
workflow(
step1: job(
WorkflowTestStep1::class,
WorkflowTestJob1::class,
foo: '${foo}'
),
step2: job(
Expand All @@ -147,11 +147,11 @@ public function testWithConflictingTypeReferencedParameters(): void
$this->expectException(BadMethodCallException::class);
workflow(
step1: job(
WorkflowTestStep1::class,
WorkflowTestJob1::class,
foo: '${foo}'
),
step2: job(
WorkflowTestStep2Conflict::class,
WorkflowTestJob2Conflict::class,
baz: '${step1:bar}',
bar: '${foo}'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Chevere\Action\Action;

class TaskTestStep0 extends Action
class TaskTestJob0 extends Action
{
public function run(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Chevere\Action\Action;

class TaskTestStep1 extends Action
class TaskTestJob1 extends Action
{
public function run(string $foo, int $bar): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Chevere\Parameter\Parameters;
use Chevere\Parameter\StringParameter;

class WorkflowRunnerTestStep1 extends Action
class WorkflowRunnerTestJob1 extends Action
{
public function getResponseParameters(): ParametersInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Chevere\Parameter\Parameters;
use Chevere\Parameter\StringParameter;

class WorkflowRunnerTestStep2 extends Action
class WorkflowRunnerTestJob2 extends Action
{
public function getResponseParameters(): ParametersInterface
{
Expand Down
Loading

0 comments on commit 855db74

Please sign in to comment.