From cc79cc7cd4292d50b656445041b95140faedf3a8 Mon Sep 17 00:00:00 2001
From: Sebastien Curt <curt.sebastien@gmail.com>
Date: Thu, 25 Nov 2021 12:11:32 +0100
Subject: [PATCH] Add user story application test

---
 .env                                          |  30 +++
 .env.test                                     |   3 +
 composer.json                                 |   2 +
 composer.lock                                 | 228 +++++++++++++++++-
 config/bundles.php                            |   2 +
 .../test/dama_doctrine_test_bundle.yaml       |   4 +
 config/packages/test/web_profiler.yaml        |   6 -
 phpunit.xml.dist                              |   3 +
 .../AppUserRegistrationFixture.php            |  42 ++++
 symfony.lock                                  |  27 +++
 tests/bootstrap.php                           |   2 +-
 11 files changed, 341 insertions(+), 8 deletions(-)
 create mode 100644 config/packages/test/dama_doctrine_test_bundle.yaml
 delete mode 100644 config/packages/test/web_profiler.yaml
 create mode 100644 src/DataFixtures/AppUserRegistrationFixture.php

diff --git a/.env b/.env
index ef1e6c9..af8d447 100644
--- a/.env
+++ b/.env
@@ -30,3 +30,33 @@ APP_SECRET=55ba185719845f708d18a2739b07c44a
 # DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7"
 DATABASE_URL="mysql://rekallfrwsmember:sm4SyZVPu6wpjZfg@mysql:3306/rekallfrwsmember?serverVersion=5.6&charset=utf8"
 ###< doctrine/doctrine-bundle ###
+# Set the docker-compose to use
+# for production with a traefik frontend
+# docker-compose.yml:traefik.yml
+# for development purposes
+# docker-compose.yml:dev.yml
+COMPOSE_FILE=docker-compose.yml
+# local for development or test, prod for production
+ENV=local
+# error, notice, info or debug
+LOG_LEVEL=debug
+
+# Ports to access front and symfony using dev.yml
+MEMOREKALL_MEMBER_PORT=8081
+# Source path
+
+# Symfony Configuration
+APP_DEBUG=1
+
+# If this fails, replace ${MYSQL_DATABASE:-rekallfrwsmember} by rekallfrwsmember
+# and do the same for the other variables
+MYSQL_DATABASE=${MYSQL_DATABASE:-rekallfrwsmember}
+MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}
+MYSQL_USER=${MYSQL_USER:-rekallfrwsmember}
+MYSQL_PASSWORD=${MYSQL_PASSWORD:-sm4SyZVPu6wpjZfg}
+
+BY_PASS_CODE=ed156b9188ecddf0c556d5712f0a84cc
+
+# Use smtp or mail in production
+MAILER_DSN=null://null
+SYMFONY_SECRET=0f817363a768f111a17d2522b8d7e2d72cf738b1
\ No newline at end of file
diff --git a/.env.test b/.env.test
index 9e7162f..d2b7628 100644
--- a/.env.test
+++ b/.env.test
@@ -4,3 +4,6 @@ APP_SECRET='$ecretf0rt3st'
 SYMFONY_DEPRECATIONS_HELPER=999999
 PANTHER_APP_ENV=panther
 PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
+
+DATABASE_URL="mysql://rekallfrwsmember:sm4SyZVPu6wpjZfg@mysql:3306/rekallfrwsmember?serverVersion=5.6&charset=utf8"
+BY_PASS_CODE=ed156b9188ecddf0c556d5712f0a84cc
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 63f8f04..8953a88 100644
--- a/composer.json
+++ b/composer.json
@@ -48,6 +48,8 @@
         "twig/twig": "^2.12|^3.0"
     },
     "require-dev": {
+        "dama/doctrine-test-bundle": "^6.7",
+        "doctrine/doctrine-fixtures-bundle": "^3.4",
         "codeception/module-asserts": "^1.3",
         "codeception/module-phpbrowser": "^1.0",
         "codeception/module-symfony": "^2.0",
diff --git a/composer.lock b/composer.lock
index c80c545..92092cc 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "ce53d22b36fff2dd4dfc9f67b5f8e87a",
+    "content-hash": "e79713ea98e230cc6acefeabf296273d",
     "packages": [
         {
             "name": "composer/package-versions-deprecated",
@@ -7889,6 +7889,232 @@
         }
     ],
     "packages-dev": [
+        {
+            "name": "dama/doctrine-test-bundle",
+            "version": "v6.7.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/dmaicher/doctrine-test-bundle.git",
+                "reference": "2ccf6653ce9c7bf46ae53b2e5bbbb60417d9e3e1"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/dmaicher/doctrine-test-bundle/zipball/2ccf6653ce9c7bf46ae53b2e5bbbb60417d9e3e1",
+                "reference": "2ccf6653ce9c7bf46ae53b2e5bbbb60417d9e3e1",
+                "shasum": ""
+            },
+            "require": {
+                "doctrine/dbal": "^2.9.3 || ^3.0",
+                "doctrine/doctrine-bundle": "^1.11 || ^2.0",
+                "php": "^7.1 || ^8.0",
+                "psr/cache": "^1.0 || ^2.0 || ^3.0",
+                "symfony/cache": "^4.4 || ^5.3 || ^6.0",
+                "symfony/framework-bundle": "^4.4 || ^5.3 || ^6.0"
+            },
+            "require-dev": {
+                "behat/behat": "^3.0",
+                "doctrine/cache": "^1.12",
+                "phpstan/phpstan": "^0.12.85",
+                "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
+                "symfony/phpunit-bridge": "^5.3 || ^6.0",
+                "symfony/process": "^4.4 || ^5.3 || ^6.0",
+                "symfony/yaml": "^4.4 || ^5.3 || ^6.0"
+            },
+            "type": "symfony-bundle",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "6.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "DAMA\\DoctrineTestBundle\\": "src/DAMA/DoctrineTestBundle"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "David Maicher",
+                    "email": "mail@dmaicher.de"
+                }
+            ],
+            "description": "Symfony bundle to isolate doctrine database tests and improve test performance",
+            "keywords": [
+                "doctrine",
+                "isolation",
+                "performance",
+                "symfony",
+                "tests"
+            ],
+            "support": {
+                "issues": "https://github.com/dmaicher/doctrine-test-bundle/issues",
+                "source": "https://github.com/dmaicher/doctrine-test-bundle/tree/v6.7.1"
+            },
+            "time": "2021-11-09T11:55:09+00:00"
+        },
+        {
+            "name": "doctrine/data-fixtures",
+            "version": "1.5.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/doctrine/data-fixtures.git",
+                "reference": "f18adf13f6c81c67a88360dca359ad474523f8e3"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/f18adf13f6c81c67a88360dca359ad474523f8e3",
+                "reference": "f18adf13f6c81c67a88360dca359ad474523f8e3",
+                "shasum": ""
+            },
+            "require": {
+                "doctrine/common": "^2.13|^3.0",
+                "doctrine/persistence": "^1.3.3|^2.0",
+                "php": "^7.2 || ^8.0"
+            },
+            "conflict": {
+                "doctrine/phpcr-odm": "<1.3.0"
+            },
+            "require-dev": {
+                "doctrine/coding-standard": "^9.0",
+                "doctrine/dbal": "^2.5.4 || ^3.0",
+                "doctrine/mongodb-odm": "^1.3.0 || ^2.0.0",
+                "doctrine/orm": "^2.7.0",
+                "ext-sqlite3": "*",
+                "phpunit/phpunit": "^8.0"
+            },
+            "suggest": {
+                "alcaeus/mongo-php-adapter": "For using MongoDB ODM 1.3 with PHP 7 (deprecated)",
+                "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures",
+                "doctrine/orm": "For loading ORM fixtures",
+                "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Jonathan Wage",
+                    "email": "jonwage@gmail.com"
+                }
+            ],
+            "description": "Data Fixtures for all Doctrine Object Managers",
+            "homepage": "http://www.doctrine-project.org",
+            "keywords": [
+                "database"
+            ],
+            "support": {
+                "issues": "https://github.com/doctrine/data-fixtures/issues",
+                "source": "https://github.com/doctrine/data-fixtures/tree/1.5.1"
+            },
+            "funding": [
+                {
+                    "url": "https://www.doctrine-project.org/sponsorship.html",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://www.patreon.com/phpdoctrine",
+                    "type": "patreon"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdata-fixtures",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2021-09-20T21:51:43+00:00"
+        },
+        {
+            "name": "doctrine/doctrine-fixtures-bundle",
+            "version": "3.4.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/doctrine/DoctrineFixturesBundle.git",
+                "reference": "31ba202bebce0b66fe830f49f96228dcdc1503e7"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/31ba202bebce0b66fe830f49f96228dcdc1503e7",
+                "reference": "31ba202bebce0b66fe830f49f96228dcdc1503e7",
+                "shasum": ""
+            },
+            "require": {
+                "doctrine/data-fixtures": "^1.3",
+                "doctrine/doctrine-bundle": "^1.11|^2.0",
+                "doctrine/orm": "^2.6.0",
+                "doctrine/persistence": "^1.3.7|^2.0",
+                "php": "^7.1 || ^8.0",
+                "symfony/config": "^3.4|^4.3|^5.0|^6.0",
+                "symfony/console": "^3.4|^4.3|^5.0|^6.0",
+                "symfony/dependency-injection": "^3.4.47|^4.3|^5.0|^6.0",
+                "symfony/doctrine-bridge": "^3.4|^4.1|^5.0|^6.0",
+                "symfony/http-kernel": "^3.4|^4.3|^5.0|^6.0"
+            },
+            "require-dev": {
+                "doctrine/coding-standard": "^8.0",
+                "phpstan/phpstan": "^0.12.99",
+                "phpunit/phpunit": "^7.4 || ^8.0 || ^9.2",
+                "symfony/phpunit-bridge": "^4.1|^5.0|^6.0",
+                "vimeo/psalm": "^4.10"
+            },
+            "type": "symfony-bundle",
+            "autoload": {
+                "psr-4": {
+                    "Doctrine\\Bundle\\FixturesBundle\\": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Doctrine Project",
+                    "homepage": "http://www.doctrine-project.org"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "http://symfony.com/contributors"
+                }
+            ],
+            "description": "Symfony DoctrineFixturesBundle",
+            "homepage": "http://www.doctrine-project.org",
+            "keywords": [
+                "Fixture",
+                "persistence"
+            ],
+            "support": {
+                "issues": "https://github.com/doctrine/DoctrineFixturesBundle/issues",
+                "source": "https://github.com/doctrine/DoctrineFixturesBundle/tree/3.4.1"
+            },
+            "funding": [
+                {
+                    "url": "https://www.doctrine-project.org/sponsorship.html",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://www.patreon.com/phpdoctrine",
+                    "type": "patreon"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdoctrine-fixtures-bundle",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2021-10-28T05:46:28+00:00"
+        },
         {
             "name": "myclabs/deep-copy",
             "version": "1.10.2",
diff --git a/config/bundles.php b/config/bundles.php
index b8d5412..15fdbcb 100644
--- a/config/bundles.php
+++ b/config/bundles.php
@@ -15,4 +15,6 @@ return [
     SymfonyCasts\Bundle\VerifyEmail\SymfonyCastsVerifyEmailBundle::class => ['all' => true],
     Gregwar\CaptchaBundle\GregwarCaptchaBundle::class => ['all' => true],
     Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
+    DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true],
+    Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
 ];
diff --git a/config/packages/test/dama_doctrine_test_bundle.yaml b/config/packages/test/dama_doctrine_test_bundle.yaml
new file mode 100644
index 0000000..80b0091
--- /dev/null
+++ b/config/packages/test/dama_doctrine_test_bundle.yaml
@@ -0,0 +1,4 @@
+dama_doctrine_test:
+    enable_static_connection: true
+    enable_static_meta_data_cache: true
+    enable_static_query_cache: true
diff --git a/config/packages/test/web_profiler.yaml b/config/packages/test/web_profiler.yaml
deleted file mode 100644
index 03752de..0000000
--- a/config/packages/test/web_profiler.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
-web_profiler:
-    toolbar: false
-    intercept_redirects: false
-
-framework:
-    profiler: { collect: false }
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index af3f147..1eda82f 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -39,4 +39,7 @@
         <extension class="Symfony\Component\Panther\ServerExtension" />
     </extensions>
     -->
+    <extensions>
+        <extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"/>
+    </extensions>
 </phpunit>
diff --git a/src/DataFixtures/AppUserRegistrationFixture.php b/src/DataFixtures/AppUserRegistrationFixture.php
new file mode 100644
index 0000000..7cde893
--- /dev/null
+++ b/src/DataFixtures/AppUserRegistrationFixture.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace App\DataFixtures;
+
+use App\Entity\User;
+use Doctrine\Bundle\FixturesBundle\Fixture;
+use Doctrine\Persistence\ObjectManager;
+use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
+
+class AppUserRegistrationFixture extends Fixture
+{
+    public function __construct(UserPasswordHasherInterface $passwordHasher){
+        $this->passwordHasher = $passwordHasher;
+    }
+
+    public function load(ObjectManager $manager): void
+    {
+        $user = new User();
+        $user->setEmail("notVerified@localhost.com");
+        $user->setFirstName("Test");
+        $user->setLastName("Test LastName");
+        $user->setSalt("");
+        $user->setRoles(["ROLE_USER"]);
+        $password = $this->passwordHasher->hashPassword($user, 'password');
+        $user->setPassword($password);
+        $manager->persist($user);
+        $manager->flush($user);
+
+        $user = new User();
+        $user->setEmail("defaultUser@localhost.com");
+        $user->setFirstName("Test");
+        $user->setLastName("Test LastName");
+        $user->setSalt("");
+        $user->setRoles(["ROLE_USER"]);
+        $user->setIsVerified(true);
+        $password = $this->passwordHasher->hashPassword($user, 'password');
+        $user->setPassword($password);
+        $manager->persist($user);
+
+        $manager->flush();
+    }
+}
diff --git a/symfony.lock b/symfony.lock
index 24d4dff..3456dbf 100644
--- a/symfony.lock
+++ b/symfony.lock
@@ -53,6 +53,18 @@
     "composer/package-versions-deprecated": {
         "version": "1.11.99.4"
     },
+    "dama/doctrine-test-bundle": {
+        "version": "6.7",
+        "recipe": {
+            "repo": "github.com/symfony/recipes-contrib",
+            "branch": "master",
+            "version": "4.0",
+            "ref": "56eaa387b5e48ebcc7c95a893b47dfa1ad51449c"
+        },
+        "files": [
+            "config/packages/test/dama_doctrine_test_bundle.yaml"
+        ]
+    },
     "doctrine/annotations": {
         "version": "1.13",
         "recipe": {
@@ -74,6 +86,9 @@
     "doctrine/common": {
         "version": "3.2.0"
     },
+    "doctrine/data-fixtures": {
+        "version": "1.5.1"
+    },
     "doctrine/dbal": {
         "version": "3.1.4"
     },
@@ -96,6 +111,18 @@
             "src/Entity/.gitignore"
         ]
     },
+    "doctrine/doctrine-fixtures-bundle": {
+        "version": "3.4",
+        "recipe": {
+            "repo": "github.com/symfony/recipes",
+            "branch": "master",
+            "version": "3.0",
+            "ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
+        },
+        "files": [
+            "src/DataFixtures/AppFixtures.php"
+        ]
+    },
     "doctrine/doctrine-migrations-bundle": {
         "version": "3.2",
         "recipe": {
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 469dcce..a7bcaf9 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -7,5 +7,5 @@ require dirname(__DIR__).'/vendor/autoload.php';
 if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) {
     require dirname(__DIR__).'/config/bootstrap.php';
 } elseif (method_exists(Dotenv::class, 'bootEnv')) {
-    (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
+    (new Dotenv())->usePutenv(true)->bootEnv(dirname(__DIR__).'/.env');
 }
-- 
GitLab