diff --git a/Jenkinsfile.review b/Jenkinsfile.review index 1418416af84bf014a01730713c4d6f016f63120e..39e8d3842afc6b78d7086b18803d395f0f7a3f74 100644 --- a/Jenkinsfile.review +++ b/Jenkinsfile.review @@ -68,6 +68,9 @@ pipeline { stage("Unit tests") { steps { dir('appli_sf') { + sh 'bin/console doctrine:schema:drop --force' + sh 'bin/console doctrine:schema:update --force' + sh 'bin/console cache:clear' sh 'bin/phpunit tests/UnitTests' } } @@ -75,10 +78,31 @@ pipeline { stage("Functional tests") { steps { dir('appli_sf') { + sh 'bin/console doctrine:schema:drop --force' + sh 'bin/console doctrine:schema:update --force' + sh 'bin/console cache:clear' sh 'bin/phpunit tests/FunctionalTests' } } } + stage("E2E tests") { + environment { + CYPRESS_BASE_URL = "http://localhost" + } + steps { + dir('appli_sf') { + sh 'bin/console doctrine:schema:drop --force' + sh 'bin/console doctrine:schema:update --force' + sh 'bin/console cache:clear' + sh 'bin/console import:individus imports/individus.csv --use-civil-name=1 --no-interaction --quiet' + sh 'bin/console user:add --username=admin --password=P@ssword12345 --email=test@deptnot.test --name=Administrateur --role=ROLE_ADMIN --no-interaction' + dir('tests/E2E') { + sh 'yarn' + sh ' cypress run' + } + } + } + } } } } diff --git a/appli_sf/tests/FunctionalTests/Controller/DefaultControllerTest.php b/appli_sf/tests/FunctionalTests/Controller/DefaultControllerTest.php index fd23e0a18fa061d881af77c9f85714bc257d99e5..0ac1fe57ade85cab26433cd975068bbb6099fa40 100644 --- a/appli_sf/tests/FunctionalTests/Controller/DefaultControllerTest.php +++ b/appli_sf/tests/FunctionalTests/Controller/DefaultControllerTest.php @@ -2,15 +2,19 @@ namespace App\Tests\FunctionalTests\Controller; +use App\DataFixtures\PersonCivilNameFixtures; +use App\DataFixtures\UserFixtures; use App\Entity\User; use App\Helper\UserHelper; use App\Repository\UserRepository; +use App\Tests\FunctionalTests\TestCase\FixtureAwareWebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; -class DefaultControllerTest extends WebTestCase +class DefaultControllerTest extends FixtureAwareWebTestCase { /** * @var \Doctrine\ORM\EntityManager @@ -33,6 +37,12 @@ class DefaultControllerTest extends WebTestCase $this->entityManager = $kernel->getContainer() ->get('doctrine') ->getManager(); + $encoder = self::$container->get(UserPasswordEncoderInterface::class); + + // Chargement des fixtures + $this->addFixture(new UserFixtures($encoder)); + $this->addFixture(new PersonCivilNameFixtures()); + $this->executeFixtures(); } /** diff --git a/appli_sf/tests/FunctionalTests/TestCase/FixtureAwareWebTestCase.php b/appli_sf/tests/FunctionalTests/TestCase/FixtureAwareWebTestCase.php new file mode 100644 index 0000000000000000000000000000000000000000..27505826cec3397c0ecaa5e4d4f055a104f97063 --- /dev/null +++ b/appli_sf/tests/FunctionalTests/TestCase/FixtureAwareWebTestCase.php @@ -0,0 +1,71 @@ +<?php + +namespace App\Tests\FunctionalTests\TestCase; + +use Doctrine\Common\DataFixtures\Executor\ORMExecutor; +use Doctrine\Common\DataFixtures\FixtureInterface; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; +use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +abstract class FixtureAwareWebTestCase extends WebTestCase +{ + /** + * @var ORMExecutor + */ + private $fixtureExecutor; + + /** + * @var ContainerAwareLoader + */ + private $fixtureLoader; + + public function setUp() + { + self::bootKernel(); + } + + /** + * Adds a new fixture to be loaded. + * + * @param FixtureInterface $fixture + */ + protected function addFixture(FixtureInterface $fixture) + { + $this->getFixtureLoader()->addFixture($fixture); + } + + /** + * Executes all the fixtures that have been loaded so far. + */ + protected function executeFixtures() + { + $this->getFixtureExecutor()->execute($this->getFixtureLoader()->getFixtures()); + } + + /** + * @return ORMExecutor + */ + private function getFixtureExecutor() + { + if (!$this->fixtureExecutor) { + /** @var \Doctrine\ORM\EntityManager $entityManager */ + $entityManager = self::$kernel->getContainer()->get('doctrine')->getManager(); + $this->fixtureExecutor = new ORMExecutor($entityManager, new ORMPurger($entityManager)); + } + + return $this->fixtureExecutor; + } + + /** + * @return ContainerAwareLoader + */ + private function getFixtureLoader() + { + if (!$this->fixtureLoader) { + $this->fixtureLoader = new ContainerAwareLoader(self::$kernel->getContainer()); + } + + return $this->fixtureLoader; + } +} diff --git a/docker/lamp/Dockerfile b/docker/lamp/Dockerfile index bda8445224094bffd7dcebdf7729e542c24f8609..7dd46a7de256e77707f689678a14f471e407002f 100644 --- a/docker/lamp/Dockerfile +++ b/docker/lamp/Dockerfile @@ -16,7 +16,7 @@ RUN groupmod -g ${BOOT2DOCKER_GID} staff ENV DEBIAN_FRONTEND noninteractive RUN set -eux; \ apt-get update; \ - apt-get install -y \ + apt-get install -y --no-install-recommends \ supervisor \ wget \ apache2 \ @@ -31,14 +31,29 @@ RUN set -eux; \ php-zip \ libapache2-mod-php \ curl \ - gnupg2 \ + gnupg \ + ca-certificates \ + libgtk2.0-0 \ + libgtk-3-0 \ + libnotify-dev \ + libgconf-2-4 \ + libnss3 \ + libxss1 \ + libasound2 \ + libxtst6 \ + xauth \ + xvfb \ jq; \ echo "ServerName localhost" >> /etc/apache2/apache2.conf; # Install yarn -RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ - apt-get update && apt-get install -y yarn +ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn +RUN set -eux;\ + apt-get update && apt-get install -y gnupg; \ + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -; \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list; \ + apt-get update; \ + apt-get install -y --no-install-recommends nodejs yarn; # Add image configuration and scripts ADD files/start-apache2.sh /start-apache2.sh @@ -71,6 +86,9 @@ ENV PHP_UPLOAD_MAX_FILESIZE 10M ENV PHP_POST_MAX_SIZE 10M ENV PHP_VERSION 7.2 +# Install Cypress +RUN yarn global add --pure-lockfile cypress@4.11.0; + WORKDIR /app CMD ["/run.sh"] diff --git a/docker/lamp/files/create_mysql_users.sh b/docker/lamp/files/create_mysql_users.sh index b2022c7e927c8b1c642a32dacd5f330bf29f8f3b..f6a08c1808043282fd1d924739626bea68abb313 100755 --- a/docker/lamp/files/create_mysql_users.sh +++ b/docker/lamp/files/create_mysql_users.sh @@ -3,11 +3,19 @@ /usr/bin/mysqld_safe > /dev/null 2>&1 & RET=1 +COUNT_ATTEMPT=0 +NB_MAX_ATTEMPT=15 while [[ RET -ne 0 ]]; do echo "=> Waiting for confirmation of MySQL service startup" sleep 5 mysql -uroot -e "status" > /dev/null 2>&1 RET=$? + (( COUNT_ATTEMPT=COUNT_ATTEMPT+1 )) + echo "=> Tentative $COUNT_ATTEMPT sur $NB_MAX_ATTEMPT" + + if [[ COUNT_ATTEMPT -ge NB_MAX_ATTEMPT ]]; then + exit 5; + fi done mysql -uroot -e "CREATE USER 'notaires'@'localhost' IDENTIFIED BY 'password'" diff --git a/docker/lamp/files/run.sh b/docker/lamp/files/run.sh index e6681ad5c93c3f0f7bb229f08a57ef32898042cf..f884ceea5c8e8dd73d1be0df7f3f7b43943a18d6 100755 --- a/docker/lamp/files/run.sh +++ b/docker/lamp/files/run.sh @@ -82,6 +82,12 @@ if [[ ! -d $VOLUME_HOME/mysql ]]; then echo "=> Done!" /create_mysql_users.sh + RET=$? + + if [[ RET -ne 0 ]]; then + echo "=> Échec du démarrage de la BDD" + exit $? + fi else echo "=> Using an existing volume of MySQL" fi