diff options
| author | 2019-12-23 11:00:22 +0100 | |
|---|---|---|
| committer | 2019-12-23 11:00:22 +0100 | |
| commit | 8f5d8af72f91e3fa1d47717379570964fe970069 (patch) | |
| tree | ed089f75bfc7070ac1192f6e235387a70f0d0258 /tests | |
| parent | 61fb6f8b86a3fc395dcfa16abab2c94ad3be5b27 (diff) | |
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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/app/Models/SearchTest.php | 8 | ||||
| -rw-r--r-- | tests/app/Models/UserQueryTest.php | 42 | ||||
| -rw-r--r-- | tests/phpunit.xml | 13 |
3 files changed, 23 insertions, 40 deletions
diff --git a/tests/app/Models/SearchTest.php b/tests/app/Models/SearchTest.php index 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.php index 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.xml deleted file mode 100644 index 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> |
