-
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] fix repository crash when variable classname is used (#280)
- Loading branch information
Showing
6 changed files
with
97 additions
and
19 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
File renamed without changes.
53 changes: 53 additions & 0 deletions
53
tests/acceptance/acceptance/doctrine/RepositoryClass.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 | ||
|
||
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\Foo; | ||
use Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine\FooRepository; | ||
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(Foo::class); | ||
} | ||
} | ||
""" | ||
When I run Psalm | ||
Then I see these errors | ||
| Type | Message | | ||
| Trace | $repository: Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine\FooRepository | | ||
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\Foo'; | ||
/** @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
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\Mapping\Entity; | ||
|
||
/** | ||
* @Entity(repositoryClass=FooRepository::class) | ||
*/ | ||
class Foo | ||
{ | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\SymfonyPsalmPlugin\Tests\Fixture\Doctrine; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
|
||
class FooRepository extends EntityRepository | ||
{ | ||
} |