File tree Expand file tree Collapse file tree 2 files changed +82
-0
lines changed
tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+
5+ namespace SaschaEgerer \PhpstanTypo3 \Tests \Unit \Type \QueryResultToArrayDynamicReturnTypeExtension ;
6+
7+
8+ use PHPStan \Testing \TypeInferenceTestCase ;
9+
10+ final class QueryResultToArrayDynamicReturnTypeExtensionTest extends TypeInferenceTestCase
11+ {
12+ /**
13+ * @return iterable<mixed>
14+ */
15+ public function dataFileAsserts (): iterable
16+ {
17+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/query-result-to-array.php ' );
18+ }
19+
20+ /**
21+ * @dataProvider dataFileAsserts
22+ *
23+ * @param string $assertType
24+ * @param string $file
25+ * @param mixed ...$args
26+ */
27+ public function testFileAsserts (
28+ string $ assertType ,
29+ string $ file ,
30+ ...$ args
31+ ): void
32+ {
33+ $ this ->assertFileAsserts ($ assertType , $ file , ...$ args );
34+ }
35+
36+ public static function getAdditionalConfigFiles (): array
37+ {
38+ return [__DIR__ . '/../../../../extension.neon ' ];
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace SaschaEgerer \PhpstanTypo3 \Tests \Unit \Type \QueryResultToArrayDynamicReturnTypeExtension ;
4+
5+ use TYPO3 \CMS \Extbase \DomainObject \AbstractEntity ;
6+ use TYPO3 \CMS \Extbase \Mvc \Controller \ActionController ;
7+ use TYPO3 \CMS \Extbase \Persistence \QueryResultInterface ;
8+ use TYPO3 \CMS \Extbase \Persistence \Repository ;
9+ use TYPO3 \CMS \Extbase \Persistence \RepositoryInterface ;
10+ use function PHPStan \Testing \assertType ;
11+
12+ /**
13+ * @extends Repository<FrontendUserGroup>
14+ */
15+ class FrontendUserGroupRepository extends Repository implements RepositoryInterface
16+ {
17+
18+ }
19+
20+ class FrontendUserGroup extends AbstractEntity
21+ {
22+ }
23+
24+ class MyController extends ActionController
25+ {
26+ /**
27+ * @var FrontendUserGroupRepository
28+ */
29+ private $ myRepository ;
30+
31+ public function __construct (FrontendUserGroupRepository $ myRepository )
32+ {
33+ $ this ->myRepository = $ myRepository ;
34+ }
35+
36+ public function showAction ()
37+ {
38+ $ queryResult = $ this ->myRepository ->findAll ();
39+ $ myObjects = $ queryResult ->toArray ();
40+ assertType ('array<int, FrontendUserGroup> ' , $ myObjects );
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments