Skip to content

Commit 84e2f58

Browse files
committed
Add small test to embeddable test
1 parent 5c48add commit 84e2f58

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"doctrine/doctrine-bundle": "^1.8",
2929
"doctrine/orm": "^2.3",
3030
"friendsofphp/php-cs-fixer": "^2.8",
31+
"moneyphp/money": "^3.2",
3132
"symfony/phpunit-bridge": "^3.4|^4.0",
3233
"symfony/process": "^3.4|^4.0",
3334
"symfony/yaml": "^3.4|^4.0"

tests/Maker/FunctionalTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,18 @@ public function getCommandEntityTests()
11361136
->setRequiredPhpVersion(70100)
11371137
];
11381138

1139+
yield 'entity_regenerate_embeddable_object' => [MakerTestDetails::createTest(
1140+
$this->getMakerInstance(MakeEntity::class),
1141+
[
1142+
// namespace: use default App\Entity
1143+
'',
1144+
])
1145+
->setArgumentsString('--regenerate')
1146+
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRegenerateEmbeddableObject')
1147+
->configureDatabase()
1148+
->setRequiredPhpVersion(70100)
1149+
];
1150+
11391151
yield 'entity_regenerate_embeddable' => [MakerTestDetails::createTest(
11401152
$this->getMakerInstance(MakeEntity::class),
11411153
[
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Entity()
9+
*/
10+
class Invoice
11+
{
12+
/**
13+
* @ORM\Column(name="id", type="integer")
14+
* @ORM\Id
15+
* @ORM\GeneratedValue(strategy="AUTO")
16+
*/
17+
private $id;
18+
19+
/**
20+
* @ORM\Column(name="title", type="string", length=255)
21+
*/
22+
private $title;
23+
24+
/**
25+
* @ORM\Embedded(class="Money\Money")
26+
*/
27+
private $total;
28+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace App\Tests;
4+
5+
use App\Entity\Invoice;
6+
use Money\Currency;
7+
use Money\Money;
8+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
9+
use Doctrine\ORM\EntityManager;
10+
use App\Entity\Food;
11+
use App\Entity\Recipe;
12+
13+
class GeneratedEntityTest extends KernelTestCase
14+
{
15+
public function testGeneratedEntity()
16+
{
17+
self::bootKernel();
18+
/** @var EntityManager $em */
19+
$em = self::$kernel->getContainer()
20+
->get('doctrine')
21+
->getManager();
22+
23+
$em->createQuery('DELETE FROM App\\Entity\\Invoice i')->execute();
24+
25+
$invoice = new Invoice();
26+
// check that the constructor was instantiated properly
27+
$this->assertInstanceOf(Money::class, $invoice->getTotal());
28+
// fields should now have setters
29+
$invoice->setTitle('Borscht');
30+
31+
$total = new Money(100, new Currency('EUR'));
32+
$invoice->setTotal($total);
33+
34+
$em->persist($invoice);
35+
36+
$em->flush();
37+
$em->refresh($invoice);
38+
39+
/** @var Invoice[] $actualInvoice */
40+
$actualInvoice = $em->getRepository(Invoice::class)
41+
->findAll();
42+
43+
$this->assertcount(1, $actualInvoice);
44+
45+
/** @var Money $actualTotal */
46+
$actualTotal = $actualInvoice[0]->getTotal();
47+
48+
$this->assertInstanceOf(Money::class, $actualTotal);
49+
}
50+
}

0 commit comments

Comments
 (0)