Просмотр исходного кода

tec: Fix test suite (#2721)

* Rework the travis file to enable PHPUnit

I realized that unit tests weren't executed on Travis. While working on
this file to enable these tests, I started to think we could simplify
it.

I separated jobs so:

- PHP linter and tests are only performed on PHP 7.3
- Translations are tested separatly so they can fail (it was already the
  case but it was hard to understand the way it was done)
- PHP 5.6 only checks syntax issues
- the last job checks css, js, etc. (it didn't change)

PHPUnit is not executed on 5.6 because only the version 5 is available
while the latest version is the 8 (https://phpunit.de/supported-versions.html).

I think it's easier to read (each job is more explicit) but I'm not a
Travis expert so maybe there's some room for improvements.

* Fix failing tests

The category `_name` regression was introduced in commit b323ed084.

I wasn't able to understand when and why Search tests was wrong.

The rest is about upgrade of PHPUnit.
Marien Fressinaud 6 лет назад
Родитель
Сommit
8f5d8af72f
5 измененных файлов с 66 добавлено и 73 удалено
  1. 42 32
      .travis.yml
  2. 1 1
      app/Models/Category.php
  3. 4 4
      tests/app/Models/SearchTest.php
  4. 19 23
      tests/app/Models/UserQueryTest.php
  5. 0 13
      tests/phpunit.xml

+ 42 - 32
.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_js
       node_js:
         - "node"
-      php:
-        # none
       env:
         - 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
-

+ 1 - 1
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;

+ 4 - 4
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),

+ 19 - 23
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()

+ 0 - 13
tests/phpunit.xml

@@ -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>