Skip to content

Commit ccdafd8

Browse files
author
Valentin Wotschel
committed
Replace test annotations with attributes
1 parent 0cd0e1a commit ccdafd8

19 files changed

+77
-172
lines changed

tests/Dissect/Lexer/AbstractLexerTest.php

+6-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Dissect\Lexer\Exception\RecognitionException;
66
use Dissect\Parser\Parser;
7+
use PHPUnit\Framework\Attributes\Test;
78
use PHPUnit\Framework\TestCase;
89

910
class AbstractLexerTest extends TestCase
@@ -15,9 +16,7 @@ public function setUp(): void
1516
$this->lexer = new StubLexer();
1617
}
1718

18-
/**
19-
* @test
20-
*/
19+
#[Test]
2120
public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccordingly()
2221
{
2322
$stream = $this->lexer->lex("ab\nc");
@@ -38,9 +37,7 @@ public function lexShouldDelegateToExtractTokenUpdatingTheLineAndOffsetAccording
3837
$this->assertEquals(2, $stream->getCurrentToken()->getLine());
3938
}
4039

41-
/**
42-
* @test
43-
*/
40+
#[Test]
4441
public function lexShouldAppendAnEofTokenAutomatically()
4542
{
4643
$stream = $this->lexer->lex("abc");
@@ -50,9 +47,7 @@ public function lexShouldAppendAnEofTokenAutomatically()
5047
$this->assertEquals(1, $stream->getCurrentToken()->getLine());
5148
}
5249

53-
/**
54-
* @test
55-
*/
50+
#[Test]
5651
public function lexShouldThrowAnExceptionOnAnUnrecognizableToken()
5752
{
5853
try {
@@ -63,18 +58,14 @@ public function lexShouldThrowAnExceptionOnAnUnrecognizableToken()
6358
}
6459
}
6560

66-
/**
67-
* @test
68-
*/
61+
#[Test]
6962
public function lexShouldNormalizeLineEndingsBeforeLexing()
7063
{
7164
$stream = $this->lexer->lex("a\r\nb");
7265
$this->assertEquals("\n", $stream->get(1)->getValue());
7366
}
7467

