Skip to content

Commit 3411074

Browse files
committed
Improve tests
1 parent d660679 commit 3411074

16 files changed

+68
-54
lines changed

.php-cs-fixer.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
22

33
$files = PhpCsFixer\Finder::create()
4-
->in([__DIR__ . '/src']);
4+
->in([
5+
__DIR__ . '/src',
6+
// __DIR__ . '/tests',
7+
]);
58

69
return (new PhpCsFixer\Config())
710
->setRules([
8-
'@PER-CS2.0' => true,
9-
'@PER-CS2.0:risky' => true,
11+
'@PER-CS3x0' => true,
12+
'@PER-CS3x0:risky' => true,
1013
'strict_param' => true,
1114
'align_multiline_comment' => true,
1215
'array_syntax' => [

src/Runtime/Extractor/TypeExtractorInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ interface TypeExtractorInterface
88
{
99
/**
1010
* @return non-empty-string
11-
*
1211
* @throws \Throwable in case of any internal error occurs
1312
*/
1413
public function getDefinitionByValue(mixed $value): string;

src/Runtime/Parser/InMemoryTypeParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __construct(
3333

3434
/**
3535
* @param non-empty-string $definition
36+
*
3637
* @return non-empty-string
3738
*/
3839
private function keyOf(string $definition): string

src/Runtime/Repository/ReferencesResolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TypeLang\Mapper\Runtime\Repository;
66

7-
use TypeLang\Mapper\Runtime\Repository\Reference\NativeReferencesReader;
87
use TypeLang\Mapper\Runtime\Repository\Reference\ReferencesReaderInterface;
98
use TypeLang\Parser\Node\Name;
109
use TypeLang\Parser\Node\Stmt\TypeStatement;

tests/Mapping/Metadata/ClassMetadataTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,3 @@ public function testDiscriminatorManagement(): void
9494
self::assertNull($m->findDiscriminator());
9595
}
9696
}
97-
98-

tests/Mapping/Metadata/DiscriminatorMapMetadataTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PHPUnit\Framework\Attributes\CoversClass;
88
use TypeLang\Mapper\Mapping\Metadata\DiscriminatorMapMetadata;
99
use TypeLang\Mapper\Mapping\Metadata\TypeMetadata;
10-
use TypeLang\Mapper\Type\IntType;
10+
use TypeLang\Mapper\Type\TypeInterface;
1111
use TypeLang\Parser\Node\Stmt\NamedTypeNode;
1212

1313
#[CoversClass(DiscriminatorMapMetadata::class)]
@@ -25,7 +25,7 @@ public function testBasics(): void
2525

2626
public function testAddAndFindType(): void
2727
{
28-
$type = new IntType();
28+
$type = $this->createMock(TypeInterface::class);
2929
$stmt = new NamedTypeNode('int');
3030
$tm = new TypeMetadata($type, $stmt);
3131

@@ -39,7 +39,7 @@ public function testAddAndFindType(): void
3939

4040
public function testDefaultType(): void
4141
{
42-
$type = new IntType();
42+
$type = $this->createMock(TypeInterface::class);
4343
$stmt = new NamedTypeNode('int');
4444
$tm = new TypeMetadata($type, $stmt);
4545

@@ -51,5 +51,3 @@ public function testDefaultType(): void
5151
self::assertNull($m->getDefaultType());
5252
}
5353
}
54-
55-

tests/Mapping/Metadata/EmptyConditionMetadataTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ public function testMatch(): void
2424
self::assertFalse($cond->match(new \stdClass(), [1]));
2525
}
2626
}
27-
28-

tests/Mapping/Metadata/ExpressionConditionMetadataTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,25 @@
55
namespace TypeLang\Mapper\Tests\Mapping\Metadata;
66

77
use PHPUnit\Framework\Attributes\CoversClass;
8-
use Symfony\Component\ExpressionLanguage\Node\ArgumentsNode;
98
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
10-
use Symfony\Component\ExpressionLanguage\Node\GetAttrNode;
11-
use Symfony\Component\ExpressionLanguage\Node\NameNode;
12-
use Symfony\Component\ExpressionLanguage\Node\Node;
139
use Symfony\Component\ExpressionLanguage\ParsedExpression;
1410
use TypeLang\Mapper\Mapping\Metadata\ExpressionConditionMetadata;
1511

1612
#[CoversClass(ExpressionConditionMetadata::class)]
1713
final class ExpressionConditionMetadataTest extends MetadataTestCase
1814
{
19-
private function createParsedExpressionAlwaysTrue(string $context = ExpressionConditionMetadata::DEFAULT_CONTEXT_VARIABLE_NAME): ParsedExpression
15+
private function createParsedExpressionAlwaysTrue(): ParsedExpression
2016
{
2117
$root = new ConstantNode(true);
22-
return new ParsedExpression('true', $root);
23-
}
2418

25-
private function createParsedExpressionCheckContext(string $property, string $context = ExpressionConditionMetadata::DEFAULT_CONTEXT_VARIABLE_NAME): ParsedExpression
26-
{
27-
$name = new NameNode($context);
28-
$attr = new GetAttrNode($name, new ConstantNode($property), new ArgumentsNode());
29-
return new ParsedExpression($context . '.' . $property, $attr);
19+
return new ParsedExpression('true', $root);
3020
}
3121

3222
public function testGetters(): void
3323
{
34-
$expr = $this->createParsedExpressionAlwaysTrue('ctx');
24+
$expr = $this->createParsedExpressionAlwaysTrue();
3525
$m = new ExpressionConditionMetadata($expr, 'ctx', 5);
26+
3627
self::assertSame($expr, $m->getExpression());
3728
self::assertSame('ctx', $m->getContextVariableName());
3829
self::assertSame(5, $m->getTimestamp());
@@ -42,8 +33,7 @@ public function testMatchUsesExpressionNodesEvaluation(): void
4233
{
4334
$expr = $this->createParsedExpressionAlwaysTrue();
4435
$m = new ExpressionConditionMetadata($expr);
36+
4537
self::assertTrue($m->match(new \stdClass(), null));
4638
}
4739
}
48-
49-

tests/Mapping/Metadata/MatchConditionMetadataTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,34 @@ final class MatchConditionMetadataTest extends MetadataTestCase
1212
{
1313
public function testAbstractContract(): void
1414
{
15-
$impl = new class () extends MatchConditionMetadata { public function match(object $object, mixed $value): bool { return $value === 1; } };
15+
$impl = new class extends MatchConditionMetadata {
16+
public function match(object $object, mixed $value): bool
17+
{
18+
return $value === 1;
19+
}
20+
};
21+
1622
self::assertTrue($impl->match(new \stdClass(), 1));
1723
self::assertFalse($impl->match(new \stdClass(), 2));
1824
}
1925

2026
public function testTimestampInheritance(): void
2127
{
2228
$impl = new class (123) extends MatchConditionMetadata {
23-
public function match(object $object, mixed $value): bool { return true; }
29+
public function match(object $object, mixed $value): bool
30+
{
31+
return true;
32+
}
2433
};
34+
2535
self::assertSame(123, $impl->getTimestamp());
2636
}
2737

2838
public function testMatchWithDifferentObjects(): void
2939
{
30-
$impl = new class () extends MatchConditionMetadata {
31-
public function match(object $object, mixed $value): bool {
40+
$impl = new class extends MatchConditionMetadata {
41+
public function match(object $object, mixed $value): bool
42+
{
3243
return $object instanceof \stdClass && $value === 'test';
3344
}
3445
};
@@ -38,5 +49,3 @@ public function match(object $object, mixed $value): bool {
3849
self::assertFalse($impl->match(new \DateTime(), 'test'));
3950
}
4051
}
41-
42-

tests/Mapping/Metadata/MetadataTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ public function testTimestampIsFromConstructor(): void
1919

2020
public function testTimestampAutoGeneratedIsInt(): void
2121
{
22-
$m = new class () extends Metadata {};
22+
$m = new class extends Metadata {};
2323

2424
self::assertIsInt($m->getTimestamp());
2525
self::assertGreaterThanOrEqual(0, $m->getTimestamp());
2626
}
2727
}
28-
29-

0 commit comments

Comments
 (0)