Asserts::assertIsNotAssocArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the ASSERTS package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace Ahc\Asserts;
13
14
trait Asserts
15
{
16
    public function assertJsonSubset($expected, $actual, string $message = '')
17
    {
18
        $actual   = \json_encode($actual);
19
        $expected = \json_encode($expected);
20
        $expected = \trim($expected, '{}');
21
22
        $this->assertContains($expected, $actual, "$message$actual doesnot contain $expected");
0 ignored issues
show
Bug introduced by
It seems like assertContains() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $this->/** @scrutinizer ignore-call */ 
23
               assertContains($expected, $actual, "$message$actual doesnot contain $expected");
Loading history...
23
    }
24
25
    public function assertJsonSubsets($expected, /* more expected ...*/ $actual)
26
    {
27
        $expected = \func_get_args();
28
        $actual   = \array_pop($expected);
29
30
        foreach ($expected as $i => $expect) {
31
            $this->assertJsonSubset($expect, $actual, "Data set #$i: ");
32
        }
33
    }
34
35
    public function assertFloatEquals(float $expected, float $actual, int $precision = 6, string $message = '')
36
    {
37
        if (\function_exists('bccomp')) {
38
            $this->assertSame(0, \bccomp($expected, $actual, $precision), $message);
0 ignored issues
show
Bug introduced by
The method assertSame() does not exist on Ahc\Asserts\Asserts. Did you maybe mean assertAll()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
            $this->/** @scrutinizer ignore-call */ 
39
                   assertSame(0, \bccomp($expected, $actual, $precision), $message);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
40
            return;
41
        }
42
43
        $this->assertEquals($expected, $actual, $message, \pow(10, 0 - \abs($precision)));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not exist on Ahc\Asserts\Asserts. Did you maybe mean assertFloatEquals()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        $this->/** @scrutinizer ignore-call */ 
44
               assertEquals($expected, $actual, $message, \pow(10, 0 - \abs($precision)));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
    }
45
46
    public function assertArrayHasKeys(array $expectedKeys, array $actualArray, string $message = '')
47
    {
48
        foreach ($expectedKeys as $key) {
49
            $this->assertArrayHasKey($key, $actualArray, $message);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not exist on Ahc\Asserts\Asserts. Did you maybe mean assertArrayHasKeys()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            $this->/** @scrutinizer ignore-call */ 
50
                   assertArrayHasKey($key, $actualArray, $message);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
        }
51
    }
52
53
    public function assertAll(array $expectations, $actual, array $messages = [])
54
    {
55
        foreach ($expectations as $assert => $expected) {
56
            if (\strpos($assert, 'assert') === false) {
57
                $assert = 'assert' . \ucfirst($assert);
58
            }
59
60
            $msgKey = \lcfirst(\str_replace('assert', '', $assert));
61
62
            $this->{$assert}($expected, $actual, $messages[$assert] ?? $messages[$msgKey] ?? null);
63
        }
64
    }
65
66
    public function assertIsAssocArray(array $array, string $message = '')
67
    {
68
        $this->assertTrue(\array_keys($array) !== \range(0, \count($array) - 1), $message);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not exist on Ahc\Asserts\Asserts. Did you maybe mean assertAll()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        $this->/** @scrutinizer ignore-call */ 
69
               assertTrue(\array_keys($array) !== \range(0, \count($array) - 1), $message);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
    }
70
71
    public function assertIsNotAssocArray(array $array, string $message = '')
72
    {
73
        $this->assertFalse(\array_keys($array) !== \range(0, \count($array) - 1), $message);
0 ignored issues
show
Bug introduced by
The method assertFalse() does not exist on Ahc\Asserts\Asserts. Did you maybe mean assertAll()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $this->/** @scrutinizer ignore-call */ 
74
               assertFalse(\array_keys($array) !== \range(0, \count($array) - 1), $message);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
74
    }
75
76
    public function assertFileIsExecutable(string $filePath, string $message = '')
77
    {
78
        \clearstatcache();
79
80
        $this->assertTrue(\is_executable($filePath), $message);
81
    }
82
83
    public function assertFileIsNotExecutable(string $filePath, string $message = '')
84
    {
85
        \clearstatcache();
86
87
        $this->assertFalse(\is_executable($filePath), $message);
88
    }
89
}
90