-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[doctrine] improve repository handler (#353)
- Loading branch information
Showing
6 changed files
with
133 additions
and
48 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
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
53 changes: 53 additions & 0 deletions
53
tests/acceptance/acceptance/doctrine/RepositoryClassWithAttributes.feature
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,53 @@ | ||
@symfony-common | ||
Feature: RepositoryClass using attributes | ||
|
||
Background: | ||
Given I have issue handlers "UndefinedClass,UnusedVariable" suppressed | ||
And I have Symfony plugin enabled | ||
And I have the following code preamble | ||
""" | ||
<?php | ||
namespace RepositoryClass; | ||
use Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine\EntityWithAttributes; | ||
use Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine\EntityWithAttributesRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
""" | ||
|
||
Scenario: The plugin can find correct repository class from entity | ||
Given I have the following code | ||
""" | ||
class SomeService | ||
{ | ||
public function __construct(EntityManagerInterface $entityManager) | ||
{ | ||
/** @psalm-trace $repository */ | ||
$repository = $entityManager->getRepository(EntityWithAttributes::class); | ||
} | ||
} | ||
""" | ||
When I run Psalm | ||
Then I see these errors | ||
| Type | Message | | ||
| Trace | $repository: Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine\EntityWithAttributesRepository | | ||
And I see no other errors | ||
|
||
Scenario: Passing variable class does not crash the plugin | ||
Given I have the following code | ||
""" | ||
class SomeService | ||
{ | ||
public function __construct(EntityManagerInterface $entityManager) | ||
{ | ||
$entity = 'Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine\EntityWithAttributes'; | ||
/** @psalm-trace $repository */ | ||
$repository = $entityManager->getRepository($entity::class); | ||
} | ||
} | ||
""" | ||
When I run Psalm | ||
Then I see these errors | ||
| Type | Message | | ||
| Trace | $repository: Doctrine\ORM\EntityRepository<object> | | ||
| MixedArgument | Argument 1 of Doctrine\ORM\EntityManagerInterface::getRepository cannot be mixed, expecting class-string | | ||
And I see no other errors |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine; | ||
|
||
use Doctrine\ORM\Mapping\Entity; | ||
|
||
#[Entity(repositoryClass: EntityWithAttributesRepository::class)] | ||
class EntityWithAttributes | ||
{ | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
|
||
/** | ||
* @extends EntityRepository<EntityWithAttributes> | ||
*/ | ||
class EntityWithAttributesRepository extends EntityRepository | ||
{ | ||
} |