Skip to content

Commit

Permalink
Merge pull request #141 from sascha-egerer/feature/do-not-try-to-find…
Browse files Browse the repository at this point in the history
…-model-for-abstract-repository

[BUGFIX] Do not try to find model for abstract repository
  • Loading branch information
sascha-egerer committed Nov 27, 2023
2 parents ebfc114 + a2359a3 commit b3f4ca1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Expand Up @@ -32,6 +32,10 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
return false;
}

if ($classReflection->isAbstract()) {
return false;
}

if (strpos($methodName, 'countBy') !== 0) {
return false;
}
Expand Down
Expand Up @@ -34,6 +34,10 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
return false;
}

if ($classReflection->isAbstract()) {
return false;
}

if (strpos($methodName, 'findOneBy') === 0) {
$propertyName = lcfirst(substr($methodName, 9));
} elseif (strpos($methodName, 'findBy') === 0) {
Expand Down
49 changes: 49 additions & 0 deletions tests/Unit/Type/data/repository-stub-files.php
Expand Up @@ -14,6 +14,14 @@ class MyModel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity

}

class ExtendingMyAbstractModel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{

/** @var string */
protected $foo;

}

namespace RepositoryStubFiles\My\Test\Extension\Domain\Repository;

use function PHPStan\Testing\assertType;
Expand Down Expand Up @@ -55,10 +63,51 @@ public function myTests(): void
'int',
$this->countByFoo('a')
);

// call findBy with non-existing model property
assertType(
'*ERROR*',
$this->findByNonexisting('a')
);
assertType(
'*ERROR*',
$this->countByNonexisting('a')
);
}

}

/** @extends \TYPO3\CMS\Extbase\Persistence\Repository<\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface> */
abstract class MyAbstractModelRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{

}

/** @template TEntityClass of \RepositoryStubFiles\My\Test\Extension\Domain\Model\ExtendingMyAbstractModel **/
class ExtendingMyAbstractModelRepository extends MyAbstractModelRepository
{

public function myTests(): void
{
// call findBy with a non existing model property
assertType(
'TYPO3\CMS\Extbase\Persistence\QueryResultInterface<RepositoryStubFiles\My\Test\Extension\Domain\Model\ExtendingMyAbstractModel>',
$this->findByFoo('a')
);
// call findBy with a non existing model property
assertType(
'*ERROR*',
$this->findByNonexisting('a')
);
assertType(
'*ERROR*',
$this->countByNonexisting('a')
);
}

}


class MyModelWithoutExtends extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{

Expand Down

0 comments on commit b3f4ca1

Please sign in to comment.