File tree Expand file tree Collapse file tree 4 files changed +91
-0
lines changed
fixtures/MakeEntityRegenerateEmbeddableObject Expand file tree Collapse file tree 4 files changed +91
-0
lines changed Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff 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 [
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments