Skip to content

Commit 3ebd10a

Browse files
committed
Added test
1 parent 3daf927 commit 3ebd10a

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace SaschaEgerer\PhpstanTypo3\Tests\Unit\Type;
4+
5+
use PHPStan\Testing\TypeInferenceTestCase;
6+
7+
class SiteGetAttributeDynamicReturnTypeExtensionTest extends TypeInferenceTestCase
8+
{
9+
10+
/**
11+
* @return iterable<mixed>
12+
*/
13+
public function dataFileAsserts(): iterable
14+
{
15+
// path to a file with actual asserts of expected types:
16+
yield from $this->gatherAssertTypes(__DIR__ . '/data/site-get-attribute-return-types.php');
17+
}
18+
19+
/**
20+
* @dataProvider dataFileAsserts
21+
* @param string $assertType
22+
* @param string $file
23+
* @param mixed ...$args
24+
*/
25+
public function testFileAsserts(
26+
string $assertType,
27+
string $file,
28+
...$args
29+
): void
30+
{
31+
$this->assertFileAsserts($assertType, $file, ...$args);
32+
}
33+
34+
public static function getAdditionalConfigFiles(): array
35+
{
36+
return [
37+
__DIR__ . '/../../../extension.neon',
38+
__DIR__ . '/data/site-get-attribute-return-types.neon',
39+
];
40+
}
41+
42+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
typo3:
3+
siteGetAttributeMapping:
4+
myCustomIntAttribute: int
5+
myCustomStringAttribute: string
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace SiteGetAttributeReturnTypes;
4+
5+
use TYPO3\CMS\Core\Site\Entity\Site;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
// phpcs:ignore Squiz.Classes.ClassFileName.NoMatch
10+
class MySite
11+
{
12+
13+
public function getAttributeTests(Site $site): void
14+
{
15+
assertType('string', $site->getAttribute('base'));
16+
assertType('array<int, mixed>', $site->getAttribute('baseVariants'));
17+
assertType('array<int, mixed>', $site->getAttribute('errorHandling'));
18+
assertType('array<int, mixed>', $site->getAttribute('languages'));
19+
assertType('int', $site->getAttribute('rootPageId'));
20+
assertType('array', $site->getAttribute('routeEnhancers'));
21+
assertType('string', $site->getAttribute('websiteTitle'));
22+
assertType('int', $site->getAttribute('myCustomIntAttribute'));
23+
assertType('string', $site->getAttribute('myCustomStringAttribute'));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)