Completed
Pull Request — master (#247)
by Jaap
11:03 queued 01:08
created

PregSplitTest::testSimplePregSplit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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