zenstruck /
foundry
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Zenstruck\Foundry\Tests\Functional; |
||||
| 4 | |||||
| 5 | use Doctrine\Common\Proxy\Proxy as DoctrineProxy; |
||||
| 6 | use Zenstruck\Foundry\Tests\Fixtures\Entity\Category; |
||||
| 7 | use Zenstruck\Foundry\Tests\Fixtures\Entity\Post; |
||||
| 8 | use Zenstruck\Foundry\Tests\Fixtures\Factories\CategoryFactory; |
||||
| 9 | use Zenstruck\Foundry\Tests\Fixtures\Factories\PostFactory; |
||||
| 10 | use function Zenstruck\Foundry\repository; |
||||
| 11 | |||||
| 12 | /** |
||||
| 13 | * @author Kevin Bond <[email protected]> |
||||
| 14 | */ |
||||
| 15 | final class ORMRepositoryProxyTest extends RepositoryProxyTest |
||||
| 16 | { |
||||
| 17 | protected function setUp(): void |
||||
| 18 | { |
||||
| 19 | if (false === \getenv('DATABASE_URL')) { |
||||
| 20 | self::markTestSkipped('doctrine/orm not enabled.'); |
||||
| 21 | } |
||||
| 22 | } |
||||
| 23 | |||||
| 24 | /** |
||||
| 25 | * @test |
||||
| 26 | */ |
||||
| 27 | public function functions_calls_are_passed_to_underlying_repository(): void |
||||
| 28 | { |
||||
| 29 | $this->assertSame('from custom method', repository(Post::class)->customMethod()); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 30 | } |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * @see https://github.com/zenstruck/foundry/issues/42 |
||||
| 34 | * |
||||
| 35 | * @test |
||||
| 36 | */ |
||||
| 37 | public function doctrine_proxies_are_converted_to_foundry_proxies(): void |
||||
| 38 | { |
||||
| 39 | PostFactory::createOne(['category' => CategoryFactory::new()]); |
||||
| 40 | |||||
| 41 | // clear the em so nothing is tracked |
||||
| 42 | static::$kernel->getContainer()->get('doctrine')->getManager()->clear(); |
||||
| 43 | |||||
| 44 | // load a random Post which causes the em to track a "doctrine proxy" for category |
||||
| 45 | PostFactory::random(); |
||||
| 46 | |||||
| 47 | // load a random Category which should be a "doctrine proxy" |
||||
| 48 | $category = CategoryFactory::random()->object(); |
||||
| 49 | |||||
| 50 | // ensure the category is a "doctrine proxy" and a Category |
||||
| 51 | $this->assertInstanceOf(DoctrineProxy::class, $category); |
||||
| 52 | $this->assertInstanceOf(Category::class, $category); |
||||
| 53 | } |
||||
| 54 | |||||
| 55 | /** |
||||
| 56 | * @test |
||||
| 57 | */ |
||||
| 58 | public function proxy_wrapping_orm_entity_manager_can_order_by_in_find_one_by(): void |
||||
| 59 | { |
||||
| 60 | $categoryA = CategoryFactory::createOne(); |
||||
|
0 ignored issues
–
show
|
|||||
| 61 | $categoryB = CategoryFactory::createOne(); |
||||
|
0 ignored issues
–
show
|
|||||
| 62 | $categoryC = CategoryFactory::createOne(); |
||||
| 63 | |||||
| 64 | $this->assertSame($categoryC->getId(), CategoryFactory::repository()->findOneBy([], ['id' => 'DESC'])->getId()); |
||||
|
0 ignored issues
–
show
The method
getId() does not exist on Zenstruck\Foundry\Proxy. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 65 | } |
||||
| 66 | |||||
| 67 | protected function categoryClass(): string |
||||
| 68 | { |
||||
| 69 | return Category::class; |
||||
| 70 | } |
||||
| 71 | |||||
| 72 | protected function categoryFactoryClass(): string |
||||
| 73 | { |
||||
| 74 | return CategoryFactory::class; |
||||
| 75 | } |
||||
| 76 | } |
||||
| 77 |