edmondscommerce /
doctrine-static-meta
| 1 | <?php declare(strict_types=1); |
||||
| 2 | |||||
| 3 | namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Factory; |
||||
| 4 | |||||
| 5 | use EdmondsCommerce\DoctrineStaticMeta\AbstractIntegrationTest; |
||||
| 6 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\EmailAddressFieldInterface; |
||||
| 7 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\IsbnFieldInterface; |
||||
| 8 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\EmailAddressFieldTrait; |
||||
| 9 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\IsbnFieldTrait; |
||||
| 10 | |||||
| 11 | class EntityFactoryTest extends AbstractIntegrationTest |
||||
| 12 | { |
||||
| 13 | public const WORK_DIR = AbstractIntegrationTest::VAR_PATH.'/'.self::TEST_TYPE.'/EntityFactoryTest'; |
||||
| 14 | |||||
| 15 | private const TEST_ENTITY_FQN = self::TEST_PROJECT_ROOT_NAMESPACE.'\\Entities\\TestEntity'; |
||||
| 16 | |||||
| 17 | private $entityFqn; |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * @var EntityFactory |
||||
| 21 | */ |
||||
| 22 | private $factory; |
||||
| 23 | |||||
| 24 | private $built = false; |
||||
| 25 | |||||
| 26 | public function setup() |
||||
| 27 | { |
||||
| 28 | parent::setup(); |
||||
| 29 | if (false === $this->built) { |
||||
| 30 | $this->getEntityGenerator()->generateEntity(self::TEST_ENTITY_FQN); |
||||
| 31 | $this->getFieldSetter()->setEntityHasField( |
||||
| 32 | self::TEST_ENTITY_FQN, |
||||
| 33 | IsbnFieldTrait::class |
||||
| 34 | ); |
||||
| 35 | $this->getFieldSetter()->setEntityHasField( |
||||
| 36 | self::TEST_ENTITY_FQN, |
||||
| 37 | EmailAddressFieldTrait::class |
||||
| 38 | ); |
||||
| 39 | $this->built = true; |
||||
| 40 | } |
||||
| 41 | $this->setupCopiedWorkDir(); |
||||
| 42 | $this->entityFqn = $this->getCopiedFqn(self::TEST_ENTITY_FQN); |
||||
| 43 | $this->factory = $this->container->get(EntityFactory::class); |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * @test |
||||
| 48 | * |
||||
| 49 | */ |
||||
| 50 | public function itCanCreateAnEmptyEntity(): void |
||||
| 51 | { |
||||
| 52 | $entity = $this->factory->create($this->entityFqn); |
||||
| 53 | self::assertInstanceOf($this->entityFqn, $entity); |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | /** |
||||
| 57 | * @test |
||||
| 58 | * |
||||
| 59 | */ |
||||
| 60 | public function itThrowsAnExceptionIfThereIsAnInvalidProperty(): void |
||||
| 61 | { |
||||
| 62 | $this->expectException(\InvalidArgumentException::class); |
||||
| 63 | $this->factory->create($this->entityFqn, ['invalidProperty' => true]); |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | /** |
||||
| 67 | * @test |
||||
| 68 | * |
||||
| 69 | */ |
||||
| 70 | public function itCanCreateAnEntityWithValues(): void |
||||
| 71 | { |
||||
| 72 | $values = [ |
||||
| 73 | IsbnFieldInterface::PROP_ISBN => '978-3-16-148410-0', |
||||
| 74 | EmailAddressFieldInterface::PROP_EMAIL_ADDRESS => '[email protected]', |
||||
| 75 | ]; |
||||
| 76 | $entity = $this->factory->create($this->entityFqn, $values); |
||||
| 77 | |||||
| 78 | self::assertSame($entity->getIsbn(), $values[IsbnFieldInterface::PROP_ISBN]); |
||||
|
0 ignored issues
–
show
|
|||||
| 79 | |||||
| 80 | self::assertSame($entity->getEmailAddress(), $values[EmailAddressFieldInterface::PROP_EMAIL_ADDRESS]); |
||||
|
0 ignored issues
–
show
The method
getEmailAddress() does not exist on EdmondsCommerce\Doctrine...erfaces\EntityInterface.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 81 | } |
||||
| 82 | } |
||||
| 83 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.