diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-10-17 12:58:22 +0300 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-10-17 23:40:50 +0300 |
commit | 10e175cc5eaf5b8f82b266ac2affd9df4cdf6bb8 (patch) | |
tree | 5c640ed85fc2c2009a044c49127bbf6c8b94a08e | |
parent | 8f9cb3db4b85e80ae8f9bc4288f1f894f2b919dc (diff) |
Add first unit tests
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
-rw-r--r-- | .drone.yml | 117 | ||||
-rw-r--r-- | tests/php/UtilTest.php | 45 | ||||
-rw-r--r-- | tests/php/bootstrap.php | 31 | ||||
-rw-r--r-- | tests/php/phpunit.xml | 23 |
4 files changed, 216 insertions, 0 deletions
diff --git a/.drone.yml b/.drone.yml index 6f2baa374..9e66ebba0 100644 --- a/.drone.yml +++ b/.drone.yml @@ -31,9 +31,126 @@ pipeline: when: matrix: TESTS: check-app-compatbility + syntax-php5.6: + image: nextcloudci/php5.6:php5.6-3 + environment: + - APP_NAME=spreed + - CORE_BRANCH=master + - DB=sqlite + commands: + # Pre-setup steps + - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh + - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB + - cd ../server + - composer install + - ./lib/composer/bin/parallel-lint --exclude lib/composer/jakub-onderka/ --exclude 3rdparty/symfony/polyfill-php70/Resources/stubs/ --exclude 3rdparty/patchwork/utf8/src/Patchwork/Utf8/Bootup/ --exclude 3rdparty/paragonie/random_compat/lib/ --exclude lib/composer/composer/autoload_static.php --exclude 3rdparty/composer/autoload_static.php . + when: + matrix: + TESTS: syntax-php5.6 + syntax-php7.0: + image: nextcloudci/php7.0:php7.0-2 + environment: + - APP_NAME=spreed + - CORE_BRANCH=master + - DB=sqlite + commands: + # Pre-setup steps + - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh + - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB + - cd ../server + - composer install + - ./lib/composer/bin/parallel-lint --exclude lib/composer/jakub-onderka/ --exclude 3rdparty/symfony/polyfill-php70/Resources/stubs/ --exclude 3rdparty/patchwork/utf8/src/Patchwork/Utf8/Bootup/ --exclude 3rdparty/paragonie/random_compat/lib/ --exclude lib/composer/composer/autoload_static.php --exclude 3rdparty/composer/autoload_static.php . + when: + matrix: + TESTS: syntax-php7.0 + signed-off-check: + image: nextcloudci/php7.0:php7.0-2 + environment: + - APP_NAME=spreed + - CORE_BRANCH=master + - DB=sqlite + commands: + # Pre-setup steps + - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh + - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB + - cd ../server + - php ./build/signed-off-checker.php + when: + matrix: + TESTS: signed-off-check + php5.6: + image: nextcloudci/php5.6:php5.6-3 + environment: + - APP_NAME=spreed + - CORE_BRANCH=master + - DB=sqlite + commands: + - apt update && apt-get -y install php5-xdebug + + # Pre-setup steps + - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh + - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB + - cd ../server/apps/$APP_NAME + + # Run phpunit tests + - cd tests/php/ + - phpunit --configuration phpunit.xml + + # Create coverage report + - wget https://codecov.io/bash -O codecov.sh + - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 5315d2c6-105e-4462-91d9-d9e7d4a0cf17 -f clover.xml; fi" + - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 5315d2c6-105e-4462-91d9-d9e7d4a0cf17 -f clover.xml; fi" + when: + matrix: + TESTS: php5.6 + php7.0: + image: nextcloudci/php7.0:php7.0-2 + environment: + - APP_NAME=spreed + - CORE_BRANCH=master + - DB=sqlite + commands: + # Pre-setup steps + - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh + - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB + - cd ../server/apps/$APP_NAME + + # Run phpunit tests + - cd tests/php/ + - phpunit --configuration phpunit.xml + when: + matrix: + TESTS: php7.0 + php7.1: + image: nextcloudci/php7.1:php7.1-3 + environment: + - APP_NAME=spreed + - CORE_BRANCH=master + - DB=sqlite + commands: + # FIXME: Move into Docker image + - yum -y install wget + + # Pre-setup steps + - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh + - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB + - cd ../server/apps/$APP_NAME + + # Run phpunit tests + - cd tests/php/ + - phpunit --configuration phpunit.xml + when: + matrix: + TESTS: php7.1 matrix: include: - TESTS: eslint - TESTS: stylelint - TESTS: check-app-compatbility + - TESTS: syntax-php5.6 + - TESTS: syntax-php7.0 + - TESTS: signed-off-check + - TESTS: php5.6 + - TESTS: php7.0 + - TESTS: php7.1 diff --git a/tests/php/UtilTest.php b/tests/php/UtilTest.php new file mode 100644 index 000000000..3dc6ff573 --- /dev/null +++ b/tests/php/UtilTest.php @@ -0,0 +1,45 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCA\Spreed\Tests\Settings; +use OCA\Spreed\Util; +use OCP\IConfig; +use Test\TestCase; + +class UtilTest extends TestCase { + /** @var Util */ + private $util; + + public function setUp() { + parent::setUp(); + $this->util = new Util(); + } + + public function testGetStunServer() { + $config = $this->getMock(IConfig::class); + $config + ->expects($this->once()) + ->method('getAppValue') + ->with('spreed', 'stun_server', 'stun.l.google.com:19302') + ->willReturn('88.198.160.129'); + + $this->assertSame('88.198.160.129', $this->util->getStunServer($config)); + } +} diff --git a/tests/php/bootstrap.php b/tests/php/bootstrap.php new file mode 100644 index 000000000..091b50ad3 --- /dev/null +++ b/tests/php/bootstrap.php @@ -0,0 +1,31 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +if (!defined('PHPUNIT_RUN')) { + define('PHPUNIT_RUN', 1); +} +require_once __DIR__.'/../../../../lib/base.php'; +\OC::$loader->addValidRoot(\OC::$SERVERROOT . '/tests'); +\OC_App::loadApp('spreed'); +if(!class_exists('PHPUnit_Framework_TestCase')) { + require_once('PHPUnit/Autoload.php'); +} +OC_Hook::clear(); diff --git a/tests/php/phpunit.xml b/tests/php/phpunit.xml new file mode 100644 index 000000000..d307fcec0 --- /dev/null +++ b/tests/php/phpunit.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8" ?> +<phpunit bootstrap="bootstrap.php" + strict="true" + verbose="true" + timeoutForSmallTests="900" + timeoutForMediumTests="900" + timeoutForLargeTests="900" +> + <testsuite name='Spreed App Tests'> + <directory suffix='Test.php'>.</directory> + </testsuite> + <!-- filters for code coverage --> + <filter> + <whitelist> + <directory suffix=".php">../../../spreed/appinfo</directory> + <directory suffix=".php">../../../spreed/lib</directory> + </whitelist> + </filter> + <logging> + <!-- and this is where your report will be written --> + <log type="coverage-clover" target="./clover.xml"/> + </logging> +</phpunit> |