Passed
Pull Request — master (#33)
by Melech
05:54 queued 02:40
created

Compare::equals()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Test\Assert\Asserters;
15
16
use Valkyrja\Test\Assert\Compare as Contract;
17
use Valkyrja\Test\Exceptions\AssertFailureException;
18
19
/**
20
 * Class Compare.
21
 *
22
 * @author Melech Mizrachi
23
 */
24
class Compare extends Asserter implements Contract
25
{
26
    /**
27
     * @inheritDoc
28
     */
29
    public function equals(mixed $expected, mixed $actual): void
30
    {
31
        $this->assertions[] = 'equals';
32
33
        if ($expected === $actual) {
34
            $this->successes[] = 'equals';
35
36
            return;
37
        }
38
39
        $this->errors[] = new AssertFailureException(
40
            sprintf('Failed asserting that expected %s matches actual %s', $expected, $actual)
41
        );
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47
    public function notEquals(mixed $unexpected, mixed $actual): void
48
    {
49
        $this->assertions[] = 'notequals';
50
51
        if ($unexpected !== $actual) {
52
            $this->successes[] = 'notequals';
53
54
            return;
55
        }
56
57
        $this->errors[] = new AssertFailureException(
58
            sprintf('Failed asserting that unexpected %s does not match actual %s', $unexpected, $actual)
59
        );
60
    }
61
}
62