Skip to content

Commit

Permalink
update command
Browse files Browse the repository at this point in the history
  • Loading branch information
timiTao committed Jan 8, 2019
1 parent 7854946 commit d2f1e8d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions spec/Api/Command/RunCommand/CommandSpec.php
Expand Up @@ -19,7 +19,7 @@ class CommandSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith('test');
$this->beConstructedWith('test', ['test']);
}

function it_is_initializable()
Expand All @@ -28,8 +28,12 @@ function it_is_initializable()
$this->shouldHaveType(CommandConsumer::class);
}

function it_should_have_data(): void
function it_should_have_query(): void
{
$this->getCypherQuery()->shouldBeString();
}
function it_should_have_parameters(): void
{
$this->getParameters()->shouldBeArray();
}
}
14 changes: 12 additions & 2 deletions src/Api/Command/RunCommand/Command.php
Expand Up @@ -22,10 +22,14 @@ class Command implements CommandConsumer
/** @var string */
private $query;

public function __construct(string $query)
/** @var array */
private $parameters;

public function __construct(string $query, array $parameters = [])
{
Assertion::notEmpty($query);
$this->query = $query;
$this->parameters = $parameters;
}

public function getName(): Name
Expand All @@ -36,12 +40,18 @@ public function getName(): Name
public function getPayload(): array
{
return [
'query' => $this->query
'query' => $this->query,
'parameters' => $this->parameters
];
}

public function getCypherQuery(): string
{
return $this->query;
}

public function getParameters(): array
{
return $this->parameters;
}
}
2 changes: 1 addition & 1 deletion src/Api/Command/RunCommand/UseCase.php
Expand Up @@ -27,7 +27,7 @@ public function __construct(Client $client)
public function handle(Command $command): Response
{
try {
$this->client->run($command->getCypherQuery());
$this->client->run($command->getCypherQuery(), $command->getParameters());
} catch (Neo4jExceptionInterface $e) {
return Response::fail($e->getMessage());
}
Expand Down

0 comments on commit d2f1e8d

Please sign in to comment.