Completed
Push — master ( d87057...f3ab30 )
by Jaap
28s queued 12s
created

PregSplitTest::tearDown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace phpDocumentor\Reflection;
6
7
use phpDocumentor\Reflection\Exception\PcreException;
8
use PHPUnit\Framework\TestCase;
9
use function set_error_handler;
10
use const E_WARNING;
11
12
final class PregSplitTest extends TestCase
13
{
14
    /** @var callable|null */
15
    private $errorHandler = null;
16
17
    protected function tearDown() : void
18
    {
19
        if ($this->errorHandler === null) {
20
            return;
21
        }
22
23
        set_error_handler($this->errorHandler, E_WARNING);
24
    }
25
26
    /**
27
     * @covers \phpDocumentor\Reflection\Utils::pregSplit
28
     */
29
    public function testSimplePregSplit() : void
30
    {
31
        $result = Utils::pregSplit('/\s/', 'word split');
32
33
        $this->assertSame(['word', 'split'], $result);
34
    }
35
36
    /**
37
     * @covers \phpDocumentor\Reflection\Utils::pregSplit
38
     */
39
    public function testPregSplitThrowsOnError() : void
40
    {
41
        //We need to disable the error handler for phpunit... because we expect some errors here
42
        $this->errorHandler = set_error_handler(static function () : void {
43
        }, E_WARNING);
44
45
        $this->expectException(PcreException::class);
46
        Utils::pregSplit('~InvalidRegular)Expression~', 'some word');
47
    }
48
}
49