|
| 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\TypeSystem\Resolver\Access; |
| 24 | + |
| 25 | +use PackageFactory\ComponentEngine\Parser\Ast\AccessNode; |
| 26 | +use PackageFactory\ComponentEngine\Parser\Ast\ExpressionNode; |
| 27 | +use PackageFactory\ComponentEngine\Test\Unit\TypeSystem\Scope\Fixtures\DummyScope; |
| 28 | +use PackageFactory\ComponentEngine\TypeSystem\Resolver\Access\AccessTypeResolver; |
| 29 | +use PackageFactory\ComponentEngine\TypeSystem\Type\StringType\StringType; |
| 30 | +use PHPUnit\Framework\TestCase; |
| 31 | + |
| 32 | +final class AccessTypeResolverTest extends TestCase |
| 33 | +{ |
| 34 | + public function invalidAccessExamples(): iterable |
| 35 | + { |
| 36 | + yield 'access property on primitive string' => [ |
| 37 | + 'someString.bar', |
| 38 | + '@TODO: Cannot access on type PackageFactory\ComponentEngine\TypeSystem\Type\StringType\StringType' |
| 39 | + ]; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @dataProvider invalidAccessExamples |
| 44 | + * @test |
| 45 | + */ |
| 46 | + public function invalidAccessResultsInError(string $accessAsString, string $expectedErrorMessage): void |
| 47 | + { |
| 48 | + $this->expectExceptionMessage($expectedErrorMessage); |
| 49 | + |
| 50 | + $scope = new DummyScope([ |
| 51 | + 'someString' => StringType::get() |
| 52 | + ]); |
| 53 | + $accessTypeResolver = new AccessTypeResolver( |
| 54 | + scope: $scope |
| 55 | + ); |
| 56 | + $accessNode = ExpressionNode::fromString($accessAsString)->root; |
| 57 | + assert($accessNode instanceof AccessNode); |
| 58 | + |
| 59 | + $accessTypeResolver->resolveTypeOf($accessNode); |
| 60 | + } |
| 61 | +} |
0 commit comments