TokenizerTest::testExtractThrowsExceptionPCRE()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.9
1
<?php declare(strict_types = 1);
2
3
namespace Apicart\FQL\Tests\Tokenizer;
4
5
use Apicart\FQL\Tokenizer\AbstractTokenExtractor;
6
use Apicart\FQL\Tokenizer\Full;
7
use Apicart\FQL\Tokenizer\Text;
8
use Apicart\FQL\Tokenizer\Tokenizer;
9
use PHPUnit\Framework\TestCase;
10
use ReflectionClass;
11
use RuntimeException;
12
13
final class TokenizerTest extends TestCase
14
{
15
16
    public function testExtractThrowsExceptionPCRE(): void
17
    {
18
        self::expectException(RuntimeException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        self::/** @scrutinizer ignore-call */ 
19
              expectException(RuntimeException::class);
Loading history...
19
        self::expectExceptionMessage('PCRE regex error code: 2');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        self::/** @scrutinizer ignore-call */ 
20
              expectExceptionMessage('PCRE regex error code: 2');
Loading history...
20
21
        $extractorMock = $this->getMockBuilder(AbstractTokenExtractor::class)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

21
        $extractorMock = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(AbstractTokenExtractor::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
22
            ->setMethods(['getExpressionTypeMap'])
23
            ->getMockForAbstractClass();
24
25
        $extractorMock->expects(self::once())
26
            ->method('getExpressionTypeMap')
27
            ->willReturn([
28
                '/(?:\D+|<\d+>)*[!?]/' => Tokenizer::TOKEN_WHITESPACE,
29
            ]);
30
31
        /** @var AbstractTokenExtractor $extractor */
32
        $extractor = $extractorMock;
33
        $extractor->extract('foobar foobar foobar', 0);
34
    }
35
36
37
    public function testFullExtractTermTokenThrowsException(): void
38
    {
39
        self::expectException(RuntimeException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        self::/** @scrutinizer ignore-call */ 
40
              expectException(RuntimeException::class);
Loading history...
40
        self::expectExceptionMessage('Could not extract term token from the given data');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        self::/** @scrutinizer ignore-call */ 
41
              expectExceptionMessage('Could not extract term token from the given data');
Loading history...
41
42
        $extractor = new Full();
43
        $reflectedClass = new ReflectionClass($extractor);
44
        $reflectedProperty = $reflectedClass->getProperty('expressionTypeMap');
45
        $reflectedProperty->setAccessible(true);
46
        $reflectedProperty->setValue([
47
            '/(?<lexeme>foobar)/' => Tokenizer::TOKEN_TERM,
48
        ]);
49
        $extractor->extract('foobar', 0);
50
    }
51
52
53
    public function testTextExtractTermTokenThrowsException(): void
54
    {
55
        self::expectException(RuntimeException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        self::/** @scrutinizer ignore-call */ 
56
              expectException(RuntimeException::class);
Loading history...
56
        self::expectExceptionMessage('Could not extract term token from the given data');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        self::/** @scrutinizer ignore-call */ 
57
              expectExceptionMessage('Could not extract term token from the given data');
Loading history...
57
58
        $extractor = new Text();
59
        $reflectedClass = new ReflectionClass($extractor);
60
        $reflectedProperty = $reflectedClass->getProperty('expressionTypeMap');
61
        $reflectedProperty->setAccessible(true);
62
        $reflectedProperty->setValue([
63
            '/(?<lexeme>foobar)/' => Tokenizer::TOKEN_TERM,
64
        ]);
65
        $extractor->extract('foobar', 0);
66
    }
67
68
}
69