From 1b42656e0ff0ac81baba2cdad8f1a958c9ab4aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 20 Apr 2021 17:20:57 +0200 Subject: [PATCH 1/6] bootstrap to be run on root bundle --- .env | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ .env.test | 6 +++++ .gitignore | 16 ++++++++++++ .gitmodules | 3 +++ composer.json | 19 ++++++++++++-- phpunit.xml.dist | 38 ++++++++++++++++++++++++++++ tests/app | 1 + 7 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 .env create mode 100644 .env.test create mode 100644 phpunit.xml.dist create mode 160000 tests/app diff --git a/.env b/.env new file mode 100644 index 000000000..619f471ca --- /dev/null +++ b/.env @@ -0,0 +1,64 @@ +## +## Manually dump .env files in .env.local.php with +## `$ composer symfony:dump-env prod` +## + +## Project environment +APP_ENV=dev + +## Enable debug +APP_DEBUG=true + +## Locale +LOCALE=fr + +## Framework secret +APP_SECRET=ThisTokenIsNotSoSecretChangeIt + +## Symfony/swiftmailer +MAILER_TRANSPORT=smtp +MAILER_HOST=smtp +MAILER_PORT=1025 +MAILER_CRYPT= +MAILER_AUTH= +MAILER_USER= +MAILER_PASSWORD= +MAILER_URL=${MAILER_TRANSPORT}://${MAILER_HOST}:${MAILER_PORT}?encryption=${MAILER_CRYPT}&auth_mode=${MAILER_AUTH}&username=${MAILER_USER}&password=${MAILER_PASSWORD} + +## Notifications +NOTIFICATION_HOST=localhost:8001 +NOTIFICATION_FROM_EMAIL=admin@chill.social +NOTIFICATION_FROM_NAME=Chill + +## Gelf +GELF_HOST=gelf +GELF_PORT=12201 + +## OVH OpenStack Storage User/Role +OS_USERNAME= +OS_PASSWORD= +OS_TENANT_ID= +OS_REGION_NAME=GRA +OS_AUTH_URL=https://auth.cloud.ovh.net/v2.0/ + +## OVH OpenStack Storage Container +ASYNC_UPLOAD_TEMP_URL_KEY= +ASYNC_UPLOAD_TEMP_URL_BASE_PATH= +ASYNC_UPLOAD_TEMP_URL_CONTAINER= + +## Redis Cache +REDIS_HOST=redis +REDIS_PORT=6379 +REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT} + +## Twilio +TWILIO_SID=~ +TWILIO_SECRET=~ + +## DOCKER IMAGES REGISTRY +#IMAGE_PHP= +#IMAGE_NGINX= + +## DOCKER IMAGES VERSION +#VERSION=test +VERSION=prod diff --git a/.env.test b/.env.test new file mode 100644 index 000000000..c9ff04a55 --- /dev/null +++ b/.env.test @@ -0,0 +1,6 @@ +# variables for .env environement +# those variables suits for gitlab-ci +# Run tests from root to adapt your own environment +KERNEL_CLASS='App\Kernel' +APP_SECRET='$ecretf0rt3st' +DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres?serverVersion=12&charset=utf8 diff --git a/.gitignore b/.gitignore index dd42f244a..61e7792ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,19 @@ .composer/* composer.phar + +###> symfony/framework-bundle ### +/.env.local +/.env.local.php +/.env.*.local +/config/secrets/prod/prod.decrypt.private.php +/public/bundles/ +/var/ +/vendor/ +/bin/ +###< symfony/framework-bundle ### + +###> phpunit/phpunit ### +/phpunit.xml +.phpunit.result.cache +###< phpunit/phpunit ### diff --git a/.gitmodules b/.gitmodules index 7bc519c88..560ba7980 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "_exts/sphinx-php"] path = _exts/sphinx-php url = https://github.com/fabpot/sphinx-php.git +[submodule "tests/app"] + path = tests/app + url = https://gitlab.com/Chill-projet/chill-app.git diff --git a/composer.json b/composer.json index 50fa4141a..313d60006 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,14 @@ "Chill\\ThirdPartyBundle\\": "src/Bundle/ChillThirdPartyBundle" } }, + "autoload-dev": { + "psr-4": { + "App\\": "tests/app/src/" + } + }, "require": { "champs-libres/async-uploader-bundle": "dev-sf4", "graylog2/gelf-php": "^1.5", - "symfony/flex": "^1.9", "symfony/form": "4.*", "symfony/twig-bundle": "^4.4", "twig/extra-bundle": "^2.12|^3.0", @@ -66,6 +70,17 @@ "symfony/stopwatch": "^5.1", "symfony/web-profiler-bundle": "^5.0", "symfony/var-dumper": "4.*", - "symfony/debug-bundle": "^5.1" + "symfony/debug-bundle": "^5.1", + "symfony/phpunit-bridge": "^5.2" + }, + "scripts": { + "auto-scripts": { + "cache:clear": "symfony-cmd", + "assets:install %PUBLIC_DIR%": "symfony-cmd" + } + }, + "config": { + "vendor-dir": "tests/app/vendor", + "bin-dir": "bin" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 000000000..c005618a8 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + src/Bundle/ChillMainBundle/Tests/ + + + + src/Bundle/ChillPersonBundle/Tests/ + + + + + + + + + + + diff --git a/tests/app b/tests/app new file mode 160000 index 000000000..88bd6e9ea --- /dev/null +++ b/tests/app @@ -0,0 +1 @@ +Subproject commit 88bd6e9ea0aefd258eec9ee6095cdb8cb6eda5b5 From e98a5b88aafd26f0a1df1c7e485a31e9735d97a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 20 Apr 2021 17:21:39 +0200 Subject: [PATCH 2/6] fix some tests in main bundle --- .../Test/PrepareClientTrait.php | 2 +- .../Controller/DefaultControllerTest.php | 13 ------------ .../Tests/Export/ExportManagerTest.php | 21 +++++++------------ 3 files changed, 8 insertions(+), 28 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/Tests/Controller/DefaultControllerTest.php diff --git a/src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php b/src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php index 741f0373b..0ae7c235a 100644 --- a/src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php +++ b/src/Bundle/ChillMainBundle/Test/PrepareClientTrait.php @@ -34,7 +34,7 @@ trait PrepareClientTrait * @return \Symfony\Component\BrowserKit\Client * @throws \LogicException */ - public function getClient( + public function getClientAuthenticated( $username = 'center a_social', $password = 'password' ) { diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/DefaultControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/DefaultControllerTest.php deleted file mode 100644 index 69e7f4e47..000000000 --- a/src/Bundle/ChillMainBundle/Tests/Controller/DefaultControllerTest.php +++ /dev/null @@ -1,13 +0,0 @@ -container = self::$kernel->getContainer(); - $this->prophet = new \Prophecy\Prophet; } @@ -97,7 +90,7 @@ class ExportManagerTest extends KernelTestCase \Symfony\Component\Security\Core\User\UserInterface $user = null ) { - $localUser = $user === NULL ? $this->container->get('doctrine.orm.entity_manager') + $localUser = $user === NULL ? self::$container->get('doctrine.orm.entity_manager') ->getRepository('ChillMainBundle:User') ->findOneBy(array('username' => 'center a_social')) : $user; @@ -106,10 +99,10 @@ class ExportManagerTest extends KernelTestCase $tokenStorage->setToken($token); return new ExportManager( - $logger === NULL ? $this->container->get('logger') : $logger, - $em === NULL ? $this->container->get('doctrine.orm.entity_manager') : $em, - $authorizationChecker === NULL ? $this->container->get('security.authorization_checker') : $authorizationChecker, - $authorizationHelper === NULL ? $this->container->get('chill.main.security.authorization.helper') : $authorizationHelper, + $logger === NULL ? self::$container->get('logger') : $logger, + $em === NULL ? self::$container->get('doctrine.orm.entity_manager') : $em, + $authorizationChecker === NULL ? self::$container->get('security.authorization_checker') : $authorizationChecker, + $authorizationHelper === NULL ? self::$container->get('chill.main.security.authorization.helper') : $authorizationHelper, $tokenStorage) ; } @@ -544,7 +537,7 @@ class ExportManagerTest extends KernelTestCase $export = $this->prophet->prophesize(); $export->willImplement(ExportInterface::class); - $em = $this->container->get('doctrine.orm.entity_manager'); + $em = self::$container->get('doctrine.orm.entity_manager'); $export->initiateQuery( Argument::is(array('foo')), Argument::Type('array'), @@ -627,7 +620,7 @@ class ExportManagerTest extends KernelTestCase //add formatter interface $formatter = new \Chill\MainBundle\Export\Formatter\SpreadSheetFormatter( - $this->container->get('translator'), $exportManager); + self::$container->get('translator'), $exportManager); $exportManager->addFormatter($formatter, 'spreadsheet'); //ob_start(); From a7e49006908e07f1de45269f43bbfeb4c37c388e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 20 Apr 2021 15:32:41 +0000 Subject: [PATCH 3/6] Add .gitlab-ci.yml --- .gitlab-ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..b500e52db --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,46 @@ +# This file is a template, and might need editing before it works on your project. +# Select image from https://hub.docker.com/_/php/ +image: php:7.4 + +# Select what we should cache between builds +cache: + paths: + - vendor/ + +before_script: + - apt-get update -yqq + - apt-get install -yqq git libicu-dev g++ postgresql-server-dev-10 libzip-dev libzip4 unzip libfreetype6-dev libonig-dev `# install oniguruma, required for mbstring` libpng-dev libjpeg62-turbo-dev + # Install PHP extensions + - docker-php-ext-configure gd --with-freetype --with-jpeg + - docker-php-ext-install intl pdo_pgsql mbstring zip bcmath sockets exif + - mkdir /tmp/redis \ + && curl -L -o /tmp/redis/redis.tar.gz https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \ + && cd /tmp/redis \ + && tar xfz /tmp/redis/redis.tar.gz \ + && rm -r /tmp/redis/redis.tar.gz \ + && mkdir -p /usr/src/php/ext/redis \ + && mv /tmp/redis/phpredis-$PHPREDIS_VERSION/* /usr/src/php/ext/redis/. \ + && docker-php-ext-install redis + # Install & enable Xdebug for code coverage reports + # - pecl install xdebug + #- docker-php-ext-enable xdebug + # Install and run Composer + - curl -sS https://getcomposer.org/installer | php + - php composer.phar install + +# Bring in any services we need http://docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-a-service +# See http://docs.gitlab.com/ee/ci/services/README.html for examples. +services: + - postgresql:12 + +# Set any variables we need +variables: + # Configure postgres environment variables (https://hub.docker.com/r/_/postgres/) + POSTGRES_USER=postgres + POSTGRES_PASSWORD=postgres + +# Run our tests +# If Xdebug was installed you can generate a coverage report and see code coverage metrics. +test: + script: + - bin/phpunit --colors=never From 38cba4948bfa75d51678c0384ddcf95c0c3577b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 20 Apr 2021 21:45:06 +0200 Subject: [PATCH 4/6] fix .gitlab-ci definition --- .gitlab-ci.yml | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b500e52db..94601773d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,46 +1,37 @@ -# This file is a template, and might need editing before it works on your project. -# Select image from https://hub.docker.com/_/php/ -image: php:7.4 +--- +image: registry.gitlab.com/chill-projet/chill-app/php-base-image:7.4 # Select what we should cache between builds cache: paths: - - vendor/ + - tests/app/vendor/ before_script: - - apt-get update -yqq - - apt-get install -yqq git libicu-dev g++ postgresql-server-dev-10 libzip-dev libzip4 unzip libfreetype6-dev libonig-dev `# install oniguruma, required for mbstring` libpng-dev libjpeg62-turbo-dev - # Install PHP extensions - - docker-php-ext-configure gd --with-freetype --with-jpeg - - docker-php-ext-install intl pdo_pgsql mbstring zip bcmath sockets exif - - mkdir /tmp/redis \ - && curl -L -o /tmp/redis/redis.tar.gz https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \ - && cd /tmp/redis \ - && tar xfz /tmp/redis/redis.tar.gz \ - && rm -r /tmp/redis/redis.tar.gz \ - && mkdir -p /usr/src/php/ext/redis \ - && mv /tmp/redis/phpredis-$PHPREDIS_VERSION/* /usr/src/php/ext/redis/. \ - && docker-php-ext-install redis - # Install & enable Xdebug for code coverage reports - # - pecl install xdebug - #- docker-php-ext-enable xdebug + # add extensions to postgres + - PGPASSWORD=$POSTGRES_PASSWORD psql -U $POSTGRES_USER -h db -c "CREATE EXTENSION IF NOT EXISTS unaccent; CREATE EXTENSION IF NOT EXISTS pg_trgm;" # Install and run Composer - curl -sS https://getcomposer.org/installer | php - php composer.phar install + - php tests/app/bin/console doctrine:migrations:migrate -n + - php tests/app/bin/console doctrine:fixtures:load -n # Bring in any services we need http://docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-a-service # See http://docs.gitlab.com/ee/ci/services/README.html for examples. services: - - postgresql:12 + - name: postgres:12 + alias: db + - name: redis + alias: redis # Set any variables we need variables: # Configure postgres environment variables (https://hub.docker.com/r/_/postgres/) - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + # fetch the chill-app using git submodules + GIT_SUBMODULE_STRATEGY: recursive # Run our tests -# If Xdebug was installed you can generate a coverage report and see code coverage metrics. test: script: - bin/phpunit --colors=never From d57cfe09c88a5a660cb0b973616fdb4f93360162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 20 Apr 2021 21:45:22 +0200 Subject: [PATCH 5/6] upgrade deps to chill-app --- tests/app | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/app b/tests/app index 88bd6e9ea..9bed30b0d 160000 --- a/tests/app +++ b/tests/app @@ -1 +1 @@ -Subproject commit 88bd6e9ea0aefd258eec9ee6095cdb8cb6eda5b5 +Subproject commit 9bed30b0d45254318f421b84a04527a81417d927 From c6a87f1286bbded9c6b72d347ed0b3aa010cac57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 20 Apr 2021 21:45:50 +0200 Subject: [PATCH 6/6] do not commit composer.lock in library --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 61e7792ed..5cbbc50f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .composer/* composer.phar +composer.lock ###> symfony/framework-bundle ###