Skip to content

Commit 08ae588

Browse files
author
Kirill Nesmeyanov
committed
Apply phpcs
1 parent 4346bbd commit 08ae588

26 files changed

+1306
-15
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ jobs:
4141
run: composer test:unit
4242
- name: Execute Functional Tests
4343
run: composer test:functional
44+
- name: Execute Feature Tests
45+
run: composer test:feature

behat.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
default:
2+
suites:
3+
default:
4+
paths:
5+
- '%paths.base%/tests/Feature'
6+
contexts:
7+
# Executors
8+
- TypeLang\Mapper\Tests\Context\Execution\MapperContext
9+
# Providers
10+
- TypeLang\Mapper\Tests\Context\Provider\ConfigurationContext
11+
- TypeLang\Mapper\Tests\Context\Provider\MetadataContext
12+
- TypeLang\Mapper\Tests\Context\Provider\PlatformContext
13+
- TypeLang\Mapper\Tests\Context\Provider\TypeContext
14+
- TypeLang\Mapper\Tests\Context\Provider\TypeParserContext
15+
- TypeLang\Mapper\Tests\Context\Provider\TypeRepositoryContext
16+
# Utils
17+
- TypeLang\Mapper\Tests\Context\Support\VarDumperContext
18+
19+
extensions:
20+
TypeLang\Mapper\Tests\Extension\ContextArgumentTransformerExtension:
21+
capture:
22+
start: '{{'
23+
end: '}}'

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
}
2222
},
2323
"require-dev": {
24+
"behat/behat": "^3.14",
2425
"friendsofphp/php-cs-fixer": "^3.53",
2526
"jetbrains/phpstorm-attributes": "^1.0",
2627
"monolog/monolog": "^3.7",
@@ -30,6 +31,7 @@
3031
"phpunit/phpunit": "^10.5|^11.0",
3132
"rector/rector": "^1.1",
3233
"symfony/cache": "^5.4|^6.0|^7.0",
34+
"symfony/property-access": "^7.1",
3335
"symfony/stopwatch": "^5.4|^6.0|^7.0",
3436
"symfony/var-dumper": "^5.4|^6.0|^7.0",
3537
"type-lang/phpdoc": "^1.0",
@@ -61,9 +63,10 @@
6163
"scripts": {
6264
"build": "@php bin/build",
6365

64-
"test": ["@test:unit", "@test:functional"],
66+
"test": ["@test:unit", "@test:functional", "@test:feature"],
6567
"test:unit": "phpunit --testdox --testsuite=unit",
6668
"test:functional": "phpunit --testsuite=functional",
69+
"test:feature": "behat",
6770

6871
"linter": "@linter:check",
6972
"linter:check": "phpstan analyse --configuration phpstan.neon",

src/Runtime/Repository/TypeRepository.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use TypeLang\Mapper\Exception\Definition\TypeNotFoundException;
88
use TypeLang\Mapper\Platform\PlatformInterface;
9-
use TypeLang\Mapper\Runtime\Parser\TypeParserFacadeInterface;
9+
use TypeLang\Mapper\Runtime\Parser\TypeParserInterface;
1010
use TypeLang\Mapper\Type\Builder\TypeBuilderInterface;
1111
use TypeLang\Mapper\Type\TypeInterface;
1212
use TypeLang\Parser\Node\Stmt\TypeStatement;
@@ -26,7 +26,7 @@ final class TypeRepository implements
2626
* @param iterable<array-key, TypeBuilderInterface<covariant TypeStatement, TypeInterface>> $types
2727
*/
2828
public function __construct(
29-
private readonly TypeParserFacadeInterface $parser,
29+
private readonly TypeParserInterface $parser,
3030
iterable $types = [],
3131
private readonly ReferencesResolver $references = new ReferencesResolver(),
3232
) {
@@ -36,6 +36,7 @@ public function __construct(
3636

3737
/**
3838
* @param iterable<array-key, TypeBuilderInterface<covariant TypeStatement, TypeInterface>> $types
39+
*
3940
* @return list<TypeBuilderInterface<covariant TypeStatement, TypeInterface>>
4041
*/
4142
private static function toArrayList(iterable $types): array
@@ -60,7 +61,7 @@ public function setTypeRepository(TypeRepositoryInterface $parent): void
6061
*/
6162
public static function createFromPlatform(
6263
PlatformInterface $platform,
63-
TypeParserFacadeInterface $parser,
64+
TypeParserInterface $parser,
6465
ReferencesResolver $references = new ReferencesResolver(),
6566
): self {
6667
return new self(

tests/Context/Context.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Tests\Context;
6+
7+
use Behat\Behat\Context\Context as ContextInterface;
8+
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
9+
use Behat\Behat\Context\Exception\ContextNotFoundException;
10+
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
11+
use Behat\Hook\BeforeScenario;
12+
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\TextUI\Configuration\Builder;
14+
15+
abstract class Context implements ContextInterface
16+
{
17+
protected ?InitializedContextEnvironment $env = null;
18+
19+
/**
20+
* @api
21+
* @throws ContextNotFoundException
22+
*/
23+
#[BeforeScenario]
24+
public function gatherEnvironment(BeforeScenarioScope $scope): void
25+
{
26+
$environment = $scope->getEnvironment();
27+
28+
if (!$environment instanceof InitializedContextEnvironment) {
29+
throw new ContextNotFoundException('Unsupported tests environment', static::class);
30+
}
31+
32+
(new Builder())->build([]);
33+
34+
$this->env = $environment;
35+
}
36+
37+
/**
38+
* @template T of ContextInterface
39+
*
40+
* @param class-string<T> $context
41+
*
42+
* @return T
43+
* @throws ContextNotFoundException
44+
*/
45+
protected function from(string $context): ContextInterface
46+
{
47+
if ($this->env === null) {
48+
throw new ContextNotFoundException('Uninitialized environment', static::class);
49+
}
50+
51+
return $this->env->getContext($context);
52+
}
53+
}

0 commit comments

Comments
 (0)