From 6548e663ca3ae397cabe33bb7485a5edfeceac61 Mon Sep 17 00:00:00 2001
From: Perreal Guillaume <guillaume.perreal@irstea.fr>
Date: Tue, 20 Aug 2019 14:51:25 +0200
Subject: [PATCH] Ajout d'un Embedded, pour voir.

---
 tests/Fixtures/Entity/Address.php           | 149 ++++++++++++++++++++
 tests/Fixtures/Entity/GeolocalizedTrait.php |  46 ++++++
 tests/Fixtures/Entity/Person.php            |   4 +-
 tests/Fixtures/Entity/Structure.php         |   6 +-
 4 files changed, 203 insertions(+), 2 deletions(-)
 create mode 100644 tests/Fixtures/Entity/Address.php
 create mode 100644 tests/Fixtures/Entity/GeolocalizedTrait.php

diff --git a/tests/Fixtures/Entity/Address.php b/tests/Fixtures/Entity/Address.php
new file mode 100644
index 0000000..33c4e13
--- /dev/null
+++ b/tests/Fixtures/Entity/Address.php
@@ -0,0 +1,149 @@
+<?php declare(strict_types=1);
+/**
+ * Copyright (C) 2019 IRSTEA
+ * All rights reserved.
+ *
+ * @copyright 2019 IRSTEA
+ * @author guillaume.perreal
+ */
+
+
+namespace Irstea\NgModelGeneratorBundle\Tests\Fixtures\Entity;
+
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Class Address
+ *
+ * @ORM\Embeddable()
+ */
+final class Address
+{
+    /**
+     * @var string
+     */
+    private $street;
+
+    /**
+     * @var string
+     */
+    private $postalCode;
+
+    /**
+     * @var string
+     */
+    private $city;
+
+    /**
+     * @var string
+     */
+    private $country;
+
+    /**
+     * Address constructor.
+     * @param string $street
+     * @param string $postalCode
+     * @param string $city
+     * @param string $country
+     */
+    public function __construct(string $street, string $postalCode, string $city, string $country)
+    {
+        $this->street = $street;
+        $this->postalCode = $postalCode;
+        $this->city = $city;
+        $this->country = $country;
+    }
+
+    /**
+     * Get street.
+     *
+     * @return string
+     */
+    public function getStreet(): string
+    {
+        return $this->street;
+    }
+
+    /**
+     * Set street.
+     *
+     * @param string $street
+     */
+    public function setStreet(string $street): void
+    {
+        $this->street = $street;
+    }
+
+    /**
+     * Get postalCode.
+     *
+     * @return string
+     */
+    public function getPostalCode(): string
+    {
+        return $this->postalCode;
+    }
+
+    /**
+     * Set postalCode.
+     *
+     * @param string $postalCode
+     */
+    public function setPostalCode(string $postalCode): void
+    {
+        $this->postalCode = $postalCode;
+    }
+
+    /**
+     * Get city.
+     *
+     * @return string
+     */
+    public function getCity(): string
+    {
+        return $this->city;
+    }
+
+    /**
+     * Set city.
+     *
+     * @param string $city
+     */
+    public function setCity(string $city): void
+    {
+        $this->city = $city;
+    }
+
+    /**
+     * Get country.
+     *
+     * @return string
+     */
+    public function getCountry(): string
+    {
+        return $this->country;
+    }
+
+    /**
+     * Set country.
+     *
+     * @param string $country
+     */
+    public function setCountry(string $country): void
+    {
+        $this->country = $country;
+    }
+
+    /**
+     * @param Address $other
+     * @return bool
+     */
+    public function isEqualTo(Address $other): bool
+    {
+        return $other->street === $this->street
+            && $other->postalCode === $this->postalCode
+            && $other->city === $this->city
+            && $other->country === $this->city;
+    }
+}
diff --git a/tests/Fixtures/Entity/GeolocalizedTrait.php b/tests/Fixtures/Entity/GeolocalizedTrait.php
new file mode 100644
index 0000000..2284d39
--- /dev/null
+++ b/tests/Fixtures/Entity/GeolocalizedTrait.php
@@ -0,0 +1,46 @@
+<?php declare(strict_types=1);
+/**
+ * Copyright (C) 2019 IRSTEA
+ * All rights reserved.
+ *
+ * @copyright 2019 IRSTEA
+ * @author guillaume.perreal
+ */
+
+
+namespace Irstea\NgModelGeneratorBundle\Tests\Fixtures\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+
+/**
+ * Trait GeolocalizedTrait
+ */
+trait GeolocalizedTrait
+{
+    /**
+     * @var Address|null
+     * @ORM\Embedded(class=Address::class)
+     */
+    private $address;
+
+    /**
+     * Get address.
+     *
+     * @return Address|null
+     */
+    public function getAddress(): ?Address
+    {
+        return $this->address;
+    }
+
+    /**
+     * Get address.
+     *
+     * @return Address|null
+     */
+    public function setAddress(?Address $address): void
+    {
+        $this->address = $address;
+    }
+}
diff --git a/tests/Fixtures/Entity/Person.php b/tests/Fixtures/Entity/Person.php
index 55b876e..d2c0a17 100644
--- a/tests/Fixtures/Entity/Person.php
+++ b/tests/Fixtures/Entity/Person.php
@@ -27,6 +27,7 @@ final class Person
 {
     use EntityTrait;
     use TimestampedTrait;
+    use GeolocalizedTrait;
 
     /**
      * @var string
@@ -81,7 +82,7 @@ final class Person
      * @param Structure|null $affectation
      * @throws \Exception
      */
-    public function __construct(string $firstName, string $lastName, string $email = null, string $phoneNumber = null, Structure $affectation = null)
+    public function __construct(string $firstName, string $lastName, string $email = null, string $phoneNumber = null, Structure $affectation = null, Address $address = null)
     {
         $this->createId();
         $this->created();
@@ -94,6 +95,7 @@ final class Person
         $this->managedProjects = new ArrayCollection();
         $this->participeTo = new ArrayCollection();
         $this->affectation = $affectation;
+        $this->address = $address;
     }
 
     /**
diff --git a/tests/Fixtures/Entity/Structure.php b/tests/Fixtures/Entity/Structure.php
index c365351..39b9b36 100644
--- a/tests/Fixtures/Entity/Structure.php
+++ b/tests/Fixtures/Entity/Structure.php
@@ -26,6 +26,7 @@ class Structure
 {
     use EntityTrait;
     use TimestampedTrait;
+    use GeolocalizedTrait;
 
     /**
      * @ORM\Column()
@@ -49,14 +50,17 @@ class Structure
      * Structure constructor.
      * @param string $name
      * @param Structure|null $parent
+     * @param Address|null $address
+     * @throws \Exception
      */
-    public function __construct(string $name, self $parent = null)
+    public function __construct(string $name, self $parent = null, Address $address = null)
     {
         $this->createId();
         $this->created();
 
         $this->name = $name;
         $this->parent = $parent;
+        $this->address = $address;
         $this->children = New ArrayCollection();
     }
 
-- 
GitLab