Skip to content

Commit 403ea77

Browse files
committed
Improve float + int and add backed enum tests
1 parent b92fcc1 commit 403ea77

File tree

9 files changed

+913
-89
lines changed

9 files changed

+913
-89
lines changed

behat.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ default:
1515
- TypeLang\Mapper\Tests\Context\Provider\MetadataContext
1616
- TypeLang\Mapper\Tests\Context\Provider\PlatformContext
1717
- TypeLang\Mapper\Tests\Context\Provider\TypeContext
18+
- TypeLang\Mapper\Tests\Context\Provider\TypeContext\EnumTypeContext
1819
- TypeLang\Mapper\Tests\Context\Provider\TypeParserContext
1920
- TypeLang\Mapper\Tests\Context\Provider\TypeRepositoryContext
2021
# Utils

src/Exception/Mapping/text.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
- Всё
4+
- Некорректное значение (значение)
5+
- Некорректное значение для типа (значение, ожидаемый тип)
6+
- Объект
7+
- Неизвестное значение для поля (поле объекта, тип поля + объекта)
8+
- Тип у поля не указан (значение, поле объекта, ожидаемый тип объекта)
9+
- Некорректное значение для поля (значение, поле объекта, тип поля + объекта)
10+
- Массив
11+
- Неизвестное значение для ключа (индекс массива)
12+
- Некорректное значение для ключа (значение, индекс массива)
13+
- Некорректное значение для значения (значение, индекс массива)

tests/Context/Provider/TypeContext.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public function givenTypeStatement(string $type): void
7070
#[Given('/^type "(?P<class>[a-zA-Z0-9_\x80-\xff\\\\]+?)"$/')]
7171
public function givenType(string $class): void
7272
{
73-
$this->givenTypeWith($class);
73+
$this->givenTypeWithJsonArguments($class);
7474
}
7575

7676
#[Given('/^type "(?P<class>[a-zA-Z0-9_\x80-\xff\\\\]+?)" with (?P<args>.+?)$/')]
77-
public function givenTypeWith(string $class, string $args = '{}'): void
77+
public function givenTypeWithJsonArguments(string $class, string $args = '{}'): void
7878
{
7979
try {
8080
$arguments = \json_decode($args, true, flags: \JSON_THROW_ON_ERROR);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Tests\Context\Provider\TypeContext;
6+
7+
use Behat\Step\Given;
8+
use TypeLang\Mapper\Tests\Stub\IntBackedEnumStub;
9+
use TypeLang\Mapper\Tests\Stub\StringBackedEnumStub;
10+
use TypeLang\Mapper\Type\BackedEnumType;
11+
use TypeLang\Mapper\Type\IntType;
12+
use TypeLang\Mapper\Type\StringType;
13+
14+
/**
15+
* @api
16+
* @see http://behat.org/en/latest/quick_start.html
17+
*/
18+
final class EnumTypeContext extends ExternalTypeContext
19+
{
20+
#[Given('/^type "int-backed-enum"$/')]
21+
public function givenIntBackedEnumType(): void
22+
{
23+
$this->setCurrent(new BackedEnumType(
24+
class: IntBackedEnumStub::class,
25+
type: new IntType(),
26+
));
27+
}
28+
29+
#[Given('/^type "string-backed-enum"$/')]
30+
public function givenStringBackedEnumType(): void
31+
{
32+
$this->setCurrent(new BackedEnumType(
33+
class: StringBackedEnumStub::class,
34+
type: new StringType(),
35+
));
36+
}
37+
}
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\Provider\TypeContext;
6+
7+
use TypeLang\Mapper\Tests\Context\Context;
8+
use TypeLang\Mapper\Tests\Context\Provider\TypeContext;
9+
use TypeLang\Mapper\Type\TypeInterface;
10+
use TypeLang\Parser\Node\Stmt\TypeStatement;
11+
12+
/**
13+
* @api
14+
* @see http://behat.org/en/latest/quick_start.html
15+
*/
16+
abstract class ExternalTypeContext extends Context
17+
{
18+
/**
19+
* @api
20+
*/
21+
public function getCurrent(): TypeInterface
22+
{
23+
return $this->from(TypeContext::class)
24+
->getCurrent();
25+
}
26+
27+
/**
28+
* @api
29+
*/
30+
public function setCurrent(TypeInterface $type): TypeInterface
31+
{
32+
return $this->from(TypeContext::class)
33+
->setCurrent($type);
34+
}
35+
36+
/**
37+
* @api
38+
*/
39+
public function getStatement(): TypeStatement
40+
{
41+
return $this->from(TypeContext::class)
42+
->getStatement();
43+
}
44+
45+
/**
46+
* @api
47+
*/
48+
public function setStatement(TypeStatement $type): TypeStatement
49+
{
50+
return $this->from(TypeContext::class)
51+
->setStatement($type);
52+
}
53+
}

tests/Feature/Type/float.feature

+153-28
Large diffs are not rendered by default.

tests/Feature/Type/int-backed-enum.feature

+260
Large diffs are not rendered by default.

tests/Feature/Type/int.feature

+130-59
Large diffs are not rendered by default.

tests/Feature/Type/string-backed-enum.feature

+264
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)