From 3d393e571923f62a32f92bb10f01eceabad821e8 Mon Sep 17 00:00:00 2001 From: ruan <2369127-ruany@users.noreply.gitlab.com> Date: Thu, 6 Aug 2020 15:45:58 +0200 Subject: [PATCH] [CI] Set up PHPUnit and first unit test --- .gitignore | 2 ++ .gitlab-ci.yml | 15 ++++++++------- inc/test/composer.json | 10 ++++++++++ inc/test/php/LangTest.php | 23 +++++++++++++++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 inc/test/composer.json create mode 100644 inc/test/php/LangTest.php diff --git a/.gitignore b/.gitignore index da11dba..89f4292 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea litebans-php.iml +inc/test/vendor +inc/test/composer.lock diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0653acc..241168a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,10 +1,9 @@ -# 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:latest # Select what we should cache between builds cache: paths: + - inc/test/vendor/ - vendor/ before_script: @@ -23,16 +22,18 @@ before_script: - pecl install xdebug - docker-php-ext-enable xdebug # Install and run Composer - #- curl -sS https://getcomposer.org/installer | php - #- php composer.phar install + - curl -sS https://getcomposer.org/installer | php + - php composer.phar install + - php composer.phar require --dev phpunit/phpunit ^9 # 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/ce/ci/services/README.html for examples. -services: - - mysql:5.7 +services: [] +# - mysql:5.7 # Set any variables we need variables: + COMPOSER: 'inc/test/composer.json' # Configure mysql environment variables (https://hub.docker.com/r/_/mysql/) MYSQL_DATABASE: mysql_database MYSQL_ROOT_PASSWORD: mysql_strong_password @@ -41,4 +42,4 @@ variables: # If Xdebug was installed you can generate a coverage report and see code coverage metrics. test: script: - - vendor/bin/phpunit --configuration phpunit.xml --coverage-text --colors=never + - ./vendor/bin/phpunit inc/test/php diff --git a/inc/test/composer.json b/inc/test/composer.json new file mode 100644 index 0000000..b21d5bf --- /dev/null +++ b/inc/test/composer.json @@ -0,0 +1,10 @@ +{ + "autoload": { + "classmap": [ + "inc/" + ] + }, + "require-dev": { + "phpunit/phpunit": "^9" + } +} diff --git a/inc/test/php/LangTest.php b/inc/test/php/LangTest.php new file mode 100644 index 0000000..82c7d8d --- /dev/null +++ b/inc/test/php/LangTest.php @@ -0,0 +1,23 @@ +assertTrue(is_array($instance->array)); + + $count = sizeof($instance->array); + $this->assertTrue($count > 0); + + echo "Language $lang_class is valid. $count messages defined."; + } + } +}