From dcd9a67cbe737d1f533b8fa5ae837b6eaf788ccb Mon Sep 17 00:00:00 2001 From: Alexandre Tual Date: Wed, 27 Nov 2019 12:02:43 +0100 Subject: [PATCH 1/2] feat/Customer Entity --- config/doctrine/Customer.orm.yml | 22 +++++ config/routes.yaml | 7 +- fixtures/Customer.yml | 83 +++++++++++++++++++ src/Entity/Customer.php | 30 +++++++ src/Migrations/Version20191127101445.php | 35 ++++++++ src/Repository/CustomerRepository.php | 19 +++++ .../Repository/CustomerRepositoryTest.php | 29 +++++++ .../Repository/PartnerRepositoryTest.php | 53 ++++++++++++ tests/Small/Entity/CustomerTest.php | 24 ++++++ 9 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 config/doctrine/Customer.orm.yml create mode 100644 fixtures/Customer.yml create mode 100644 src/Entity/Customer.php create mode 100644 src/Migrations/Version20191127101445.php create mode 100644 src/Repository/CustomerRepository.php create mode 100644 tests/Medium/Repository/CustomerRepositoryTest.php create mode 100644 tests/Medium/Repository/PartnerRepositoryTest.php create mode 100644 tests/Small/Entity/CustomerTest.php diff --git a/config/doctrine/Customer.orm.yml b/config/doctrine/Customer.orm.yml new file mode 100644 index 0000000..90179ea --- /dev/null +++ b/config/doctrine/Customer.orm.yml @@ -0,0 +1,22 @@ +App\Entity\Customer: + type: entity + table: customer + id: + id: + type: integer + generator: + strategy: AUTO + fields: + name: + type: string + lenght: 255 + createdAt: + type: datetime + gedmo: + timestampable: + on: create + updatedAt: + type: datetime + gedmo: + timestampable: + on: update \ No newline at end of file diff --git a/config/routes.yaml b/config/routes.yaml index a7d5a2f..c3a75ba 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -20,4 +20,9 @@ api_delete_partner: api_create_partner: path: /api/partner controller: App\Controller\PartnerController::create - methods: POST \ No newline at end of file + methods: POST + +api_list_customer: + path: /api/customer + controller: App\Controller\CustomerController::list + methods: GET \ No newline at end of file diff --git a/fixtures/Customer.yml b/fixtures/Customer.yml new file mode 100644 index 0000000..2036571 --- /dev/null +++ b/fixtures/Customer.yml @@ -0,0 +1,83 @@ +App\Entity\Customer: + customer_0: + name: FTV + customer_1: + name: M6 + customer_2: + name: Unimédias + customer_3: + name: Meetic + customer_4: + name: Enedis + customer_5: + name: Lizeo + customer_6: + name: Euronews + customer_7: + name: Le Livre Scolaire + customer_8: + name: Arte + customer_9: + name: Canal + + customer_10: + name: TF1 + customer_11: + name: Ouicar + customer_12: + name: Marcel + customer_13: + name: Yellow La Poste + customer_14: + name: Pichet + customer_15: + name: Carrus + customer_16: + name: Leroy Merlin + customer_17: + name: Decathlon + customer_18: + name: La Redoute + customer_19: + name: Colisweb + customer_20: + name: Accor + customer_21: + name: L'Etudiant + customer_22: + name: Aramis + customer_23: + name: Oui SNCF + customer_24: + name: Voyage SNCF + customer_25: + name: Alltricks + customer_26: + name: Trigone + customer_27: + name: Pages Jaunes + customer_28: + name: Radio France + customer_29: + name: Megalithe.co + customer_30: + name: NRJ + customer_31: + name: Le Monde + customer_32: + name: Dawex + customer_33: + name: Mandarine + customer_34: + name: Kering + customer_35: + name: Volvo + customer_36: + name: Société Générale + customer_37: + name: BNP + customer_38: + name: Sodexo + customer_39: + name: Keplr + customer_40: + name: Booster \ No newline at end of file diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php new file mode 100644 index 0000000..969ed71 --- /dev/null +++ b/src/Entity/Customer.php @@ -0,0 +1,30 @@ +name; + } + + /** + * @param string $name + * @return Customer + */ + public function setName(string $name): Customer + { + $this->name = $name; + return $this; + } +} diff --git a/src/Migrations/Version20191127101445.php b/src/Migrations/Version20191127101445.php new file mode 100644 index 0000000..88437a4 --- /dev/null +++ b/src/Migrations/Version20191127101445.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE customer (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE customer'); + } +} diff --git a/src/Repository/CustomerRepository.php b/src/Repository/CustomerRepository.php new file mode 100644 index 0000000..383585d --- /dev/null +++ b/src/Repository/CustomerRepository.php @@ -0,0 +1,19 @@ +registry = $registry; + } +} \ No newline at end of file diff --git a/tests/Medium/Repository/CustomerRepositoryTest.php b/tests/Medium/Repository/CustomerRepositoryTest.php new file mode 100644 index 0000000..2c94e0f --- /dev/null +++ b/tests/Medium/Repository/CustomerRepositoryTest.php @@ -0,0 +1,29 @@ +setName('M6') + ; + + $actual = self::$kernel->getContainer() + ->get(CustomerRepository::class)->save($entity); + + $this->assertSame($entity, $actual); + + $this->initialState($actual); + } +} diff --git a/tests/Medium/Repository/PartnerRepositoryTest.php b/tests/Medium/Repository/PartnerRepositoryTest.php new file mode 100644 index 0000000..b00ee22 --- /dev/null +++ b/tests/Medium/Repository/PartnerRepositoryTest.php @@ -0,0 +1,53 @@ +setFirstName('Master') + ->setLastName('World') + ->setJob('Leader') + ->setEmail('master.world@link-value.fr') + ->setPhoneNumber('01 02 01 03') + ->setExperience(10) + ->setCustomer('client') + ->setProject('project') + ; + + $actual = self::$kernel->getContainer() + ->get(PartnerRepository::class)->save($entity); + + $this->assertSame($entity, $actual); + + $this->initialState($actual); + } + + public function initialState($entity) + { + $entityManager = self::$kernel->getContainer() + ->get('doctrine') + ->getManager(); + + $entity = $entityManager->merge($entity); + $entityManager->remove($entity); + $entityManager->flush(); + } +} diff --git a/tests/Small/Entity/CustomerTest.php b/tests/Small/Entity/CustomerTest.php new file mode 100644 index 0000000..2edada0 --- /dev/null +++ b/tests/Small/Entity/CustomerTest.php @@ -0,0 +1,24 @@ + Date: Wed, 27 Nov 2019 14:08:53 +0100 Subject: [PATCH 2/2] fixup! feat/Customer Entity --- src/Repository/CustomerRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repository/CustomerRepository.php b/src/Repository/CustomerRepository.php index 383585d..230289a 100644 --- a/src/Repository/CustomerRepository.php +++ b/src/Repository/CustomerRepository.php @@ -16,4 +16,4 @@ public function __construct(ManagerRegistry $registry) parent::__construct($registry, Customer::class); $this->registry = $registry; } -} \ No newline at end of file +}