-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from sascha-egerer/issue/103
[BUGFIX] Make QueryResultToArrayDynamicReturnTypeExtension work with CompoundType
- Loading branch information
Showing
5 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ultToArrayDynamicReturnTypeExtension/QueryResultToArrayDynamicReturnTypeExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace SaschaEgerer\PhpstanTypo3\Tests\Unit\Type\QueryResultToArrayDynamicReturnTypeExtension; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
|
||
final class QueryResultToArrayDynamicReturnTypeExtensionTest extends TypeInferenceTestCase | ||
{ | ||
|
||
/** | ||
* @return iterable<mixed> | ||
*/ | ||
public function dataFileAsserts(): iterable | ||
{ | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/query-result-to-array.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
* | ||
* @param string $assertType | ||
* @param string $file | ||
* @param mixed ...$args | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
...$args | ||
): void | ||
{ | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [__DIR__ . '/../../../../extension.neon']; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
tests/Unit/Type/QueryResultToArrayDynamicReturnTypeExtension/data/query-result-to-array.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
// phpcs:disable Squiz.Classes.ClassFileName.NoMatch | ||
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses | ||
|
||
namespace SaschaEgerer\PhpstanTypo3\Tests\Unit\Type\QueryResultToArrayDynamicReturnTypeExtension; | ||
|
||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; | ||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; | ||
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult; | ||
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; | ||
use TYPO3\CMS\Extbase\Persistence\Repository; | ||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* @extends Repository<FrontendUserGroup> | ||
*/ | ||
class FrontendUserGroupRepository extends Repository | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @extends Repository<FrontendUserGroup> | ||
*/ | ||
class FrontendUserCustomFindAllGroupRepository extends Repository | ||
{ | ||
|
||
/** | ||
* @return QueryResultInterface<FrontendUserGroup> | ||
*/ | ||
public function findAll(): QueryResultInterface // phpcs:ignore SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint | ||
{ | ||
$queryResult = null; // phpcs:ignore SlevomatCodingStandard.Variables.UselessVariable.UselessVariable | ||
/** @var QueryResult<FrontendUserGroup> $queryResult */ | ||
return $queryResult; | ||
} | ||
|
||
} | ||
|
||
class FrontendUserGroup extends AbstractEntity | ||
{ | ||
|
||
} | ||
|
||
class MyController extends ActionController | ||
{ | ||
|
||
/** @var FrontendUserGroupRepository */ | ||
private $myRepository; | ||
|
||
/** @var FrontendUserCustomFindAllGroupRepository */ | ||
private $myCustomFindAllRepository; | ||
|
||
public function __construct( | ||
FrontendUserGroupRepository $myRepository, | ||
FrontendUserCustomFindAllGroupRepository $myCustomFindAllRepository | ||
) | ||
{ | ||
$this->myRepository = $myRepository; | ||
$this->myCustomFindAllRepository = $myCustomFindAllRepository; | ||
} | ||
|
||
public function showAction(): void | ||
{ | ||
assertType( | ||
'array<int, SaschaEgerer\PhpstanTypo3\Tests\Unit\Type\QueryResultToArrayDynamicReturnTypeExtension\FrontendUserGroup>', | ||
$this->myRepository->findAll()->toArray() | ||
); | ||
|
||
$queryResult = $this->myRepository->findAll(); | ||
$myObjects = $queryResult->toArray(); | ||
assertType( | ||
'array<int, SaschaEgerer\PhpstanTypo3\Tests\Unit\Type\QueryResultToArrayDynamicReturnTypeExtension\FrontendUserGroup>', | ||
$myObjects | ||
); | ||
|
||
assertType( | ||
'array<int, SaschaEgerer\PhpstanTypo3\Tests\Unit\Type\QueryResultToArrayDynamicReturnTypeExtension\FrontendUserGroup>', | ||
$this->myCustomFindAllRepository->findAll()->toArray() | ||
); | ||
|
||
$queryResult = $this->myCustomFindAllRepository->findAll(); | ||
$myObjects = $queryResult->toArray(); | ||
assertType( | ||
'array<int, SaschaEgerer\PhpstanTypo3\Tests\Unit\Type\QueryResultToArrayDynamicReturnTypeExtension\FrontendUserGroup>', | ||
$myObjects | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters