Passed
Push — master ( 0b999e...3d12f2 )
by Baptiste
43s
created

CountTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A the_json_collection_should_have_at_least_elements() 0 6 1
A the_json_path_should_have_at_most_elements() 0 6 1
A the_json_path_should_have_elements() 0 6 1
1
<?php declare(strict_types=1);
2
namespace Behapi\Json;
3
4
use Webmozart\Assert\Assert;
5
6
trait CountTrait
7
{
8
    abstract protected function getValue(?string $path);
9
10
    /**
11
     * @Then in the json, the root collection should have at least :count element(s)
12
     * @Then in the json, :path collection should have at least :count element(s)
13
     */
14
    final public function the_json_collection_should_have_at_least_elements(?string $path = null, int $count): void
15
    {
16
        $value = $this->getValue($path);
17
18
        Assert::isCountable($value);
19
        Assert::minCount($value, $count);
20
    }
21
22
    /**
23
     * @Then in the json, the root collection should have :count element(s)
24
     * @Then in the json, :path collection should have :count element(s)
25
     */
26
    final public function the_json_path_should_have_elements(?string $path = null, int $count): void
27
    {
28
        $value = $this->getValue($path);
29
30
        Assert::isCountable($value);
31
        Assert::count($value, $count);
32
    }
33
34
    /**
35
     * @Then in the json, the root collection should have at most :count element(s)
36
     * @Then in the json, :path collection should have at most :count element(s)
37
     */
38
    final public function the_json_path_should_have_at_most_elements(?string $path = null, int $count): void
39
    {
40
        $value = $this->getValue($path);
41
42
        Assert::isCountable($value);
43
        Assert::maxCount($value, $count);
44
    }
45
}
46