diff --git a/.drone.yml b/.drone.yml index 454cc40..aa41157 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ workspace: branches: [master, release*, release/*] pipeline: - install-server: + install-core: image: owncloudci/core version: ${OC_VERSION} pull: true @@ -16,7 +16,7 @@ pipeline: db_password: owncloud when: matrix: - NEED_SERVER: true + NEED_CORE: true install-app: image: owncloudci/php:${PHP_VERSION} @@ -85,7 +85,6 @@ pipeline: image: owncloudci/php:${PHP_VERSION} pull: true environment: - - PHP_VERSION=${PHP_VERSION} - COVERAGE=${COVERAGE} commands: - if [ -z "${COVERAGE}" ]; then make test-php-unit; fi @@ -98,8 +97,8 @@ pipeline: image: plugins/codecov:2 secrets: [codecov_token] pull: true - files: - - tests/output/clover.xml + paths: + - tests/output/*.xml when: matrix: COVERAGE: true @@ -107,11 +106,11 @@ pipeline: notify: image: plugins/slack:1 pull: true - secrets: [ slack_webhook ] + secrets: [slack_webhook] channel: builds when: - status: [ failure, changed ] - event: [ push, tag ] + status: [failure, changed] + event: [push, tag] services: mysql: @@ -168,24 +167,28 @@ matrix: - PHP_VERSION: 7.2 OC_VERSION: daily-master-qa TEST_SUITE: codecheck + NEED_CORE: true NEED_SERVER: true NEED_INSTALL_APP: true - PHP_VERSION: 7.2 OC_VERSION: daily-master-qa TEST_SUITE: codecheck-deprecations + NEED_CORE: true NEED_SERVER: true NEED_INSTALL_APP: true - PHP_VERSION: 7.1 OC_VERSION: daily-stable10-qa TEST_SUITE: codecheck + NEED_CORE: true NEED_SERVER: true NEED_INSTALL_APP: true - PHP_VERSION: 7.1 OC_VERSION: daily-stable10-qa TEST_SUITE: codecheck-deprecations + NEED_CORE: true NEED_SERVER: true NEED_INSTALL_APP: true @@ -195,7 +198,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: sqlite DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 7.1 @@ -203,7 +206,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: mysql DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 7.1 @@ -211,7 +214,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: pgsql DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 7.1 @@ -219,7 +222,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: oci DB_NAME: XE - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 7.2 @@ -227,7 +230,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: mysql DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 5.6 @@ -235,7 +238,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: sqlite DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 5.6 @@ -243,7 +246,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: mysql DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 7.0 @@ -251,7 +254,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: mysql DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 7.0 @@ -259,7 +262,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: pgsql DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true COVERAGE: true @@ -268,7 +271,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: oci DB_NAME: XE - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 7.1 @@ -276,7 +279,7 @@ matrix: TEST_SUITE: phpunit DB_TYPE: mysql DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true - PHP_VERSION: 7.2 @@ -284,5 +287,5 @@ matrix: TEST_SUITE: phpunit DB_TYPE: mysql DB_NAME: owncloud - NEED_SERVER: true + NEED_CORE: true NEED_INSTALL_APP: true diff --git a/.gitignore b/.gitignore index 34b6aff..d818d7d 100644 --- a/.gitignore +++ b/.gitignore @@ -50,19 +50,14 @@ nbproject .well-known /.buildpath -# Tests - auto-generated files -/tests/coverage* -/tests/clover.xml -/tests/output/clover.xml -/tests/js/node_modules -/tests/output/ - -build - +/build/ +/l10n/.transifexrc .php_cs.cache # Composer -composer.phar vendor/ vendor-bin/**/composer.lock vendor-bin/**/vendor + +# Tests - auto-generated files +/tests/output diff --git a/.phan/config.php b/.phan/config.php new file mode 100644 index 0000000..6004d6e --- /dev/null +++ b/.phan/config.php @@ -0,0 +1,109 @@ + + * + * @copyright Copyright (c) 2018, ownCloud GmbH + * @license GPL-2.0 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +return [ + + // Supported values: '7.0', '7.1', '7.2', null. + // If this is set to null, + // then Phan assumes the PHP version which is closest to the minor version + // of the php executable used to execute phan. + 'target_php_version' => null, + + // A list of directories that should be parsed for class and + // method information. After excluding the directories + // defined in exclude_analysis_directory_list, the remaining + // files will be statically analyzed for errors. + // + // Thus, both first-party and third-party code being used by + // your application should be included in this list. + 'directory_list' => [ + 'appinfo', + 'lib', + 'vendor', + '../../lib', + '../../core' + ], + + // A directory list that defines files that will be excluded + // from static analysis, but whose class and method + // information should be included. + // + // Generally, you'll want to include the directories for + // third-party code (such as "vendor/") in this list. + // + // n.b.: If you'd like to parse but not analyze 3rd + // party code, directories containing that code + // should be added to both the `directory_list` + // and `exclude_analysis_directory_list` arrays. + 'exclude_analysis_directory_list' => [ + 'vendor', + '../../lib', + '../../core' + ], + + // A regular expression to match files to be excluded + // from parsing and analysis and will not be read at all. + // + // This is useful for excluding groups of test or example + // directories/files, unanalyzable files, or files that + // can't be removed for whatever reason. + // (e.g. '@Test\.php$@', or '@vendor/.*/(tests|Tests)/@') + 'exclude_file_regex' => '@.*/[^/]*(tests|Tests|templates)/@', + + // If true, missing properties will be created when + // they are first seen. If false, we'll report an + // error message. + "allow_missing_properties" => false, + + // If enabled, allow null to be cast as any array-like type. + // This is an incremental step in migrating away from null_casts_as_any_type. + // If null_casts_as_any_type is true, this has no effect. + "null_casts_as_any_type" => true, + + // Backwards Compatibility Checking. This is slow + // and expensive, but you should consider running + // it before upgrading your version of PHP to a + // new version that has backward compatibility + // breaks. + 'backward_compatibility_checks' => false, + + // The initial scan of the function's code block has no + // type information for `$arg`. It isn't until we see + // the call and rescan test()'s code block that we can + // detect that it is actually returning the passed in + // `string` instead of an `int` as declared. + 'quick_mode' => false, + + // The minimum severity level to report on. This can be + // set to Issue::SEVERITY_LOW, Issue::SEVERITY_NORMAL or + // Issue::SEVERITY_CRITICAL. Setting it to only + // critical issues is a good place to start on a big + // sloppy mature code base. + 'minimum_severity' => 5, + + // A set of fully qualified class-names for which + // a call to parent::__construct() is required + 'parent_constructor_required' => [ + ], + +]; \ No newline at end of file diff --git a/Makefile b/Makefile index 3e4a105..3e1178a 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,12 @@ # later. See the COPYING file. # @author Ilja Neumann +SHELL := /bin/bash + +COMPOSER_BIN := $(shell command -v composer 2> /dev/null) +ifndef COMPOSER_BIN + $(error composer is not available on your system, please install composer) +endif app_name=$(notdir $(CURDIR)) project_directory=$(CURDIR)/../$(app_name) @@ -11,8 +17,14 @@ source_package_name=$(source_build_directory)/$(app_name) appstore_build_directory=$(CURDIR)/build/artifacts/appstore appstore_package_name=$(appstore_build_directory)/$(app_name) npm=$(shell which npm 2> /dev/null) -composer=$(shell which composer 2> /dev/null) +# dependency folders (leave empty if not required) +composer_deps= +composer_dev_deps= +nodejs_deps= +bower_deps= + +# signing occ=$(CURDIR)/../../occ private_key=$(HOME)/.owncloud/certificates/$(app_name).key certificate=$(HOME)/.owncloud/certificates/$(app_name).crt @@ -30,6 +42,14 @@ endif PHPUNIT=php -d zend.enable_gc=0 "$(PWD)/../../lib/composer/bin/phpunit" PHPUNITDBG=phpdbg -qrr -d memory_limit=4096M -d zend.enable_gc=0 "$(PWD)/../../lib/composer/bin/phpunit" PHP_CS_FIXER=php -d zend.enable_gc=0 vendor-bin/owncloud-codestyle/vendor/bin/php-cs-fixer +PHAN=php -d zend.enable_gc=0 vendor-bin/phan/vendor/bin/phan +PHPSTAN=php -d zend.enable_gc=0 vendor-bin/phpstan/vendor/bin/phpstan + +.DEFAULT_GOAL := help + +# start with displaying help +help: + @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' # Removes the appstore build .PHONY: clean @@ -107,6 +127,16 @@ test-php-style-fix: ## Run php-cs-fixer and fix code style issues test-php-style-fix: vendor-bin/owncloud-codestyle/vendor $(PHP_CS_FIXER) fix -v --diff --diff-format udiff --allow-risky yes +.PHONY: test-php-phan +test-php-phan: ## Run phan +test-php-phan: vendor-bin/phan/vendor + $(PHAN) --config-file .phan/config.php --require-config-exists + +.PHONY: test-php-phpstan +test-php-phpstan: ## Run phpstan +test-php-phpstan: vendor-bin/phpstan/vendor + $(PHPSTAN) analyse --memory-limit=4G --configuration=./phpstan.neon --no-progress --level=5 appinfo lib + .PHONY: test-codecheck test-codecheck: test-syntax-php $(occ) app:check-code $(app_name) -c private -c strong-comparison @@ -136,3 +166,15 @@ vendor-bin/owncloud-codestyle/vendor: vendor/bamarni/composer-bin-plugin vendor- vendor-bin/owncloud-codestyle/composer.lock: vendor-bin/owncloud-codestyle/composer.json @echo owncloud-codestyle composer.lock is not up to date. + +vendor-bin/phan/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/phan/composer.lock + composer bin phan install --no-progress + +vendor-bin/phan/composer.lock: vendor-bin/phan/composer.json + @echo phan composer.lock is not up to date. + +vendor-bin/phpstan/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/phpstan/composer.lock + composer bin phpstan install --no-progress + +vendor-bin/phpstan/composer.lock: vendor-bin/phpstan/composer.json + @echo phpstan composer.lock is not up to date. diff --git a/lib/BackgroundJob.php b/lib/BackgroundJob.php index f05a264..97ce9a1 100644 --- a/lib/BackgroundJob.php +++ b/lib/BackgroundJob.php @@ -95,7 +95,7 @@ protected function createPublicity($id, $authorId, $timeStamp) { $notification = $this->notificationManager->createNotification(); $notification->setApp('announcementcenter') ->setDateTime($dateTime) - ->setObject('announcement', $id) + ->setObject('announcement', (string) $id) ->setSubject('announced', [$authorId]) ->setLink($this->urlGenerator->linkToRoute('announcementcenter.page.index')); diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 55e6584..5e735c3 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -153,7 +153,7 @@ public function delete($id) { $notification = $this->notificationManager->createNotification(); $notification->setApp('announcementcenter') - ->setObject('announcement', $id); + ->setObject('announcement', (string) $id); $this->notificationManager->markProcessed($notification); return new Response(); diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..fc21bec --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + bootstrap: %currentWorkingDirectory%/../../lib/base.php + ignoreErrors: + diff --git a/phpunit.xml b/phpunit.xml index 9235143..1a92c0d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,12 +2,13 @@ +> - ./tests + ./tests/Unit @@ -21,4 +22,3 @@ - diff --git a/tests/Activity/ExtensionTest.php b/tests/Unit/Activity/ExtensionTest.php similarity index 98% rename from tests/Activity/ExtensionTest.php rename to tests/Unit/Activity/ExtensionTest.php index 275e44e..6e98f87 100644 --- a/tests/Activity/ExtensionTest.php +++ b/tests/Unit/Activity/ExtensionTest.php @@ -19,11 +19,11 @@ * */ -namespace OCA\AnnouncementCenter\Tests\Activity; +namespace OCA\AnnouncementCenter\Tests\Unit\Activity; use OCA\AnnouncementCenter\Activity\Extension; use OCA\AnnouncementCenter\Manager; -use OCA\AnnouncementCenter\Tests\TestCase; +use OCA\AnnouncementCenter\Tests\Unit\TestCase; use OCP\Activity\IExtension; use OCP\Activity\IManager; use OCP\IL10N; diff --git a/tests/AppInfo/AppTest.php b/tests/Unit/AppInfo/AppTest.php similarity index 96% rename from tests/AppInfo/AppTest.php rename to tests/Unit/AppInfo/AppTest.php index ed2605c..f86c15c 100644 --- a/tests/AppInfo/AppTest.php +++ b/tests/Unit/AppInfo/AppTest.php @@ -19,7 +19,7 @@ * */ -namespace OCA\AnnouncementCenter\Tests; +namespace OCA\AnnouncementCenter\Tests\Unit; /** * Class AppTest @@ -94,7 +94,7 @@ public function testAppActivity() { $this->assertInstanceOf('\OCA\AnnouncementCenter\Activity\Extension', $navigation); }); - include(__DIR__ . '/../../appinfo/app.php'); + include(__DIR__ . '/../../../appinfo/app.php'); } public function testAppNotification() { @@ -118,6 +118,6 @@ public function testAppNotification() { $this->assertInternalType('string', $info['name']); }); - include(__DIR__ . '/../../appinfo/app.php'); + include(__DIR__ . '/../../../appinfo/app.php'); } } diff --git a/tests/AppInfo/ApplicationTest.php b/tests/Unit/AppInfo/ApplicationTest.php similarity index 96% rename from tests/AppInfo/ApplicationTest.php rename to tests/Unit/AppInfo/ApplicationTest.php index 707bc8c..ec66114 100644 --- a/tests/AppInfo/ApplicationTest.php +++ b/tests/Unit/AppInfo/ApplicationTest.php @@ -19,10 +19,10 @@ * */ -namespace OCA\AnnouncementCenter\Tests\AppInfo; +namespace OCA\AnnouncementCenter\Tests\Unit\AppInfo; use OCA\AnnouncementCenter\AppInfo\Application; -use OCA\AnnouncementCenter\Tests\TestCase; +use OCA\AnnouncementCenter\Tests\Unit\TestCase; /** * Class ApplicationTest diff --git a/tests/AppInfo/RoutesTest.php b/tests/Unit/AppInfo/RoutesTest.php similarity index 91% rename from tests/AppInfo/RoutesTest.php rename to tests/Unit/AppInfo/RoutesTest.php index 3a1d62d..082c8bc 100644 --- a/tests/AppInfo/RoutesTest.php +++ b/tests/Unit/AppInfo/RoutesTest.php @@ -19,11 +19,11 @@ * */ -namespace OCA\AnnouncementCenter\Tests; +namespace OCA\AnnouncementCenter\Tests\Unit; class RoutesTest extends TestCase { public function testRoutes() { - $routes = include(__DIR__ . '/../../appinfo/routes.php'); + $routes = include(__DIR__ . '/../../../appinfo/routes.php'); $this->assertInternalType('array', $routes); $this->assertCount(1, $routes); $this->assertArrayHasKey('routes', $routes); diff --git a/tests/BackgroundJobTest.php b/tests/Unit/BackgroundJobTest.php similarity index 99% rename from tests/BackgroundJobTest.php rename to tests/Unit/BackgroundJobTest.php index 3f30469..4bed19a 100644 --- a/tests/BackgroundJobTest.php +++ b/tests/Unit/BackgroundJobTest.php @@ -19,11 +19,10 @@ * */ -namespace OCA\AnnouncementCenter\Tests; +namespace OCA\AnnouncementCenter\Tests\Unit; use OCA\AnnouncementCenter\Manager; use OCP\Activity\IManager; -use OCP\AppFramework\Http; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; diff --git a/tests/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php similarity index 98% rename from tests/Controller/PageControllerTest.php rename to tests/Unit/Controller/PageControllerTest.php index 849c93e..be95122 100644 --- a/tests/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -19,10 +19,10 @@ * */ -namespace OCA\AnnouncementCenter\Tests\Controller; +namespace OCA\AnnouncementCenter\Tests\Unit\Controller; use OCA\AnnouncementCenter\Manager; -use OCA\AnnouncementCenter\Tests\TestCase; +use OCA\AnnouncementCenter\Tests\Unit\TestCase; use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; use OCP\IGroupManager; diff --git a/tests/ManagerTest.php b/tests/Unit/ManagerTest.php similarity index 98% rename from tests/ManagerTest.php rename to tests/Unit/ManagerTest.php index 4946c0d..89fe868 100644 --- a/tests/ManagerTest.php +++ b/tests/Unit/ManagerTest.php @@ -19,7 +19,7 @@ * */ -namespace OCA\AnnouncementCenter\Tests; +namespace OCA\AnnouncementCenter\Tests\Unit; use OCA\AnnouncementCenter\Manager; diff --git a/tests/Notification/NotifierTest.php b/tests/Unit/Notification/NotifierTest.php similarity index 98% rename from tests/Notification/NotifierTest.php rename to tests/Unit/Notification/NotifierTest.php index 9e7a89d..d27789c 100644 --- a/tests/Notification/NotifierTest.php +++ b/tests/Unit/Notification/NotifierTest.php @@ -19,11 +19,11 @@ * */ -namespace OCA\AnnouncementCenter\Tests\Notification; +namespace OCA\AnnouncementCenter\Tests\Unit\Notification; use OCA\AnnouncementCenter\Notification\Notifier; use OCA\AnnouncementCenter\Manager; -use OCA\AnnouncementCenter\Tests\TestCase; +use OCA\AnnouncementCenter\Tests\Unit\TestCase; use OCP\IL10N; use OCP\IUserManager; use OCP\L10N\IFactory; diff --git a/tests/TestCase.php b/tests/Unit/TestCase.php similarity index 97% rename from tests/TestCase.php rename to tests/Unit/TestCase.php index 1225ef2..98a49bc 100644 --- a/tests/TestCase.php +++ b/tests/Unit/TestCase.php @@ -19,7 +19,7 @@ * */ -namespace OCA\AnnouncementCenter\Tests; +namespace OCA\AnnouncementCenter\Tests\Unit; abstract class TestCase extends \Test\TestCase { /** @var array */ diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 504ded4..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * @copyright Copyright (c) 2016, Joas Schilling - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see - * - */ - -if (!\defined('PHPUNIT_RUN')) { - \define('PHPUNIT_RUN', 1); -} - -require_once __DIR__.'/../../../lib/base.php'; - -// Fix for "Autoload path not allowed: .../tests/lib/testcase.php" -\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); - -\OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/lib/', true); -\OC::$composerAutoloader->addPsr4('Tests\\', OC::$SERVERROOT . '/tests/', true); - -// Fix for "Autoload path not allowed: .../announcementcenter/tests/testcase.php" -\OC_App::loadApp('announcementcenter'); - -if (!\class_exists('PHPUnit_Framework_TestCase')) { - require_once('PHPUnit/Autoload.php'); -} - -OC_Hook::clear(); diff --git a/vendor-bin/owncloud-codestyle/composer.json b/vendor-bin/owncloud-codestyle/composer.json index 322a204..6497321 100644 --- a/vendor-bin/owncloud-codestyle/composer.json +++ b/vendor-bin/owncloud-codestyle/composer.json @@ -1,9 +1,4 @@ { - "config" : { - "platform": { - "php": "5.6.37" - } - }, "require": { "owncloud/coding-standard": "^1.0" } diff --git a/vendor-bin/phan/composer.json b/vendor-bin/phan/composer.json new file mode 100644 index 0000000..b8f6ca7 --- /dev/null +++ b/vendor-bin/phan/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "phan/phan": "^1.0.0" + } +} diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json new file mode 100644 index 0000000..cb0a623 --- /dev/null +++ b/vendor-bin/phpstan/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "phpstan/phpstan": "^0.10.2" + } +}