TestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMock() 0 4 1
A expectException() 0 12 3
1
<?php
2
3
namespace League\Fractal\Test;
4
5
use Mockery;
6
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
7
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
8
9
class TestCase extends PHPUnitTestCase
10
{
11
    use MockeryPHPUnitIntegration;
12
13
    /**
14
     * Simple Mockery accessor
15
     *
16
     * @param mixed ...$args
17
     *
18
     * @return \Mockery\MockInterface
19
     */
20
    protected function getMock(...$args): Mockery\MockInterface
21
    {
22
        return Mockery::mock(...$args);
23
    }
24
25
    /**
26
     * Combined and simplified expectedException method
27
     *
28
     * @param string $exception
29
     * @param string|null $message
30
     * @param bool $regex
31
     */
32
    public function expectException(string $exception, string $message = null, bool $regex = false): void
33
    {
34
        parent::expectException($exception);
35
36
        if ($message) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $message of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
37
            if ($regex) {
38
                $this->expectExceptionMessageRegExp($message);
39
            } else {
40
                $this->expectExceptionMessage($message);
41
            }
42
        }
43
    }
44
}
45