From eb179b0087d74e69f9a5898edec03cc361dbcf32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20Schl=C3=BC=C3=9Fler?= Date: Wed, 12 Jun 2019 21:27:23 +0200 Subject: [PATCH] Setup Javascript and PHP tests and badges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raimund Schlüßler --- .travis.yml | 124 +++++++++++++++++-- Makefile | 8 ++ README.md | 3 +- package.json | 5 +- phpunit.integration.xml | 22 ++++ phpunit.xml | 22 ++++ tests/bootstrap.php | 12 ++ tests/unit/Controller/PageControllerTest.php | 39 ++++++ 8 files changed, 225 insertions(+), 10 deletions(-) create mode 100644 phpunit.integration.xml create mode 100644 phpunit.xml create mode 100644 tests/bootstrap.php create mode 100644 tests/unit/Controller/PageControllerTest.php diff --git a/.travis.yml b/.travis.yml index a91a398f..75fdef9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,128 @@ dist: trusty -language: php -php: - - 7.0 - - 7.1 - - 7.2 + +addons: + apt: + packages: + - mysql-server-5.6 + - mysql-client-core-5.6 + - mysql-client-5.6 + - libxml2-utils branches: only: - master - /^stable\d+(\.\d+)?$/ +cache: + directories: + - "$HOME/.composer/cache/files" + - "$HOME/.npm" + + +env: + global: + - CORE_BRANCH=master + - PHP_COVERAGE=FALSE + - DB=mysql + +before_install: + - php --info + + # Set up DB + - if [[ "$DB" == 'pgsql' ]]; then createuser -U travis -s oc_autotest; fi + - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e 'create database oc_autotest;'; fi + - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"; fi + - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "GRANT ALL ON oc_autotest.* TO 'oc_autotest'@'localhost';"; fi + - cd .. + - git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b $CORE_BRANCH core + - mv tasks core/apps/ + +before_script: + # Set up core + - php -f core/occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database $DB --database-pass='' + + # Set up app + - php -f core/occ app:enable tasks + + # Enable app twice to check occ errors of registered commands + - php -f core/occ app:enable tasks + - cd core/apps/tasks + + # Run JS tests + - npm install -g npm@latest + - make dev-setup + + # XDebug is only needed if we report coverage -> speeds up other builds + - if [[ "$PHP_COVERAGE" = "FALSE" ]]; + then phpenv config-rm xdebug.ini; + fi + script: - - make - - make test + # Check info.xml schema validity + - wget https://apps.nextcloud.com/schema/apps/info.xsd + - xmllint appinfo/info.xml --schema info.xsd --noout + - rm info.xsd + + # Check PHP syntax errors + - find . -name \*.php -not -path './vendor/*' -exec php -l "{}" \; + + # Run server's app code checker + - php ../../occ app:check-code tasks + + # Test php + - make test-php + - if [[ "$PHP_COVERAGE" = "TRUE" ]]; + then make test-php-coverage; + else make test-php; + fi + +after_success: + - if [[ "$PHP_COVERAGE" = "TRUE" ]]; + then bash <(curl -s https://codecov.io/bash) -cF php; + fi + +after_failure: + - cat ../../data/nextcloud.log matrix: + include: + - stage: build + language: node_js + node_js: + - "10" + before_install: + before_script: + script: + - make + after_failure: + after_success: + + - stage: test + language: node_js + node_js: + - "10" + + before_install: + before_script: + + install: + - npm install -g codecov + + script: + - make dev-setup + - make test + - bash <(curl -s https://codecov.io/bash) -cF javascript; + + after_failure: + after_success: + + - language: php + php: 7.1 + + - language: php + php: 7.2 + + - language: php + php: 7.3 + env: "DB=mysql CORE_BRANCH=master PHP_COVERAGE=TRUE" fast_finish: true diff --git a/Makefile b/Makefile index 56e4bbe4..3ba4ab27 100644 --- a/Makefile +++ b/Makefile @@ -168,3 +168,11 @@ endif .PHONY: test test: $(npm) run test + +test-php: + phpunit -c phpunit.xml + phpunit -c phpunit.integration.xml + +test-php-coverage: + phpunit -c phpunit.xml --coverage-clover=coverage-unit.xml + phpunit -c phpunit.integration.xml --coverage-clover=coverage-integration.xml diff --git a/README.md b/README.md index 0bd0d45f..4a06acb2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Tasks - -[![Build Status](https://scrutinizer-ci.com/g/nextcloud/tasks/badges/build.png?b=master)](https://scrutinizer-ci.com/g/nextcloud/tasks/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nextcloud/tasks/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nextcloud/tasks/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/nextcloud/tasks/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/nextcloud/tasks/?branch=master) +![Downloads](https://img.shields.io/github/downloads/nextcloud/tasks/total.svg) [![Build Status](https://scrutinizer-ci.com/g/nextcloud/tasks/badges/build.png?b=master)](https://scrutinizer-ci.com/g/nextcloud/tasks/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nextcloud/tasks/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nextcloud/tasks/?branch=master) [![Code coverage](https://img.shields.io/codecov/c/github/nextcloud/tasks.svg)](https://codecov.io/gh/nextcloud/tasks/) [![Dependabot status](https://img.shields.io/badge/Dependabot-enabled-brightgreen.svg?longCache=true&logo=dependabot)](https://dependabot.com) **A tasks app for [Nextcloud](http://nextcloud.com). Easily sync tasks from various devices with your Nextcloud and edit them online.** diff --git a/package.json b/package.json index 87581764..c3686461 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,7 @@ "snapshotSerializers": [ "/node_modules/jest-serializer-vue" ], + "coverageDirectory": "./coverage/", "collectCoverage": true, "collectCoverageFrom": [ "/src/**/*.{js,vue}", @@ -117,7 +118,9 @@ "coverageReporters": [ "json", "text", - "html" + "html", + "lcov", + "clover" ] } } diff --git a/phpunit.integration.xml b/phpunit.integration.xml new file mode 100644 index 00000000..5e89f0e9 --- /dev/null +++ b/phpunit.integration.xml @@ -0,0 +1,22 @@ + + + + ./tests/integration + + + + + ./ + + ./l10n + ./templates + ./tests + + + + \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..9c1553a4 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,22 @@ + + + + ./tests/unit + + + + + ./ + + ./l10n + ./templates + ./tests + + + + \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..eb3bddc9 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,12 @@ + + * @copyright Bernhard Posselt 2016 + */ + +require_once __DIR__ . '/../../../tests/bootstrap.php'; diff --git a/tests/unit/Controller/PageControllerTest.php b/tests/unit/Controller/PageControllerTest.php new file mode 100644 index 00000000..e74a934f --- /dev/null +++ b/tests/unit/Controller/PageControllerTest.php @@ -0,0 +1,39 @@ + + * @copyright Hendrik Leppelsack 2015 + */ + +namespace OCA\Tasks\Controller; + +use OCP\AppFramework\Http\TemplateResponse; +use PHPUnit\Framework\TestCase as Base; + + +class PageControllerTest extends Base { + + private $controller; + + public function setUp(): void { + $request = $this->getMockBuilder('OCP\IRequest')->getMock(); + + $this->controller = new PageController( + 'tasks', + $request + ); + } + + + public function testIndex() { + $result = $this->controller->index(); + + $this->assertEquals('main', $result->getTemplateName()); + $this->assertEquals('user', $result->getRenderAs()); + $this->assertTrue($result instanceof TemplateResponse); + } +}