Skip to content

Commit 48901c8

Browse files
committed
Split IntegrationTest
1 parent 22a282c commit 48901c8

3 files changed

Lines changed: 144 additions & 83 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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\Integration;
24+
25+
use PackageFactory\ComponentEngine\Parser\Ast\ModuleNode;
26+
use PackageFactory\ComponentEngine\Parser\Tokenizer\Tokenizer;
27+
use PackageFactory\ComponentEngine\Parser\Source\Source;
28+
use PHPUnit\Framework\TestCase;
29+
30+
final class ParserIntegrationTest extends TestCase
31+
{
32+
public function astExamples(): array
33+
{
34+
return [
35+
'Comment' => ["Comment"],
36+
'Component' => ["Component"],
37+
'ComponentWithKeywords' => ["ComponentWithKeywords"],
38+
'ComponentWithNesting' => ["ComponentWithNesting"],
39+
'Enum' => ["Enum"],
40+
'Expression' => ["Expression"],
41+
'ImportExport' => ["ImportExport"],
42+
'Match' => ["Match"],
43+
'Numbers' => ["Numbers"],
44+
'Struct' => ["Struct"],
45+
'TemplateLiteral' => ["TemplateLiteral"],
46+
];
47+
}
48+
49+
/**
50+
* @dataProvider astExamples
51+
* @test
52+
* @small
53+
* @param string $input
54+
* @return void
55+
*/
56+
public function testParser(string $example): void
57+
{
58+
$source = Source::fromFile(__DIR__ . '/Examples/' . $example . '/' . $example . '.afx');
59+
$tokenizer = Tokenizer::fromSource($source);
60+
$expected = json_decode(
61+
file_get_contents(__DIR__ . '/Examples/' . $example . '/' . $example . '.ast.json'),
62+
true
63+
);
64+
65+
$module = ModuleNode::fromTokens($tokenizer->getIterator());
66+
67+
$this->assertEquals($expected, json_decode(json_encode($module), true));
68+
}
69+
}

test/Integration/IntegrationTest.php renamed to test/Integration/PhpTranspilerIntegrationTest.php

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -35,90 +35,8 @@
3535
use PackageFactory\ComponentEngine\TypeSystem\Type\StringType\StringType;
3636
use PHPUnit\Framework\TestCase;
3737

38-
final class IntegrationTest extends TestCase
38+
final class PhpTranspilerIntegrationTest extends TestCase
3939
{
40-
public function tokenizationExamples(): array
41-
{
42-
return [
43-
'Comment' => ["Comment"],
44-
'Component' => ["Component"],
45-
'ComponentWithKeywords' => ["ComponentWithKeywords"],
46-
'ComponentWithNesting' => ["ComponentWithNesting"],
47-
'Enum' => ["Enum"],
48-
'Expression' => ["Expression"],
49-
'ImportExport' => ["ImportExport"],
50-
'Match' => ["Match"],
51-
'Numbers' => ["Numbers"],
52-
'Struct' => ["Struct"],
53-
'TemplateLiteral' => ["TemplateLiteral"],
54-
];
55-
}
56-
57-
/**
58-
* @dataProvider tokenizationExamples
59-
* @test
60-
* @small
61-
* @param string $input
62-
* @return void
63-
*/
64-
public function testTokenizer(string $example): void
65-
{
66-
$source = Source::fromFile(__DIR__ . '/Examples/' . $example . '/' . $example . '.afx');
67-
$tokenizer = Tokenizer::fromSource($source);
68-
$expected = json_decode(
69-
file_get_contents(__DIR__ . '/Examples/' . $example . '/' . $example . '.tokens.json')
70-
);
71-
72-
$index = 0;
73-
foreach ($tokenizer as $token) {
74-
if (!isset($expected[$index])) {
75-
$tokenType = $token->type;
76-
$this->fail("Unfinished expectation at $index [$tokenType->name]($token->value)");
77-
}
78-
$this->assertEquals($expected[$index]->type, $token->type->name, "Type mismatch at index $index ($token->value)");
79-
$this->assertEquals($expected[$index]->value, $token->value, "Value mismatch at index $index");
80-
$index++;
81-
}
82-
}
83-
84-
public function astExamples(): array
85-
{
86-
return [
87-
'Comment' => ["Comment"],
88-
'Component' => ["Component"],
89-
'ComponentWithKeywords' => ["ComponentWithKeywords"],
90-
'ComponentWithNesting' => ["ComponentWithNesting"],
91-
'Enum' => ["Enum"],
92-
'Expression' => ["Expression"],
93-
'ImportExport' => ["ImportExport"],
94-
'Match' => ["Match"],
95-
'Numbers' => ["Numbers"],
96-
'Struct' => ["Struct"],
97-
'TemplateLiteral' => ["TemplateLiteral"],
98-
];
99-
}
100-
101-
/**
102-
* @dataProvider astExamples
103-
* @test
104-
* @small
105-
* @param string $input
106-
* @return void
107-
*/
108-
public function testParser(string $example): void
109-
{
110-
$source = Source::fromFile(__DIR__ . '/Examples/' . $example . '/' . $example . '.afx');
111-
$tokenizer = Tokenizer::fromSource($source);
112-
$expected = json_decode(
113-
file_get_contents(__DIR__ . '/Examples/' . $example . '/' . $example . '.ast.json'),
114-
true
115-
);
116-
117-
$module = ModuleNode::fromTokens($tokenizer->getIterator());
118-
119-
$this->assertEquals($expected, json_decode(json_encode($module), true));
120-
}
121-
12240
public function transpilerExamples(): array
12341
{
12442
return [
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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\Integration;
24+
25+
use PackageFactory\ComponentEngine\Parser\Tokenizer\Tokenizer;
26+
use PackageFactory\ComponentEngine\Parser\Source\Source;
27+
use PHPUnit\Framework\TestCase;
28+
29+
final class TokenizerIntegrationTest extends TestCase
30+
{
31+
public function tokenizationExamples(): array
32+
{
33+
return [
34+
'Comment' => ["Comment"],
35+
'Component' => ["Component"],
36+
'ComponentWithKeywords' => ["ComponentWithKeywords"],
37+
'ComponentWithNesting' => ["ComponentWithNesting"],
38+
'Enum' => ["Enum"],
39+
'Expression' => ["Expression"],
40+
'ImportExport' => ["ImportExport"],
41+
'Match' => ["Match"],
42+
'Numbers' => ["Numbers"],
43+
'Struct' => ["Struct"],
44+
'TemplateLiteral' => ["TemplateLiteral"],
45+
];
46+
}
47+
48+
/**
49+
* @dataProvider tokenizationExamples
50+
* @test
51+
* @small
52+
* @param string $input
53+
* @return void
54+
*/
55+
public function testTokenizer(string $example): void
56+
{
57+
$source = Source::fromFile(__DIR__ . '/Examples/' . $example . '/' . $example . '.afx');
58+
$tokenizer = Tokenizer::fromSource($source);
59+
$expected = json_decode(
60+
file_get_contents(__DIR__ . '/Examples/' . $example . '/' . $example . '.tokens.json')
61+
);
62+
63+
$index = 0;
64+
foreach ($tokenizer as $token) {
65+
if (!isset($expected[$index])) {
66+
$tokenType = $token->type;
67+
$this->fail("Unfinished expectation at $index [$tokenType->name]($token->value)");
68+
}
69+
$this->assertEquals($expected[$index]->type, $token->type->name, "Type mismatch at index $index ($token->value)");
70+
$this->assertEquals($expected[$index]->value, $token->value, "Value mismatch at index $index");
71+
$index++;
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)