A free, self-hostable news aggregator…
tec: Fix test suite (#2721)
Marien Fressinaud8f5d8af72f91
diff --git a/.travis.yml b/.travis.ymlindex 67889f166..9761090fd 100644--- a/.travis.yml+++ b/.travis.yml@@ -1,39 +1,52 @@language: php-php:- - 5.6- - 7.3-install:- # newest version without https://github.com/squizlabs/PHP_CodeSniffer/pull/1404- - composer global require squizlabs/php_codesniffer+jobs:+ fast_finish: true+ allow_failures:+ - name: "Translations"-script:- - phpenv rehash- - find . -name \*.php -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null 2>php-l-results- - if [ -s php-l-results ]; then cat php-l-results; exit 1; fi- - |- if [[ $VALIDATE_STANDARD == yes ]]; then- COMPOSER_BIN=$(composer global config --absolute bin-dir)- $COMPOSER_BIN/phpcs . --standard=phpcs.xml --warning-severity=0 --extensions=php -p- fi- - |- if [[ $CHECK_TRANSLATION == yes ]]; then- php cli/check.translation.php -r- fi+ include:+ - name: "PHP 7.3 Syntax, linter and tests"+ php: "7.3"+ install:+ - composer global require squizlabs/php_codesniffer+ - composer global require phpunit/phpunit ^7+ script:+ - phpenv rehash+ - find . -name \*.php -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null 2>php-l-results+ - if [ -s php-l-results ]; then cat php-l-results; exit 1; fi+ - COMPOSER_BIN=$(composer global config --absolute bin-dir)+ - $COMPOSER_BIN/phpunit --bootstrap ./tests/bootstrap.php --verbose ./tests+ - $COMPOSER_BIN/phpcs . --standard=phpcs.xml --warning-severity=0 --extensions=php -p-env:- - CHECK_TRANSLATION=no VALIDATE_STANDARD=yes+ - name: "PHP 7.1 Syntax and tests"+ php: "7.1"+ install:+ - composer global require phpunit/phpunit ^7+ script:+ - phpenv rehash+ - find . -name \*.php -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null 2>php-l-results+ - if [ -s php-l-results ]; then cat php-l-results; exit 1; fi+ - COMPOSER_BIN=$(composer global config --absolute bin-dir)+ - $COMPOSER_BIN/phpunit --bootstrap ./tests/bootstrap.php --verbose ./tests-matrix:- fast_finish: true- include:- - php: "7.2"- env: CHECK_TRANSLATION=yes VALIDATE_STANDARD=no- - language: node_js+ - name: "PHP 5.6 Syntax"+ php: "5.6"+ script:+ - phpenv rehash+ - find . -name \*.php -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null 2>php-l-results+ - if [ -s php-l-results ]; then cat php-l-results; exit 1; fi++ - name: "Translations"+ php: "7.3"+ script:+ - phpenv rehash+ - php cli/check.translation.php -r++ - name: "Linter JS, CSS, SCSS, Shell and Docker"+ language: node_jsnode_js:- "node"- php:- # noneenv:- HADOLINT="$HOME/hadolint"install:@@ -46,6 +59,3 @@ matrix:- stylelint "**/*.css"- bash tests/shellchecks.sh- git ls-files --exclude='*Dockerfile*' --ignored | xargs --max-lines=1 "$HADOLINT"- allow_failures:- - env: CHECK_TRANSLATION=yes VALIDATE_STANDARD=no-diff --git a/app/Models/Category.php b/app/Models/Category.phpindex a195c88b3..6956029ad 100644--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -84,7 +84,7 @@ class FreshRSS_Category extends Minz_Model {}}public function _name($value) {- $this->name = trim($value);+ $this->name = mb_strcut(trim($value), 0, 255, 'UTF-8');}public function _isDefault($value) {$this->isDefault = $value;diff --git a/tests/app/Models/SearchTest.php b/tests/app/Models/SearchTest.phpindex 5c0469a48..22070351c 100644--- a/tests/app/Models/SearchTest.php+++ b/tests/app/Models/SearchTest.php@@ -150,8 +150,8 @@ class SearchTest extends PHPUnit\Framework\TestCase {public function provideDateSearch() {return array(array('date:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', '1172754000', '1210519800'),- array('date:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', '1172754000', '1210516199'),- array('date:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172757601', '1210519800'),+ array('date:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', '1172754000', '1210519799'),+ array('date:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172754001', '1210519800'),array('date:2007-03-01/2008-05-11', strtotime('2007-03-01'), strtotime('2008-05-12') - 1),array('date:2007-03-01/', strtotime('2007-03-01'), ''),array('date:/2008-05-11', '', strtotime('2008-05-12') - 1),@@ -176,8 +176,8 @@ class SearchTest extends PHPUnit\Framework\TestCase {public function providePubdateSearch() {return array(array('pubdate:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', '1172754000', '1210519800'),- array('pubdate:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', '1172754000', '1210516199'),- array('pubdate:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172757601', '1210519800'),+ array('pubdate:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', '1172754000', '1210519799'),+ array('pubdate:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172754001', '1210519800'),array('pubdate:2007-03-01/2008-05-11', strtotime('2007-03-01'), strtotime('2008-05-12') - 1),array('pubdate:2007-03-01/', strtotime('2007-03-01'), ''),array('pubdate:/2008-05-11', '', strtotime('2008-05-12') - 1),diff --git a/tests/app/Models/UserQueryTest.php b/tests/app/Models/UserQueryTest.phpindex 1959fd492..c876740e6 100644--- a/tests/app/Models/UserQueryTest.php+++ b/tests/app/Models/UserQueryTest.php@@ -19,24 +19,22 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {$this->assertEquals('favorite', $user_query->getGetType());}- /**- * @expectedException Exceptions/FreshRSS_DAO_Exception- * @expectedExceptionMessage Category DAO is not loaded in UserQuery- */public function test__construct_whenCategoryQueryAndNoDao_throwsException() {- $this->markTestIncomplete('There is a problem with the exception autoloading. We need to make a better autoloading process');+ $this->expectException(FreshRSS_DAO_Exception::class);+ $this->expectExceptionMessage('Category DAO is not loaded in UserQuery');+$query = array('get' => 'c_1');new FreshRSS_UserQuery($query);}public function test__construct_whenCategoryQuery_storesCategoryParameters() {$category_name = 'some category name';- $cat = $this->getMock('FreshRSS_Category');+ $cat = $this->createMock('FreshRSS_Category');$cat->expects($this->atLeastOnce())->method('name')->withAnyParameters()->willReturn($category_name);- $cat_dao = $this->getMock('FreshRSS_Searchable');+ $cat_dao = $this->createMock('FreshRSS_Searchable');$cat_dao->expects($this->atLeastOnce())->method('searchById')->withAnyParameters()@@ -47,24 +45,22 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {$this->assertEquals('category', $user_query->getGetType());}- /**- * @expectedException Exceptions/FreshRSS_DAO_Exception- * @expectedExceptionMessage Feed DAO is not loaded in UserQuery- */public function test__construct_whenFeedQueryAndNoDao_throwsException() {- $this->markTestIncomplete('There is a problem with the exception autoloading. We need to make a better autoloading process');- $query = array('get' => 'c_1');+ $this->expectException(FreshRSS_DAO_Exception::class);+ $this->expectExceptionMessage('Feed DAO is not loaded in UserQuery');++ $query = array('get' => 'f_1');new FreshRSS_UserQuery($query);}public function test__construct_whenFeedQuery_storesFeedParameters() {$feed_name = 'some feed name';- $feed = $this->getMock('FreshRSS_Feed', array(), array('', false));+ $feed = $this->createMock('FreshRSS_Feed', array(), array('', false));$feed->expects($this->atLeastOnce())->method('name')->withAnyParameters()->willReturn($feed_name);- $feed_dao = $this->getMock('FreshRSS_Searchable');+ $feed_dao = $this->createMock('FreshRSS_Searchable');$feed_dao->expects($this->atLeastOnce())->method('searchById')->withAnyParameters()@@ -112,7 +108,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {public function testToArray_whenNoData_returnsEmptyArray() {$user_query = new FreshRSS_UserQuery(array());- $this->assertInternalType('array', $user_query->toArray());+ $this->assertIsIterable($user_query->toArray());$this->assertCount(0, $user_query->toArray());}@@ -126,7 +122,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {'url' => 'some url',);$user_query = new FreshRSS_UserQuery($query);- $this->assertInternalType('array', $user_query->toArray());+ $this->assertIsIterable($user_query->toArray());$this->assertCount(6, $user_query->toArray());$this->assertEquals($query, $user_query->toArray());}@@ -163,8 +159,8 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {}public function testIsDeprecated_whenCategoryExists_returnFalse() {- $cat = $this->getMock('FreshRSS_Category');- $cat_dao = $this->getMock('FreshRSS_Searchable');+ $cat = $this->createMock('FreshRSS_Category');+ $cat_dao = $this->createMock('FreshRSS_Searchable');$cat_dao->expects($this->atLeastOnce())->method('searchById')->withAnyParameters()@@ -175,7 +171,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {}public function testIsDeprecated_whenCategoryDoesNotExist_returnTrue() {- $cat_dao = $this->getMock('FreshRSS_Searchable');+ $cat_dao = $this->createMock('FreshRSS_Searchable');$cat_dao->expects($this->atLeastOnce())->method('searchById')->withAnyParameters()@@ -186,8 +182,8 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {}public function testIsDeprecated_whenFeedExists_returnFalse() {- $feed = $this->getMock('FreshRSS_Feed', array(), array('', false));- $feed_dao = $this->getMock('FreshRSS_Searchable');+ $feed = $this->createMock('FreshRSS_Feed', array(), array('', false));+ $feed_dao = $this->createMock('FreshRSS_Searchable');$feed_dao->expects($this->atLeastOnce())->method('searchById')->withAnyParameters()@@ -198,7 +194,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {}public function testIsDeprecated_whenFeedDoesNotExist_returnTrue() {- $feed_dao = $this->getMock('FreshRSS_Searchable');+ $feed_dao = $this->createMock('FreshRSS_Searchable');$feed_dao->expects($this->atLeastOnce())->method('searchById')->withAnyParameters()diff --git a/tests/phpunit.xml b/tests/phpunit.xmldeleted file mode 100644index cebfd0df8..000000000--- a/tests/phpunit.xml+++ /dev/null@@ -1,13 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>-<phpunit bootstrap="bootstrap.php">- <filter>- <whitelist>- <directory suffix=".php">../app</directory>- </whitelist>- </filter>- <testsuites>- <testsuite name="FreshRSS">- <directory>app</directory>- </testsuite>- </testsuites>-</phpunit>