From 8f5d8af72f91e3fa1d47717379570964fe970069 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 23 Dec 2019 11:00:22 +0100 Subject: 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. --- tests/app/Models/UserQueryTest.php | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'tests/app/Models/UserQueryTest.php') 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() -- cgit v1.2.3