75-
/**
76-
* @test
77-
*/
68+
#[Test]
7869
public function lexShouldSkipTokensIfToldToDoSo()
7970
{
8071
$stream = $this->lexer->lex('aeb');

tests/Dissect/Lexer/Recognizer/RegexRecognizerTest.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Dissect\Lexer\Recognizer;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use PHPUnit\Framework\TestCase;
67

78
class RegexRecognizerTest extends TestCase
89
{
9-
/**
10-
* @test
11-
*/
10+
#[Test]
1211
public function recognizerShouldMatchAndPassTheValueByReference()
1312
{
1413
$recognizer = new RegexRecognizer('/[a-z]+/');
@@ -19,9 +18,7 @@ public function recognizerShouldMatchAndPassTheValueByReference()
1918
$this->assertEquals('lorem', $value);
2019
}
2120

22-
/**
23-
* @test
24-
*/
21+
#[Test]
2522
public function recognizerShouldFailAndTheValueShouldStayNull()
2623
{
2724
$recognizer = new RegexRecognizer('/[a-z]+/');
@@ -31,9 +28,7 @@ public function recognizerShouldFailAndTheValueShouldStayNull()
3128
$this->assertNull($value);
3229
}
3330

34-
/**
35-
* @test
36-
*/
31+
#[Test]
3732
public function recognizerShouldFailIfTheMatchIsNotAtTheBeginningOfTheString()
3833
{
3934
$recognizer = new RegexRecognizer('/[a-z]+/');

tests/Dissect/Lexer/Recognizer/SimpleRecognizerTest.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Dissect\Lexer\Recognizer;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use PHPUnit\Framework\TestCase;
67

78
class SimpleRecognizerTest extends TestCase
89
{
9-
/**
10-
* @test
11-
*/
10+
#[Test]
1211
public function recognizerShouldMatchAndPassTheValueByReference()
1312
{
1413
$recognizer = new SimpleRecognizer('class');
@@ -19,9 +18,7 @@ public function recognizerShouldMatchAndPassTheValueByReference()
1918
$this->assertEquals('class', $value);
2019
}
2120

22-
/**
23-
* @test
24-
*/
21+
#[Test]
2522
public function recognizerShouldFailAndTheValueShouldStayNull()
2623
{
2724
$recognizer = new SimpleRecognizer('class');

tests/Dissect/Lexer/RegexLexerTest.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Dissect\Lexer;
44

55
use Dissect\Parser\Parser;
6+
use PHPUnit\Framework\Attributes\Test;
67
use PHPUnit\Framework\TestCase;
78

89
class RegexLexerTest extends TestCase
@@ -14,9 +15,7 @@ protected function setUp(): void
1415
$this->lexer = new StubRegexLexer();
1516
}
1617

17-
/**
18-
* @test
19-
*/
18+
#[Test]
2019
public function itShouldCallGetTypeToRetrieveTokenType()
2120
{
2221
$stream = $this->lexer->lex('5 + 6');
@@ -27,9 +26,7 @@ public function itShouldCallGetTypeToRetrieveTokenType()
2726
$this->assertEquals(Parser::EOF_TOKEN_TYPE, $stream->get(3)->getType());
2827
}
2928

30-
/**
31-
* @test
32-
*/
29+
#[Test]
3330
public function itShouldTrackLineNumbers()
3431
{
3532
$stream = $this->lexer->lex("5\n+\n\n5");

tests/Dissect/Lexer/SimpleLexerTest.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Dissect\Lexer;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use PHPUnit\Framework\TestCase;
67

78
class SimpleLexerTest extends TestCase
@@ -23,9 +24,7 @@ public function setUp(): void
2324
->skip('WS');
2425
}
2526

26-
/**
27-
* @test
28-
*/
27+
#[Test]
2928
public function simpleLexerShouldWalkThroughTheRecognizers()
3029
{
3130
$stream = $this->lexer->lex('a (b) c');
@@ -36,9 +35,7 @@ public function simpleLexerShouldWalkThroughTheRecognizers()
3635
$this->assertEquals('C', $stream->get(4)->getType());
3736
}
3837

39-
/**
40-
* @test
41-
*/
38+
#[Test]
4239
public function simpleLexerShouldSkipSpecifiedTokens()
4340
{
4441
$stream = $this->lexer->lex('a (b) c');
@@ -48,9 +45,7 @@ public function simpleLexerShouldSkipSpecifiedTokens()
4845
}
4946
}
5047

51-
/**
52-
* @test
53-
*/
48+
#[Test]
5449
public function simpleLexerShouldReturnTheBestMatch()
5550
{
5651
$this->lexer->token('CLASS', 'class');

tests/Dissect/Lexer/StatefulLexerTest.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Dissect\Lexer;
44

55
use LogicException;
6+
use PHPUnit\Framework\Attributes\Test;
67
use PHPUnit\Framework\TestCase;
78

89
class StatefulLexerTest extends TestCase
@@ -14,29 +15,23 @@ protected function setUp(): void
1415
$this->lexer = new StatefulLexer();
1516
}
1617

17-
/**
18-
* @test
19-
*/
18+
#[Test]
2019
public function addingNewTokenShouldThrowAnExceptionWhenNoStateIsBeingBuilt()
2120
{
2221
$this->expectExceptionMessage("Define a lexer state first.");
2322
$this->expectException(LogicException::class);
2423
$this->lexer->regex('WORD', '/[a-z]+/');
2524
}
2625

27-
/**
28-
* @test
29-
*/
26+
#[Test]
3027
public function anExceptionShouldBeThrownOnLexingWithoutAStartingState()
3128
{
3229
$this->expectException(LogicException::class);
3330
$this->lexer->state('root');
3431
$this->lexer->lex('foo');
3532
}
3633

37-
/**
38-
* @test
39-
*/
34+
#[Test]
4035
public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack()
4136
{
4237
/** @noinspection PhpPossiblePolymorphicInvocationInspection */
@@ -61,9 +56,7 @@ public function theStateMechanismShouldCorrectlyPushAndPopStatesFromTheStack()
6156
$this->assertEquals('quux', $stream->get(6)->getValue());
6257
}
6358

64-
/**
65-
* @test
66-
*/
59+
#[Test]
6760
public function defaultActionShouldBeNop()
6861
{
6962
$this->lexer->state('root')

tests/Dissect/Lexer/StubLexer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class StubLexer extends AbstractLexer
66
{
77
protected function extractToken(string $string): ?Token
88
{
9-
if (strlen(utf8_decode($string)) === 0) {
9+
if (strlen(mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8')) === 0) {
1010
return null;
1111
}
1212

tests/Dissect/Lexer/TokenStream/ArrayTokenStreamTest.php

+13-36
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Dissect\Lexer\CommonToken;
66
use OutOfBoundsException;
7+
use PHPUnit\Framework\Attributes\Test;
78
use PHPUnit\Framework\TestCase;
89

910
class ArrayTokenStreamTest extends TestCase
@@ -21,17 +22,13 @@ protected function setUp(): void
2122
]);
2223
}
2324

24-
/**
25-
* @test
26-
*/
25+
#[Test]
2726
public function theCursorShouldBeOnFirstTokenByDefault()
2827
{
2928
$this->assertEquals('6', $this->stream->getCurrentToken()->getValue());
3029
}
3130

32-
/**
33-
* @test
34-
*/
31+
#[Test]
3532
public function getPositionShouldReturnCurrentPosition()
3633
{
3734
$this->stream->seek(2);
@@ -40,79 +37,61 @@ public function getPositionShouldReturnCurrentPosition()
4037
$this->assertEquals(3, $this->stream->getPosition());
4138
}
4239

43-
/**
44-
* @test
45-
*/
40+
#[Test]
4641
public function lookAheadShouldReturnTheCorrectToken()
4742
{
4843
$this->assertEquals('5', $this->stream->lookAhead(2)->getValue());
4944
}
5045

51-
/**
52-
* @test
53-
*/
46+
#[Test]
5447
public function lookAheadShouldThrowAnExceptionWhenInvalid()
5548
{
5649
$this->expectException(OutOfBoundsException::class);
5750
$this->stream->lookAhead(15);
5851
}
5952

60-
/**
61-
* @test
62-
*/
53+
#[Test]
6354
public function getShouldReturnATokenByAbsolutePosition()
6455
{
6556
$this->assertEquals('3', $this->stream->get(4)->getValue());
6657
}
6758

68-
/**
69-
* @test
70-
*/
59+
#[Test]
7160
public function getShouldThrowAnExceptionWhenInvalid()
7261
{
7362
$this->expectException(OutOfBoundsException::class);
7463
$this->stream->get(15);
7564
}
7665

77-
/**
78-
* @test
79-
*/
66+
#[Test]
8067
public function moveShouldMoveTheCursorByToAnAbsolutePosition()
8168
{
8269
$this->stream->move(2);
8370
$this->assertEquals('5', $this->stream->getCurrentToken()->getValue());
8471
}
8572

86-
/**
87-
* @test
88-
*/
73+
#[Test]
8974
public function moveShouldThrowAnExceptionWhenInvalid()
9075
{
9176
$this->expectException(OutOfBoundsException::class);
9277
$this->stream->move(15);
9378
}
9479

95-
/**
96-
* @test
97-
*/
80+
#[Test]
9881
public function seekShouldMoveTheCursorByRelativeOffset()
9982
{
10083
$this->stream->seek(4);
10184
$this->assertEquals('3', $this->stream->getCurrentToken()->getValue());
10285
}
10386

104-
/**
105-
* @test
106-
*/
87+
#[Test]
10788
public function seekShouldThrowAnExceptionWhenInvalid()
10889
{
10990
$this->expectException(OutOfBoundsException::class);
11091
$this->stream->seek(15);
11192
}
11293

113-
/**
114-
* @test
115-
*/
94+
#[Test]
11695
public function nextShouldMoveTheCursorOneTokenAhead()
11796
{
11897
$this->stream->next();
@@ -122,9 +101,7 @@ public function nextShouldMoveTheCursorOneTokenAhead()
122101
$this->assertEquals('5', $this->stream->getCurrentToken()->getValue());
123102
}
124103

125-
/**
126-
* @test
127-
*/
104+
#[Test]
128105
public function nextShouldThrowAnExceptionWhenAtTheEndOfTheStream()
129106
{
130107
$this->expectException(OutOfBoundsException::class);

0 commit comments

Comments
 (0)