|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the zenstruck/foundry package. |
| 7 | + * |
| 8 | + * (c) Kevin Bond <[email protected]> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Zenstruck\Foundry\Tests\Integration\InMemory; |
| 15 | + |
| 16 | +use Doctrine\ORM\EntityManagerInterface; |
| 17 | +use PHPUnit\Framework\Attributes\RequiresPhpunit; |
| 18 | +use PHPUnit\Framework\Attributes\RequiresPhpunitExtension; |
| 19 | +use PHPUnit\Framework\Attributes\Test; |
| 20 | +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
| 21 | +use Zenstruck\Foundry\Attribute\ResetDatabase; |
| 22 | +use Zenstruck\Foundry\Attribute\WithStory; |
| 23 | +use Zenstruck\Foundry\InMemory\AsInMemoryTest; |
| 24 | +use Zenstruck\Foundry\PHPUnit\FoundryExtension; |
| 25 | +use Zenstruck\Foundry\Test\Factories; |
| 26 | +use Zenstruck\Foundry\Tests\Fixture\Entity\Address; |
| 27 | +use Zenstruck\Foundry\Tests\Fixture\Entity\Category; |
| 28 | +use Zenstruck\Foundry\Tests\Fixture\Entity\Contact; |
| 29 | +use Zenstruck\Foundry\Tests\Fixture\Entity\GenericEntity; |
| 30 | +use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\Address\AddressFactory; |
| 31 | +use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\Category\CategoryFactory; |
| 32 | +use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\Contact\ContactFactory; |
| 33 | +use Zenstruck\Foundry\Tests\Fixture\Factories\Entity\GenericEntityFactory; |
| 34 | +use Zenstruck\Foundry\Tests\Fixture\InMemory\InMemoryAddressRepository; |
| 35 | +use Zenstruck\Foundry\Tests\Fixture\InMemory\InMemoryContactRepository; |
| 36 | +use Zenstruck\Foundry\Tests\Fixture\Stories\EntityStory; |
| 37 | +use Zenstruck\Foundry\Tests\Integration\RequiresORM; |
| 38 | + |
| 39 | +/** |
| 40 | + * @author Nicolas PHILIPPE <[email protected]> |
| 41 | + * @requires PHPUnit >=11.4 |
| 42 | + */ |
| 43 | +#[RequiresPhpunit('>=11.4')] |
| 44 | +#[RequiresPhpunitExtension(FoundryExtension::class)] |
| 45 | +#[AsInMemoryTest] |
| 46 | +#[ResetDatabase] |
| 47 | +final class InMemoryUsingSetUpTest extends KernelTestCase |
| 48 | +{ |
| 49 | + use Factories; |
| 50 | + use RequiresORM; |
| 51 | + |
| 52 | + private InMemoryContactRepository $contactRepository; |
| 53 | + |
| 54 | + private EntityManagerInterface $entityManager; |
| 55 | + private Contact $contact; |
| 56 | + |
| 57 | + protected function setUp(): void |
| 58 | + { |
| 59 | + $this->contactRepository = self::getContainer()->get(InMemoryContactRepository::class); // @phpstan-ignore assign.propertyType |
| 60 | + |
| 61 | + $this->contact = ContactFactory::createOne(); |
| 62 | + |
| 63 | + self::assertCount(1, ContactFactory::repository()); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @test |
| 68 | + */ |
| 69 | + #[Test] |
| 70 | + public function can_access_objects_created_in_set_up_method(): void |
| 71 | + { |
| 72 | + self::assertCount(1, ContactFactory::repository()); |
| 73 | + |
| 74 | + self::assertSame($this->contact, $this->contactRepository->_all()[0]); |
| 75 | + } |
| 76 | +} |
0 commit comments