Skip to content

Commit 0997304

Browse files
Fixed class paths in context getAspect mapping (#55)
Co-authored-by: Sascha Egerer <[email protected]>
1 parent d56a3b9 commit 0997304

File tree

4 files changed

+79
-8
lines changed

4 files changed

+79
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ what type of aspect class is returned by the context API
3434
parameters:
3535
typo3:
3636
contextApiGetAspectMapping:
37-
myCustomAspect: \FlowdGmbh\MyProject\Context\MyCustomAspect
37+
myCustomAspect: FlowdGmbh\MyProject\Context\MyCustomAspect
3838
```

extension.neon

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ parameters:
5252
- phpstan.bootstrap.php
5353
typo3:
5454
contextApiGetAspectMapping:
55-
date: \TYPO3\CMS\Core\Context\DateTimeAspect
56-
visibility: \TYPO3\CMS\Core\Context\VisibilityAspect
57-
backend.user: \TYPO3\CMS\Core\Context\UserAspect
58-
frontend.user: \TYPO3\CMS\Core\Context\UserAspect
59-
workspace: \TYPO3\CMS\Core\Context\WorkspaceAspect
60-
language: \TYPO3\CMS\Core\Context\LanguageAspect
61-
typoscript: \TYPO3\CMS\Core\Context\TypoScriptAspect
55+
date: TYPO3\CMS\Core\Context\DateTimeAspect
56+
visibility: TYPO3\CMS\Core\Context\VisibilityAspect
57+
backend.user: TYPO3\CMS\Core\Context\UserAspect
58+
frontend.user: TYPO3\CMS\Core\Context\UserAspect
59+
workspace: TYPO3\CMS\Core\Context\WorkspaceAspect
60+
language: TYPO3\CMS\Core\Context\LanguageAspect
61+
typoscript: TYPO3\CMS\Core\Context\TypoScriptAspect
6262
stubFiles:
6363
- stubs/DomainObjectInterface.stub
6464
- stubs/GeneralUtility.stub
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace SaschaEgerer\PhpstanTypo3\Tests\Unit\Type;
4+
5+
use PHPStan\Testing\TypeInferenceTestCase;
6+
7+
class ContextDynamicReturnTypeExtensionTest 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/context-get-aspect-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 [__DIR__ . '/../../../extension.neon'];
37+
}
38+
39+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace ContextGetAspectReturnTypes;
4+
5+
use TYPO3\CMS\Core\Context\Context;
6+
use TYPO3\CMS\Core\Context\DateTimeAspect;
7+
use TYPO3\CMS\Core\Context\LanguageAspect;
8+
use TYPO3\CMS\Core\Context\TypoScriptAspect;
9+
use TYPO3\CMS\Core\Context\UserAspect;
10+
use TYPO3\CMS\Core\Context\VisibilityAspect;
11+
use TYPO3\CMS\Core\Context\WorkspaceAspect;
12+
13+
use function PHPStan\Testing\assertType;
14+
15+
// phpcs:ignore Squiz.Classes.ClassFileName.NoMatch
16+
class MyContext
17+
{
18+
19+
public function getAspectTests(Context $context): void
20+
{
21+
if (class_exists(TypoScriptAspect::class)) {
22+
assertType(TypoScriptAspect::class, $context->getAspect('typoscript'));
23+
}
24+
assertType(DateTimeAspect::class, $context->getAspect('date'));
25+
assertType(VisibilityAspect::class, $context->getAspect('visibility'));
26+
assertType(UserAspect::class, $context->getAspect('backend.user'));
27+
assertType(UserAspect::class, $context->getAspect('frontend.user'));
28+
assertType(WorkspaceAspect::class, $context->getAspect('workspace'));
29+
assertType(LanguageAspect::class, $context->getAspect('language'));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)