Commit 565f99d2 authored by Cédric Girardot's avatar Cédric Girardot

Build : Ajoute tests Cypress dans Jenkins

Change-Id: I705baef3e04ac9107756c2b34fcbbe2f62f0a3e8
parent a516d492
......@@ -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'
}
}
}
}
}
}
}
......
......@@ -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();
}
/**
......
<?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;
}
}
......@@ -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"]
......@@ -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'"
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment