diff --git a/DoctrineMigrations/Version20180225122246.php b/DoctrineMigrations/Version20180225122246.php new file mode 100644 index 0000000..6f6d7e7 --- /dev/null +++ b/DoctrineMigrations/Version20180225122246.php @@ -0,0 +1,23 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('CREATE TABLE test_entity (id UUID NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))'); + } + + public function down(Schema $schema): void { + $this->throwIrreversibleMigrationException('Down migrations are hell!'); + } +} diff --git a/src/Entity/TestEntity.php b/src/Entity/TestEntity.php new file mode 100644 index 0000000..4583f95 --- /dev/null +++ b/src/Entity/TestEntity.php @@ -0,0 +1,46 @@ +id = Uuid::uuid4(); + $this->data = ''; + } + + public function getId(): UuidInterface { + return $this->id; + } + + public function getData(): string { + return $this->data; + } + + public function setData(string $data): void { + $this->data = $data; + } +} diff --git a/src/Repository/TestEntityRepository.php b/src/Repository/TestEntityRepository.php new file mode 100644 index 0000000..0a8ca0e --- /dev/null +++ b/src/Repository/TestEntityRepository.php @@ -0,0 +1,8 @@ +getContainer()->get('doctrine'); + + assert($doctrine instanceof ManagerRegistry); + + $this->entityManager = $doctrine->getManager(); + + $this->repository = $doctrine->getRepository(TestEntity::class); + } + + public function testGetData(): void { + $data = 'test'; + + $entity = new TestEntity(); + + $id = $entity->getId(); + + $this->assertEmpty($entity->getData()); + + $entity->setData($data); + + $this->assertEquals($data, $entity->getData()); + + $this->entityManager->persist($entity); + $this->entityManager->flush(); + unset($entity); + $this->entityManager->clear(); + + + $entity = $this->repository->find($id); + assert($entity instanceof TestEntity); + + $this->assertEquals($data, $entity->getData()); + + } +}