AssertPhpCodeTrait::assertEquals()
last analyzed

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace steevanb\DoctrineEvents\Tests;
4
5
trait AssertPhpCodeTrait
6
{
7
    /**
8
     * @param mixed $expected
9
     * @param mixed $actual
10
     * @param string $message
11
     * @param float $delta
12
     * @param int $maxDepth
13
     * @param bool $canonicalize
14
     * @param bool $ignoreCase
15
     */
16
    abstract protected function assertEquals(
17
        $expected,
18
        $actual,
19
        $message = '',
20
        $delta = 0.0,
21
        $maxDepth = 10,
22
        $canonicalize = false,
23
        $ignoreCase = false
24
    );
25
26
    /**
27
     * @param string $class
28
     * @param string $method
29
     * @param string $originalPhpCodeFile
30
     */
31
    protected function assertPhpCode($class, $method, $originalPhpCodeFile)
32
    {
33
        $reflectionMethod = new \ReflectionMethod($class, $method);
34
        $lines = file($reflectionMethod->getFileName());
35
        $phpCode = implode(
36
            null,
37
            array_slice(
38
                $lines,
39
                $reflectionMethod->getStartLine(),
40
                $reflectionMethod->getEndLine() - $reflectionMethod->getStartLine()
41
            )
42
        );
43
44
        $this->assertEquals(
45
            $phpCode,
46
            file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . $originalPhpCodeFile),
47
            'Php code has changed for ' . $class . '::' . $method . '().'
48
        );
49
    }
50
}
51