Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/serverinfo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2016-07-25 16:43:16 +0300
committerBjoern Schiessle <bjoern@schiessle.org>2016-07-26 11:25:48 +0300
commit6af383023e3ff228e60f9eba125a9125beab8ac4 (patch)
treec63a7a2cf537738a3d2e1be619b37922f86954de
parentb83feb415fbe363d727f70b1dda3b35d7a281973 (diff)
add unit testsmonitoring-api2
-rw-r--r--.scrutinizer.yml6
-rw-r--r--.travis.yml45
-rw-r--r--lib/SystemStatistics.php1
-rw-r--r--tests/bootstrap.php33
-rw-r--r--tests/lib/Controller/ApiControllerTest.php124
-rw-r--r--tests/phpunit.xml26
-rw-r--r--tests/unit/controller/PageControllerTest.php51
7 files changed, 213 insertions, 73 deletions
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
new file mode 100644
index 0000000..fae9daa
--- /dev/null
+++ b/.scrutinizer.yml
@@ -0,0 +1,6 @@
+imports:
+ - javascript
+ - php
+
+tools:
+ external_code_coverage: true
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..dbc0730
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,45 @@
+language: php
+
+php:
+ - 5.4
+ - 5.5
+ - 5.6
+ - 7
+
+env:
+ global:
+ - CORE_BRANCH=master
+ matrix:
+ - DB=sqlite
+
+branches:
+ only:
+ - master
+ - /^stable\d+(\.\d+)?$/
+
+sudo: true
+before_install:
+ - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh
+ - bash ./before_install.sh serverinfo $CORE_BRANCH $DB
+
+script:
+ # Test lint
+ - cd ../server
+ - cd apps/serverinfo
+ - find . -name \*.php -exec php -l "{}" \;
+
+ # Run phpunit tests
+ - cd tests
+ - phpunit --configuration phpunit.xml
+
+ # Create coverage report
+ - wget https://scrutinizer-ci.com/ocular.phar
+ - php ocular.phar code-coverage:upload --format=php-clover clover.xml
+
+matrix:
+ include:
+ - php: 5.4
+ env: DB=mysql
+ - php: 5.4
+ env: DB=pgsql
+ fast_finish: true
diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php
index 520cd9c..6e38f96 100644
--- a/lib/SystemStatistics.php
+++ b/lib/SystemStatistics.php
@@ -52,7 +52,6 @@ class SystemStatistics {
'enable_previews' => $this->config->getSystemValue('enable_previews', true) ? 'yes' : 'no',
'memcache.local' => $this->config->getSystemValue('memcache.local', 'none'),
'memcache.distributed' => $this->config->getSystemValue('memcache.distributed', 'none'),
- 'asset-pipeline.enabled' => $this->config->getSystemValue('asset-pipeline.enabled') ? 'yes' : 'no',
'filelocking.enabled' => $this->config->getSystemValue('filelocking.enabled', true) ? 'yes' : 'no',
'memcache.locking' => $this->config->getSystemValue('memcache.locking', 'none'),
'debug' => $this->config->getSystemValue('debug', false) ? 'yes' : 'no',
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 0e0a443..7a1d136 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,23 +1,14 @@
<?php
-/**
- * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
- *
- * @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/>.
- *
- */
-require_once __DIR__ . '/../../../tests/bootstrap.php';
-require_once __DIR__ . '/../appinfo/autoload.php';
+if (!defined('PHPUNIT_RUN')) {
+ define('PHPUNIT_RUN', 1);
+}
+
+require_once __DIR__ . '/../../../lib/base.php';
+
+if(!class_exists('PHPUnit_Framework_TestCase')) {
+ require_once('PHPUnit/Autoload.php');
+}
+\OC_App::loadApp('serverinfo');
+OC_Hook::clear();
+
diff --git a/tests/lib/Controller/ApiControllerTest.php b/tests/lib/Controller/ApiControllerTest.php
new file mode 100644
index 0000000..29e4457
--- /dev/null
+++ b/tests/lib/Controller/ApiControllerTest.php
@@ -0,0 +1,124 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
+ *
+ * @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\ServerInfo\Tests\lib\Controller;
+
+
+use OCA\ServerInfo\Controller\ApiController;
+use OCA\ServerInfo\DatabaseStatistics;
+use OCA\ServerInfo\PhpStatistics;
+use OCA\ServerInfo\ShareStatistics;
+use OCA\ServerInfo\StorageStatistics;
+use OCA\ServerInfo\SystemStatistics;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\IRequest;
+use Test\TestCase;
+
+class ApiControllerTest extends TestCase {
+
+ /** @var IRequest | \PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+
+ /** @var SystemStatistics | \PHPUnit_Framework_MockObject_MockObject */
+ private $systemStatistics;
+
+ /** @var StorageStatistics | \PHPUnit_Framework_MockObject_MockObject */
+ private $storageStatistics;
+
+ /** @var PhpStatistics | \PHPUnit_Framework_MockObject_MockObject */
+ private $phpStatistics;
+
+ /** @var DatabaseStatistics | \PHPUnit_Framework_MockObject_MockObject */
+ private $databaseStatistics;
+
+ /** @var ShareStatistics | \PHPUnit_Framework_MockObject_MockObject */
+ private $shareStatistics;
+
+ /** @var ApiController */
+ private $instance;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->request = $this->getMockBuilder('OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->systemStatistics = $this->getMockBuilder('OCA\ServerInfo\SystemStatistics')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->storageStatistics = $this->getMockBuilder('OCA\ServerInfo\StorageStatistics')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->phpStatistics = $this->getMockBuilder('OCA\ServerInfo\PhpStatistics')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->databaseStatistics = $this->getMockBuilder('OCA\ServerInfo\DatabaseStatistics')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->shareStatistics = $this->getMockBuilder('OCA\ServerInfo\ShareStatistics')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->instance = new ApiController(
+ 'ServerInfoTest',
+ $this->request,
+ $this->systemStatistics,
+ $this->storageStatistics,
+ $this->phpStatistics,
+ $this->databaseStatistics,
+ $this->shareStatistics
+ );
+ }
+
+ public function testInfo() {
+
+ $this->systemStatistics->expects($this->once())->method('getSystemStatistics')
+ ->willReturn('systemStatistics');
+ $this->storageStatistics->expects($this->once())->method('getStorageStatistics')
+ ->willReturn('storageStatistics');
+ $this->phpStatistics->expects($this->once())->method('getPhpStatistics')
+ ->willReturn('phpStatistics');
+ $this->databaseStatistics->expects($this->once())->method('getDatabaseStatistics')
+ ->willReturn('databaseStatistics');
+ $this->shareStatistics->expects($this->once())->method('getShareStatistics')
+ ->willReturn('shareStatistics');
+
+ $result = $this->instance->info();
+ $this->assertTrue($result instanceof DataResponse);
+ $data = $result->getData();
+ $this->assertTrue(isset($data['data']['nextcloud']));
+ $this->assertTrue(isset($data['data']['server']));
+
+ $this->assertSame('systemStatistics', $data['data']['nextcloud']['system']);
+ $this->assertSame('storageStatistics', $data['data']['nextcloud']['storage']);
+ $this->assertSame('shareStatistics', $data['data']['nextcloud']['shares']);
+ $this->assertSame('unknown', $data['data']['server']['webserver']);
+ $this->assertSame('databaseStatistics', $data['data']['server']['database']);
+ $this->assertSame('phpStatistics', $data['data']['server']['php']);
+ }
+
+}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644
index 0000000..b61d393
--- /dev/null
+++ b/tests/phpunit.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<phpunit bootstrap="bootstrap.php"
+ verbose="true"
+ timeoutForSmallTests="900"
+ timeoutForMediumTests="900"
+ timeoutForLargeTests="900"
+ >
+ <testsuite name='Nextcloud - ServerInfo Tests'>
+ <directory suffix='Test.php'>.</directory>
+ </testsuite>
+ <!-- filters for code coverage -->
+ <filter>
+ <whitelist>
+ <directory suffix=".php">../../serverinfo/lib</directory>
+ <exclude>
+ <directory suffix=".php">../../serverinfo/l10n</directory>
+ <directory suffix=".php">../../serverinfo/lists</directory>
+ <directory suffix=".php">../../serverinfo/tests</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+ <logging>
+ <!-- and this is where your report will be written -->
+ <log type="coverage-clover" target="./clover.xml"/>
+ </logging>
+</phpunit>
diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php
deleted file mode 100644
index a20bcc2..0000000
--- a/tests/unit/controller/PageControllerTest.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
- *
- * @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\ServerInfo\Controller;
-
-use PHPUnit_Framework_TestCase;
-
-use OCP\AppFramework\Http\TemplateResponse;
-
-
-class PageControllerTest extends PHPUnit_Framework_TestCase {
-
- private $controller;
- private $userId = 'john';
-
- public function setUp() {
- $request = $this->getMockBuilder('OCP\IRequest')->getMock();
-
- $this->controller = new PageController(
- 'serverinfo', $request, $this->userId
- );
- }
-
-
- public function testIndex() {
- $result = $this->controller->index();
-
- $this->assertEquals(['user' => 'john'], $result->getParams());
- $this->assertEquals('main', $result->getTemplateName());
- $this->assertTrue($result instanceof TemplateResponse);
- }
-
-}