Passed
Push — master ( 71cd79...3a5308 )
by Vincent
02:53 queued 20s
created

ContainsAtLeastOneTest::assertContainsAtLeastOne()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace VGirol\JsonApiAssert\Tests\Constraints;
4
5
use VGirol\JsonApiAssert\Constraint\ContainsAtLeastOneConstraint;
6
use VGirol\JsonApiAssert\Tests\TestCase;
7
8
class ContainsAtLeastOneTest extends TestCase
9
{
10
    /**
11
     * @test
12
     */
13
    public function assertContainsAtLeastOne()
14
    {
15
        $allowed = ['anything', 'something'];
16
17
        $constraint = new ContainsAtLeastOneConstraint($allowed);
18
19
        $json = [
20
            'anything' => 'ok',
21
            'another' => 'ok'
22
        ];
23
        $this->assertTrue($constraint->evaluate($json, '', true));
24
    }
25
26
    /**
27
     * @test
28
     * @dataProvider assertContainsAtLeastOneFailedProvider
29
     */
30
    public function assertContainsAtLeastOneFailed($json)
31
    {
32
        $allowed = ['anything', 'something'];
33
34
        $constraint = new ContainsAtLeastOneConstraint($allowed);
35
36
        $this->assertFalse($constraint->evaluate($json, '', true));
37
    }
38
39
    public function assertContainsAtLeastOneFailedProvider()
40
    {
41
        return [
42
            'not an array' => [
43
                'failed'
44
            ],
45
            'no one expected member' => [
46
                [
47
                    'unexpected' => 'bad'
48
                ]
49
            ]
50
        ];
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function assertContainsAtLeastOneFailedAndThrowException()
57
    {
58
        $allowed = ['anything', 'something'];
59
        $json = [
60
            'unexpected' => 'bad'
61
        ];
62
63
        $constraint = new ContainsAtLeastOneConstraint($allowed);
64
65
        $this->setFailure(sprintf(
66
            '/Failed asserting that [\S\s]* %s\./',
67
            $constraint->toString()
68
        ));
69
70
        $constraint->evaluate($json);
71
    }
72
}
73