EnhancedTestCase::catchExpectedException()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 14
rs 9.9666
cc 2
nc 2
nop 2
1
<?php
2
3
namespace LE_ACME2Tests;
4
5
use PHPUnit;
6
7
class EnhancedTestCase extends PHPUnit\Framework\TestCase {
8
9
    protected function catchExpectedException(string $exception, \Closure $callback) : \Exception {
10
11
        try {
12
            $callback();
13
        } catch (\Exception $e) {
14
            $this->assertEquals(
15
                $exception,
16
                get_class($e),
17
                'Exception message: ' . $e->getMessage(),
18
            );
19
            return $e;
20
        }
21
22
        throw new \RuntimeException('Expected exception not thrown: ' . $exception);
23
    }
24
}