Skip to content

Commit b18ed2a

Browse files
committed
TASK: Remove dead code from and add unit test for AccessType class
1 parent f576194 commit b18ed2a

2 files changed

Lines changed: 53 additions & 13 deletions

File tree

src/Definition/AccessType.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,4 @@ public static function fromTokenType(TokenType $tokenType): self
3838
default => throw new \Exception('@TODO: Unknown AccessType')
3939
};
4040
}
41-
42-
public function toTokenType(): TokenType
43-
{
44-
return match ($this) {
45-
self::MANDATORY => TokenType::PERIOD,
46-
self::OPTIONAL => TokenType::OPTCHAIN
47-
};
48-
}
49-
50-
public function toPrecedence(): Precedence
51-
{
52-
return Precedence::ACCESS;
53-
}
5441
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/**
4+
* PackageFactory.ComponentEngine - Universal View Components for PHP
5+
* Copyright (C) 2022 Contributors of PackageFactory.ComponentEngine
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace PackageFactory\ComponentEngine\Test\Unit\Definition;
24+
25+
use PackageFactory\ComponentEngine\Definition\AccessType;
26+
use PackageFactory\ComponentEngine\Parser\Tokenizer\TokenType;
27+
use PHPUnit\Framework\TestCase;
28+
29+
final class AccessTypeTest extends TestCase
30+
{
31+
/**
32+
* @return array<string,mixed>
33+
*/
34+
public static function tokenTypeToAccessTypeExamples(): array
35+
{
36+
return [
37+
TokenType::PERIOD->name => [TokenType::PERIOD, AccessType::MANDATORY],
38+
TokenType::OPTCHAIN->name => [TokenType::OPTCHAIN, AccessType::OPTIONAL],
39+
];
40+
}
41+
42+
/**
43+
* @test
44+
* @dataProvider tokenTypeToAccessTypeExamples
45+
* @param TokenType $givenTokenType
46+
* @param AccessType $expectedAccessType
47+
* @return void
48+
*/
49+
public function canBeCreatedFromTokenType(TokenType $givenTokenType, AccessType $expectedAccessType): void
50+
{
51+
$this->assertSame($expectedAccessType, AccessType::fromTokenType($givenTokenType));
52+
}
53+
}

0 commit comments

Comments
 (0)