Passed
Push — master ( 510143...4409ff )
by Fabian
03:02
created

EnhancedTestCase::catchExpectedException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10
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
    /**
10
     * @deprecated Exception is not caught. Additional assertions in the same TestCase method will not be executed. Use catchExpectedException
11
     *
12
     * @param string $exception
13
     * @return void
14
     */
15
    public function expectException(string $exception): void
16
    {
17
        parent::expectException($exception);
18
    }
19
20
    protected function catchExpectedException(string $exception, \Closure $callback) {
21
22
        try {
23
            $callback();
24
        } catch (\Exception $e) {
25
            $this->assertEquals($exception, get_class($e));
26
            return;
27
        }
28
29
        throw new \RuntimeException('Expected exception not thrown: ' . $exception);
30
    }
31
}