Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ Some services are provided to be injected in contexts, which are the following:
*Note:* You don't really need to bother with the services names, as they are
compatible with behat's auto-wiring feature.

In order to enable the Json assertions, you need to either extend
`Behapi\Json\AbstractContext` or use `Behapi\Context\Json`. If you want to use
something else for the source (as the `Behapi\Json\Context` context is
dependant on [php-http](https://github.com/php-http/)), extend the
`Behapi\Json\AbstractContext` class.
In order to enable the Json assertions, you need to use `Behapi\Context\Json`.
If you want to use something else for the source (as the `Behapi\Json\Context`
context is dependant on [php-http](https://github.com/php-http/)), extend the
`Behapi\Json\Context` class.

If you need to play with the request being built, or the response created when
the request is sent, you need to inject the `@Behapi\HttpHistory\History`. It is
Expand Down
12 changes: 10 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ parameters:
ignoreErrors:
# have to ignore it, because Symfony config works like that and I'm waaay
# too lazy to properly structure the node builders just to add some asserts
# and stuff like that for every line (or almost).
- '{Cannot call method arrayNode() on Symfony\Component\Config\Definition\Builder\NodeParentInterface|null.}'
# and stuff like that for (almost) every line.
- '{^Cannot call method arrayNode\\() on Symfony\Component\Config\Definition\Builder\NodeParentInterface|null.$}'

# Waiting for https://github.com/phpstan/phpstan/issues/1615 to be solved
# and then this ignore pattern can be gone.
#
# As there is some sort of "magic" with nette / neon, we kinda have to make
# a magic pattern so we can't focus this ignore on the Assert lib
# specifically. But as it should temporary, who cares, amiritte ?
- "{^Trying to invoke array\\('Webmozart[\\\\].+?', 'notSame'|'same'\\) but it might not be a callable.$}"

includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
255 changes: 0 additions & 255 deletions src/Json/AbstractContext.php

This file was deleted.

33 changes: 33 additions & 0 deletions src/Json/ComparisonTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
namespace Behapi\Json;

use Webmozart\Assert\Assert;

trait ComparisonTrait
{
abstract protected function getValue(?string $path);

/** @Then in the json, :path should be greater than :expected */
final public function the_json_path_should_be_greater_than(string $path, int $expected): void
{
Assert::greaterThan($this->getValue($path), $expected);
}

/** @Then in the json, :path should be greater than or equal to :expected */
final public function the_json_path_should_be_greater_or_equal_than(string $path, int $expected): void
{
Assert::greaterThanEq($this->getValue($path), $expected);
}

/** @Then in the json, :path should be less than :expected */
final public function the_json_path_should_be_less_than(string $path, int $expected): void
{
Assert::lessThan($this->getValue($path), $expected);
}

/** @Then in the json, :path should be less than or equal to :expected */
final public function the_json_path_should_be_less_or_equal_than(string $path, int $expected): void
{
Assert::lessThanEq($this->getValue($path), $expected);
}
}
Loading