From 332e5c639810543a003a2364ad4dfcf4069b394e Mon Sep 17 00:00:00 2001 From: Xenofon Spafaridis Date: Wed, 4 Dec 2019 12:59:30 +0200 Subject: [PATCH] Upgrade PHPUnit --- .travis.yml | 4 +- composer.json | 6 +- phpunit.xml | 2 +- tests/src/ControllerTest.php | 61 ------- tests/src/Controllers/DELETETest.php | 31 ++-- tests/src/Controllers/GETByIdTest.php | 31 ++-- tests/src/Controllers/GETTest.php | 21 +-- tests/src/Controllers/PATCHTest.php | 29 ++-- tests/src/Controllers/POSTTest.php | 45 ++--- tests/src/Controllers/RelationshipsTest.php | 31 ++-- tests/src/FieldsTest.php | 98 +++++------ tests/src/FilterAttributeTest.php | 15 +- tests/src/FilterJSONAttributeTest.php | 11 +- tests/src/FilterTest.php | 177 +++++++------------- tests/src/Model/CacheTest.php | 11 +- tests/src/Model/DirectivesTest.php | 19 ++- tests/src/Model/GetTest.php | 27 +-- tests/src/Model/RelationshipTest.php | 5 +- tests/src/ModelTest.php | 17 +- tests/src/PageTest.php | 15 +- tests/src/RelationshipTest.php | 17 +- tests/src/ResourceTest.php | 39 ++--- tests/src/SortTest.php | 45 +++-- tests/src/ValidationModelTest.php | 5 +- tests/src/Viewers/JSONAPITest.php | 7 +- 25 files changed, 293 insertions(+), 476 deletions(-) delete mode 100644 tests/src/ControllerTest.php diff --git a/.travis.yml b/.travis.yml index e1b5c20..e7d62d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: php php: - - 7.0 + - 7.2 + - 7.3 + install: - composer self-update - composer install --no-interaction --dev diff --git a/composer.json b/composer.json index 5f8bff3..f5302f7 100644 --- a/composer.json +++ b/composer.json @@ -10,14 +10,14 @@ "homepage": "https://nohponex.gr" }], "require": { - "php": ">=7", + "php": "^7.2 | ^8.0.0", "phramework/phramework": "1.*", "ext-json": "*", "phramework/util": "^0.0.0" }, "require-dev": { - "squizlabs/php_codesniffer": "*", - "phpunit/phpunit": "5.*", + "squizlabs/php_codesniffer": "^3.5.3", + "phpunit/phpunit": "^8.4.3", "apigen/apigen": "^4.1", "satooshi/php-coveralls": "^2.0.0", "codacy/coverage": "^1.0" diff --git a/phpunit.xml b/phpunit.xml index 8abaa88..f1be68c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -13,7 +13,7 @@ - + diff --git a/tests/src/ControllerTest.php b/tests/src/ControllerTest.php deleted file mode 100644 index 455bcb8..0000000 --- a/tests/src/ControllerTest.php +++ /dev/null @@ -1,61 +0,0 @@ - - */ -class ControllerTest extends \PHPUnit_Framework_TestCase -{ - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * @todo update base - */ - protected function setUp() - { - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - public function testExtends() - { - $controller = \Phramework\JSONAPI\Controller::class; - - $classes = [ - \Phramework\JSONAPI\Controller\Base::class, - \Phramework\JSONAPI\Controller\GET::class - ]; - - /*foreach ($classes as $class) { - $this->assertTrue(is_a( - $controller, - $class, - true - )); - }*/ - } -} diff --git a/tests/src/Controllers/DELETETest.php b/tests/src/Controllers/DELETETest.php index ebb8541..693fa4e 100644 --- a/tests/src/Controllers/DELETETest.php +++ b/tests/src/Controllers/DELETETest.php @@ -17,13 +17,14 @@ namespace Phramework\JSONAPI\Controller; use \Phramework\Phramework; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Phramework\JSONAPI\Controller\DELETE * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class DELETETest extends \PHPUnit_Framework_TestCase +class DELETETest extends TestCase { /** * @var Phramework @@ -36,14 +37,6 @@ class DELETETest extends \PHPUnit_Framework_TestCase */ protected $parameters; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - } - protected function prepare() { $_SERVER['REQUEST_URI'] = '/article/1'; @@ -70,7 +63,7 @@ function ( /** * @covers ::handleDELETE */ - public function testDELETESuccess() + public function testDELETESuccess(): void { $this->prepare(); @@ -80,15 +73,15 @@ public function testDELETESuccess() $params = $this->parameters; return; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('links', $params); $this->assertObjectHasAttribute('data', $params); - $this->assertInternalType('object', $params->data); + $this->assertIsObject($params->data); $this->assertObjectHasAttribute('id', $params->data); - $this->assertInternalType('string', $params->data->id); + $this->assertIsString($params->data->id); $id = $params->data->id; @@ -97,7 +90,7 @@ public function testDELETESuccess() $article = \Phramework\JSONAPI\APP\Models\Article::getById($id); - $this->assertInternalType('object', $article); + $this->assertIsObject($article); $this->assertObjectHasAttribute('attributes', $article); $this->assertObjectHasAttribute('relationships', $article); @@ -107,7 +100,7 @@ public function testDELETESuccess() $this->assertObjectHasAttribute('creator', $relationships); $this->assertObjectHasAttribute('tag', $relationships); - $this->assertInternalType('object', $relationships->creator->data); + $this->assertIsObject($relationships->creator->data); $this->assertInternalType('array', $relationships->tag->data); $this->assertEquals('1', $relationships->creator->data->id); @@ -120,7 +113,7 @@ public function testDELETESuccess() * Cause a not found exception, at to TYPE_TO_ONE relationship * @covers \Phramework\JSONAPI\Controller\DELETE::handleDELETE */ - public function testDELETEFailureToOne() + public function testDELETEFailureToOne(): void { $this->prepare(); @@ -132,7 +125,7 @@ public function testDELETEFailureToOne() //Access parameters written by invoked phramework's viewer $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( @@ -146,7 +139,7 @@ public function testDELETEFailureToOne() * Cause a not found exception, at to TYPE_TO_MANY relationship * @covers \Phramework\JSONAPI\Controller\DELETE::handleDELETE */ - public function testDELETEFailureToMany() + public function testDELETEFailureToMany(): void { return; $this->prepare(); @@ -159,7 +152,7 @@ public function testDELETEFailureToMany() //Access parameters written by invoked phramework's viewer $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( diff --git a/tests/src/Controllers/GETByIdTest.php b/tests/src/Controllers/GETByIdTest.php index e78a716..962b9de 100644 --- a/tests/src/Controllers/GETByIdTest.php +++ b/tests/src/Controllers/GETByIdTest.php @@ -17,13 +17,14 @@ namespace Phramework\JSONAPI\Controller; use \Phramework\Phramework; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Phramework\JSONAPI\Controller\GETById * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class GETByIdTest extends \PHPUnit_Framework_TestCase +class GETByIdTest extends TestCase { /** * @var Phramework @@ -36,15 +37,7 @@ class GETByIdTest extends \PHPUnit_Framework_TestCase */ protected $parameters; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - } - - protected function prepare() + protected function prepare(): void { $_SERVER['REQUEST_URI'] = 'article/1'; $_SERVER['REQUEST_METHOD'] = Phramework::METHOD_GET; @@ -71,7 +64,7 @@ function ( /** * @covers ::handleGETById */ - public function testGETByIdSuccess() + public function testGETByIdSuccess(): void { $this->prepare(); @@ -81,12 +74,12 @@ public function testGETByIdSuccess() $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('links', $params); $this->assertObjectHasAttribute('data', $params); - $this->assertInternalType('object', $params->data); + $this->assertIsObject($params->data); $this->assertObjectHasAttribute('id', $params->data); return; @@ -100,7 +93,7 @@ public function testGETByIdSuccess() $article = \Phramework\JSONAPI\APP\Models\Article::getById($id); - $this->assertInternalType('object', $article); + $this->assertIsObject($article); $this->assertObjectHasAttribute('attributes', $article); $this->assertObjectHasAttribute('relationships', $article); @@ -110,7 +103,7 @@ public function testGETByIdSuccess() $this->assertObjectHasAttribute('creator', $relationships); $this->assertObjectHasAttribute('tag', $relationships); - $this->assertInternalType('object', $relationships->creator->data); + $this->assertIsObject($relationships->creator->data); $this->assertInternalType('array', $relationships->tag->data); $this->assertEquals('1', $relationships->creator->data->id); @@ -122,7 +115,7 @@ public function testGETByIdSuccess() /** * @covers \Phramework\JSONAPI\Controller\DELETE::handleDELETE */ - public function testDELETEFailureNotFound() + public function testDELETEFailureNotFound(): void { $this->prepare(); @@ -134,7 +127,7 @@ public function testDELETEFailureNotFound() //Access parameters returned by invoked phramework's viewer $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( @@ -147,7 +140,7 @@ public function testDELETEFailureNotFound() /** * @covers \Phramework\JSONAPI\Controller\DELETE::handleDELETE */ - public function testHandleFailure() + public function testHandleFailure(): void { $this->prepare(); @@ -158,7 +151,7 @@ public function testHandleFailure() //Access parameters returned by invoked phramework's viewer $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( diff --git a/tests/src/Controllers/GETTest.php b/tests/src/Controllers/GETTest.php index e9ebb85..13e9cfd 100644 --- a/tests/src/Controllers/GETTest.php +++ b/tests/src/Controllers/GETTest.php @@ -18,13 +18,14 @@ use Phramework\JSONAPI\APP\Bootstrap; use \Phramework\Phramework; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Phramework\JSONAPI\Controller\GET * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class GETTest extends \PHPUnit_Framework_TestCase +class GETTest extends TestCase { /** * @var Phramework @@ -36,15 +37,6 @@ class GETTest extends \PHPUnit_Framework_TestCase */ protected $parameters; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * @todo update base - */ - protected function setUp() - { - } - protected function prepare() { $_SERVER['REQUEST_URI'] = '/article/'; @@ -69,18 +61,11 @@ function ( ); } - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } /** * @covers Phramework\JSONAPI\Controller\GET::handleGET */ - public function testHandleGet() + public function testHandleGet(): void { $this->prepare(); diff --git a/tests/src/Controllers/PATCHTest.php b/tests/src/Controllers/PATCHTest.php index bb47686..4a53873 100644 --- a/tests/src/Controllers/PATCHTest.php +++ b/tests/src/Controllers/PATCHTest.php @@ -18,13 +18,14 @@ use Phramework\JSONAPI\APP\Models\User; use \Phramework\Phramework; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Phramework\JSONAPI\Controller\PATCH * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class PATCHTest extends \PHPUnit_Framework_TestCase +class PATCHTest extends TestCase { /** * @var Phramework @@ -36,14 +37,6 @@ class PATCHTest extends \PHPUnit_Framework_TestCase */ protected $parameters; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - } - protected function prepare() { $_SERVER['REQUEST_URI'] = '/article/1'; @@ -99,7 +92,7 @@ function ( /** * @covers ::handlePATCH */ - public function testPATCHSuccess() + public function testPATCHSuccess(): void { $this->prepare(); $this->phramework->invoke(); @@ -110,12 +103,12 @@ public function testPATCHSuccess() return; - $this->assertInternalType('object', $parameters); + $this->assertIsObject($parameters); $this->assertObjectHasAttribute('links', $parameters); $this->assertObjectHasAttribute('data', $parameters); - $this->assertInternalType('object', $parameters->data); + $this->assertIsObject($parameters->data); $this->assertObjectHasAttribute('id', $parameters->data); $this->assertInternalType('string', $parameters->data->id); @@ -127,7 +120,7 @@ public function testPATCHSuccess() $article = \Phramework\JSONAPI\APP\Models\Article::getById($id); - $this->assertInternalType('object', $article); + $this->assertIsObject($article); $this->assertObjectHasAttribute('attributes', $article); $this->assertObjectHasAttribute('relationships', $article); @@ -137,7 +130,7 @@ public function testPATCHSuccess() $this->assertObjectHasAttribute('creator', $relationships); $this->assertObjectHasAttribute('tag', $relationships); - $this->assertInternalType('object', $relationships->creator->data); + $this->assertIsObject($relationships->creator->data); $this->assertInternalType('array', $relationships->tag->data); $this->assertEquals('1', $relationships->creator->data->id); @@ -150,7 +143,7 @@ public function testPATCHSuccess() * Cause a not found exception, at to TYPE_TO_ONE relationship * @covers \Phramework\JSONAPI\Controller\PATCH::handlePATCH */ - public function testPATCHFailureToOne() + public function testPATCHFailureToOne(): void { $this->prepare(); @@ -162,7 +155,7 @@ public function testPATCHFailureToOne() //Access parameters written by invoked phramework's viewer $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( @@ -176,7 +169,7 @@ public function testPATCHFailureToOne() * Cause a not found exception, at to TYPE_TO_MANY relationship * @covers \Phramework\JSONAPI\Controller\PATCH::handlePATCH */ - public function testPATCHFailureToMany() + public function testPATCHFailureToMany(): void { $this->prepare(); @@ -188,7 +181,7 @@ public function testPATCHFailureToMany() //Access parameters written by invoked phramework's viewer $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( diff --git a/tests/src/Controllers/POSTTest.php b/tests/src/Controllers/POSTTest.php index deeb9df..7091bd4 100644 --- a/tests/src/Controllers/POSTTest.php +++ b/tests/src/Controllers/POSTTest.php @@ -17,6 +17,7 @@ namespace Phramework\JSONAPI\Controller; use \Phramework\Phramework; +use PHPUnit\Framework\TestCase; /** * @todo test wrong relationship @@ -25,7 +26,7 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class POSTTest extends \PHPUnit_Framework_TestCase +class POSTTest extends TestCase { /** * @var Phramework @@ -37,15 +38,7 @@ class POSTTest extends \PHPUnit_Framework_TestCase */ protected $params; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - } - - protected function prepare() + protected function prepare(): void { //ob_start(); $_SERVER['REQUEST_URI'] = '/article/'; @@ -98,22 +91,10 @@ function ( //ob_end_clean(); } - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - //\Phramework\JSONAPI\APP\Viewers\Viewer::release(__CLASS__); - //foreach ($this->buffer as $line) { - // print_r($line); - //} - } - /** * @covers \Phramework\JSONAPI\Controller\POST::handlePOSTResource */ - public function testHandlePOSTResource() + public function testHandlePOSTResource(): void { $this->testPOSTSuccess(); } @@ -121,7 +102,7 @@ public function testHandlePOSTResource() /** * @covers \Phramework\JSONAPI\Controller\POST::handlePOST */ - public function testPOSTSuccess() + public function testPOSTSuccess(): void { $this->prepare(); //ob_clean(); @@ -132,12 +113,12 @@ public function testPOSTSuccess() $params = $this->params; return; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('links', $params); $this->assertObjectHasAttribute('data', $params); - $this->assertInternalType('object', $params->data); + $this->assertIsObject($params->data); $this->assertObjectHasAttribute('id', $params->data); $this->assertInternalType('string', $params->data->id); @@ -149,7 +130,7 @@ public function testPOSTSuccess() $article = \Phramework\JSONAPI\APP\Models\Article::getById($id); - $this->assertInternalType('object', $article); + $this->assertIsObject($article); $this->assertObjectHasAttribute('attributes', $article); $this->assertObjectHasAttribute('relationships', $article); @@ -159,7 +140,7 @@ public function testPOSTSuccess() $this->assertObjectHasAttribute('creator', $relationships); $this->assertObjectHasAttribute('tag', $relationships); - $this->assertInternalType('object', $relationships->creator->data); + $this->assertIsObject($relationships->creator->data); $this->assertInternalType('array', $relationships->tag->data); $this->assertEquals('1', $relationships->creator->data->id); @@ -172,7 +153,7 @@ public function testPOSTSuccess() * Cause a not found exception, at to TYPE_TO_ONE relationship * @covers \Phramework\JSONAPI\Controller\POST::handlePOST */ - public function testPOSTFailureToOne() + public function testPOSTFailureToOne(): void { $this->prepare(); @@ -184,7 +165,7 @@ public function testPOSTFailureToOne() //Access parameters written by invoked phramework's viewer $params = $this->params; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( @@ -198,7 +179,7 @@ public function testPOSTFailureToOne() * Cause a not found exception, at to TYPE_TO_MANY relationship * @covers \Phramework\JSONAPI\Controller\POST::handlePOST */ - public function testPOSTFailureToMany() + public function testPOSTFailureToMany(): void { $this->prepare(); @@ -210,7 +191,7 @@ public function testPOSTFailureToMany() //Access parameters written by invoked phramework's viewer $params = $this->params; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( diff --git a/tests/src/Controllers/RelationshipsTest.php b/tests/src/Controllers/RelationshipsTest.php index 0a65062..2631e86 100644 --- a/tests/src/Controllers/RelationshipsTest.php +++ b/tests/src/Controllers/RelationshipsTest.php @@ -17,13 +17,14 @@ namespace Phramework\JSONAPI\Controller; use \Phramework\Phramework; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Phramework\JSONAPI\Controller\Relationships * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class RelationshipsTest extends \PHPUnit_Framework_TestCase +class RelationshipsTest extends TestCase { /** * @var Phramework @@ -36,15 +37,7 @@ class RelationshipsTest extends \PHPUnit_Framework_TestCase */ protected $parameters; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - } - - protected function prepare() + protected function prepare(): void { $_SERVER['REQUEST_URI'] = '/article/1/relationships/tag/'; $_SERVER['REQUEST_METHOD'] = Phramework::METHOD_GET; @@ -70,7 +63,7 @@ function ( /** * @covers ::handleByIdRelationships */ - public function testGETByIdSuccess() + public function testGETByIdSuccess(): void { $this->prepare(); @@ -80,14 +73,14 @@ public function testGETByIdSuccess() $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('links', $params); $this->assertObjectHasAttribute('data', $params); return; - $this->assertInternalType('object', $params->data); + $this->assertIsObject($params->data); $this->assertObjectHasAttribute('id', $params->data); $this->assertInternalType('string', $params->data->id); @@ -99,7 +92,7 @@ public function testGETByIdSuccess() $article = \Phramework\JSONAPI\APP\Models\Article::getById($id); - $this->assertInternalType('object', $article); + $this->assertIsObject($article); $this->assertObjectHasAttribute('attributes', $article); $this->assertObjectHasAttribute('relationships', $article); @@ -109,7 +102,7 @@ public function testGETByIdSuccess() $this->assertObjectHasAttribute('creator', $relationships); $this->assertObjectHasAttribute('tag', $relationships); - $this->assertInternalType('object', $relationships->creator->data); + $this->assertIsObject($relationships->creator->data); $this->assertInternalType('array', $relationships->tag->data); $this->assertEquals('1', $relationships->creator->data->id); @@ -121,7 +114,7 @@ public function testGETByIdSuccess() /** * @covers ::handleByIdRelationships */ - public function testDELETEFailureNotFound() + public function testDELETEFailureNotFound(): void { $this->prepare(); @@ -133,7 +126,7 @@ public function testDELETEFailureNotFound() //Access parameters returned by invoked phramework's viewer $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( @@ -146,7 +139,7 @@ public function testDELETEFailureNotFound() /** * @covers ::handleByIdRelationships */ - public function testHandleFailure() + public function testHandleFailure(): void { $this->prepare(); @@ -157,7 +150,7 @@ public function testHandleFailure() //Access parameters returned by invoked phramework's viewer $params = $this->parameters; - $this->assertInternalType('object', $params); + $this->assertIsObject($params); $this->assertObjectHasAttribute('errors', $params); $this->assertSame( diff --git a/tests/src/FieldsTest.php b/tests/src/FieldsTest.php index 8f74ee0..cd44a50 100644 --- a/tests/src/FieldsTest.php +++ b/tests/src/FieldsTest.php @@ -17,6 +17,8 @@ namespace Phramework\JSONAPI; use Exception; +use PHPUnit\Framework\TestCase; +use Phramework\Exceptions\IncorrectParametersException; use Phramework\JSONAPI\APP\Models\Article; use Phramework\JSONAPI\APP\Models\Tag; @@ -25,14 +27,14 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class FieldsTest extends \PHPUnit_Framework_TestCase +class FieldsTest extends TestCase { /** * @var Fields */ protected $fields; - public function setUp() + public function setUp(): void { $this->fields = new Fields(); } @@ -44,7 +46,7 @@ public function testConstruct1() { $fieldsInstance = new Fields(); - $this->assertInternalType('object', $fieldsInstance->getFields()); + $this->assertIsObject($fieldsInstance->getFields()); } /** @@ -58,25 +60,22 @@ public function testConstruct2() $fields = $fieldsInstance->getFields(); - $this->assertInternalType('object', $fields); + $this->assertIsObject($fields); $this->assertObjectHasAttribute( Article::getType(), $fields ); - $this->assertInternalType( - 'array', + $this->assertIsArray( $fields->{Article::getType()} ); } - /** - * @covers ::__construct - * @expectedException Exception - */ - public function testConstructFailure() + public function testConstructFailure(): void { + $this->expectException(\Exception::class); + new Fields((object)[ Article::getType() => 'title' //Must be an array ]); @@ -84,10 +83,8 @@ public function testConstructFailure() /** * @covers ::add - * @before testGet - * @before getFields */ - public function testAdd() + public function testAdd(): void { $return = $this->fields->add( Article::getType(), @@ -106,16 +103,18 @@ public function testAdd() ); } - /** - * @covers ::get - */ - public function testGet() + public function testGet(): void { + $this->fields->add( + Article::getType(), + ['id', 'title', 'updated'] + ); + $return = $this->fields->get( Article::getType() ); - $this->assertSame( + $this->assertEquals( $return, ['id', 'title', 'updated'] ); @@ -124,7 +123,7 @@ public function testGet() /** * @covers ::get */ - public function testGetForNotSetResourceType() + public function testGetForNotSetResourceType(): void { $return = $this->fields->get( Tag::getType() @@ -136,23 +135,15 @@ public function testGetForNotSetResourceType() ); } - /** - * @covers ::getFields - */ - public function testGetFields() + public function testGetFields(): void { - $fields = $this->fields->getFields(); + $this->fields->add(Article::getType(), ['id']); + $fields = $this->fields->get(Article::getType()); - $this->assertInternalType('object', $fields); - - $this->assertObjectHasAttribute(Article::getType(), $fields); + $this->assertNotEmpty($fields); } - - /** - * @covers ::parseFromParameters - */ - public function testParseFromParametersEmpty() + public function testParseFromParametersEmpty(): void { $fields = Fields::parseFromParameters( [], @@ -162,10 +153,7 @@ public function testParseFromParametersEmpty() $this->assertNull($fields); } - /** - * @covers ::parseFromParameters - */ - public function testParseFromParameters() + public function testParseFromParameters(): void { $parameters = (object) [ 'fields' => [ @@ -188,11 +176,7 @@ public function testParseFromParameters() $this->assertEquals(['title'], $fields->fields->{Tag::getType()}); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\IncorrectParametersException - */ - public function testParseFromParametersFailureNotAllowed() + public function testParseFromParametersFailureNotAllowed(): void { $parameters = (object)[ 'fields' => [ @@ -200,17 +184,15 @@ public function testParseFromParametersFailureNotAllowed() ] ]; + $this->expectException(IncorrectParametersException::class); + $fields = Fields::parseFromParameters( $parameters, Article::class ); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\IncorrectParametersException - */ - public function testParseFromParametersFailureNotStringValue() + public function testParseFromParametersFailureNotStringValue(): void { $parameters = (object) [ 'fields' => [ @@ -218,17 +200,15 @@ public function testParseFromParametersFailureNotStringValue() ] ]; + $this->expectException(\Phramework\Exceptions\IncorrectParametersException::class); + Fields::parseFromParameters( $parameters, Article::class ); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureNotAllowedResourceType() + public function testParseFromParametersFailureNotAllowedResourceType(): void { $parameters = (object) [ 'fields' => [ @@ -236,6 +216,8 @@ public function testParseFromParametersFailureNotAllowedResourceType() ] ]; + $this->expectException(\Phramework\Exceptions\RequestException::class); + Fields::parseFromParameters( $parameters, Article::class @@ -245,20 +227,22 @@ public function testParseFromParametersFailureNotAllowedResourceType() /** * @covers ::__get */ - public function testMagicGet() + public function testMagicGet(): void { $fields = new Fields(); - $this->assertInternalType('object', $fields->fields); + $this->assertIsObject($fields->fields); } /** * @covers ::__get - * @expectedException \Exception */ - public function testMagicGetFailure() - { + public function testMagicGetFailure(): void +{ $fields = new Fields(); + + $this->expectException(\Exception::class); + $fields->{'not-found'}; } } diff --git a/tests/src/FilterAttributeTest.php b/tests/src/FilterAttributeTest.php index 3e00083..1db5c13 100644 --- a/tests/src/FilterAttributeTest.php +++ b/tests/src/FilterAttributeTest.php @@ -19,20 +19,21 @@ use Phramework\Exceptions\RequestException; use Phramework\JSONAPI\APP\Models\Article; use Phramework\Models\Operator; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\FilterAttribute * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class FilterAttributeTest extends \PHPUnit_Framework_TestCase +class FilterAttributeTest extends TestCase { /** * @var FilterAttribute */ protected $filterAttribute; - public function setUp() + public function setUp(): void { $this->filterAttribute = new FilterAttribute( 'id', @@ -53,7 +54,7 @@ public function getAvailableProperties() /** * @covers ::__construct */ - public function testConstruct() + public function testConstruct(): void { new FilterAttribute( 'id', @@ -65,7 +66,7 @@ public function testConstruct() /** * @covers ::parse */ - public function testValidate() + public function testValidate(): void { (new FilterTest())->testParseFromParameters(); } @@ -74,7 +75,7 @@ public function testValidate() * @covers ::parse * @expectedException \Phramework\Exceptions\RequestException */ - public function testValidateFailureAttributeArray() + public function testValidateFailureAttributeArray(): void { (new FilterTest())->testParseFromParametersFailureAttributeIsArray(); } @@ -83,7 +84,7 @@ public function testValidateFailureAttributeArray() * @covers ::parse * @expectedException \Phramework\Exceptions\RequestException */ - public function testValidateFailureAttributeJSONSecondLevel() + public function testValidateFailureAttributeJSONSecondLevel(): void { (new FilterTest())->testParseFromParametersFailureAttributeJSONSecondLevel(); } @@ -106,7 +107,7 @@ public function testGet($property, $expected) * @covers ::__get * @expectedException \Exception */ - public function testGetFailure() + public function testGetFailure(): void { $this->filterAttribute->{'not-found'}; } diff --git a/tests/src/FilterJSONAttributeTest.php b/tests/src/FilterJSONAttributeTest.php index c0e3fcd..c193322 100644 --- a/tests/src/FilterJSONAttributeTest.php +++ b/tests/src/FilterJSONAttributeTest.php @@ -17,17 +17,18 @@ namespace Phramework\JSONAPI; use Phramework\Models\Operator; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\FilterJSONAttribute * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class FilterJSONAttributeTest extends \PHPUnit_Framework_TestCase +class FilterJSONAttributeTest extends TestCase { protected $filterAttribute; - public function setUp() + public function setUp(): void { $this->filterAttribute = new FilterJSONAttribute( 'meta', @@ -40,7 +41,7 @@ public function setUp() /** * @covers ::__construct */ - public function testConstruct() + public function testConstruct(): void { new FilterJSONAttribute( 'meta', @@ -53,7 +54,7 @@ public function testConstruct() /** * @covers ::__get */ - public function testGet() + public function testGet(): void { $this->assertSame( 'keywords', @@ -65,7 +66,7 @@ public function testGet() * @covers ::__get * @expectedException \Exception */ - public function testGetFailure() + public function testGetFailure(): void { $this->filterAttribute->{'not-found'}; } diff --git a/tests/src/FilterTest.php b/tests/src/FilterTest.php index c1a0d3f..0e326bf 100644 --- a/tests/src/FilterTest.php +++ b/tests/src/FilterTest.php @@ -16,17 +16,20 @@ */ namespace Phramework\JSONAPI; +use Phramework\Exceptions\IncorrectParametersException; +use Phramework\Exceptions\RequestException; use Phramework\JSONAPI\APP\Bootstrap; use Phramework\JSONAPI\APP\Models\Article; use Phramework\JSONAPI\APP\Models\Tag; use Phramework\Models\Operator; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Filter * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class FilterTest extends \PHPUnit_Framework_TestCase +class FilterTest extends TestCase { public function getAvailableProperties() { @@ -37,48 +40,20 @@ public function getAvailableProperties() ]; } - /** - * @covers ::__construct - */ - public function testConstruct1() - { - $filter = new Filter( - [1, 2, 3], - [ - 'tag' => [1, 2] - ] - ); - } - - /** - * @covers ::__construct - */ - public function testConstruct2() - { - $filter = new Filter( - [1, 2, 3], - null - ); - } - - /** - * @covers ::__construct - * @expectedException Exception - */ public function testConstructFailure1() { + $this->expectException(\Exception::class); + $filter = new Filter( [], 2 ); } - /** - * @covers ::__construct - * @expectedException Exception - */ public function testConstructFailure2() { + $this->expectException(\Exception::class); + $filter = new Filter( [], (object) [ @@ -87,12 +62,10 @@ public function testConstructFailure2() ); } - /** - * @covers ::__construct - * @expectedException Exception - */ public function testConstructFailure3() { + $this->expectException(\Exception::class); + $filter = new Filter( [], null, @@ -105,7 +78,7 @@ public function testConstructFailure3() /** * @covers ::parseFromParameters */ - public function testParseFromParametersPrimaryUsingIntval() + public function testParseFromParametersPrimaryUsingIntval(): void { $parameters = (object) [ 'filter' => (object) [ //Will accept both arrays and object @@ -126,7 +99,7 @@ public function testParseFromParametersPrimaryUsingIntval() /** * @covers ::parseFromParameters */ - public function testParseFromParametersRelationshipEmpty() + public function testParseFromParametersRelationshipEmpty(): void { $parameters = (object) [ 'filter' => (object) [ //Will accept both arrays and object @@ -147,7 +120,7 @@ public function testParseFromParametersRelationshipEmpty() /** * @covers ::parseFromParameters */ - public function testParseFromParametersEmpty() + public function testParseFromParametersEmpty(): void { $filter = Filter::parseFromParameters( [], @@ -160,7 +133,7 @@ public function testParseFromParametersEmpty() /** * @covers ::parseFromParameters */ - public function testParseFromParameters() + public function testParseFromParameters(): void { $parameters = (object) [ 'filter' => [ @@ -190,13 +163,11 @@ public function testParseFromParameters() true ); - $this->assertInternalType( - 'object', + $this->assertIsObject( $filter->relationships ); - $this->assertInternalType( - 'array', + $this->assertIsArray( $filter->relationships->tag ); @@ -235,11 +206,7 @@ public function testParseFromParameters() $this->assertTrue($found2); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\IncorrectParametersException - */ - public function testParseFromParametersFailurePrimaryNotString() + public function testParseFromParametersFailurePrimaryNotString(): void { $parameters = (object) [ 'filter' => [ @@ -247,18 +214,15 @@ public function testParseFromParametersFailurePrimaryNotString() ] ]; + $this->expectException(IncorrectParametersException::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters ); } - - /** - * @covers ::validate - * @expectedException \Phramework\Exceptions\IncorrectParametersException - */ - public function testParseFromParametersFailurePrimaryToParse() + public function testParseFromParametersFailurePrimaryToParse(): void { $parameters = (object) [ 'filter' => [ @@ -266,17 +230,15 @@ public function testParseFromParametersFailurePrimaryToParse() ] ]; + $this->expectException(IncorrectParametersException::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters )->validate(Article::class); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\IncorrectParametersException - */ - public function testParseFromParametersFailureRelationshipNotString() + public function testParseFromParametersFailureRelationshipNotString(): void { $parameters = (object) [ 'filter' => [ @@ -284,17 +246,15 @@ public function testParseFromParametersFailureRelationshipNotString() ] ]; + $this->expectException(IncorrectParametersException::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters )->validate(Article::class); } - /** - * @covers ::validate - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureNotAllowedAttribute() + public function testParseFromParametersFailureNotAllowedAttribute(): void { $parameters = (object) [ 'filter' => [ @@ -302,17 +262,15 @@ public function testParseFromParametersFailureNotAllowedAttribute() ] ]; + $this->expectException(RequestException::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters )->validate(Article::class); } - /** - * @covers ::validate - * @expectedException Exception - */ - public function testParseFromParametersFailureAttributeWithoutValidator() + public function testParseFromParametersFailureAttributeWithoutValidator(): void { $parameters = (object) [ 'filter' => [ @@ -320,17 +278,15 @@ public function testParseFromParametersFailureAttributeWithoutValidator() ] ]; + $this->expectException(\Exception::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters )->validate(Article::class); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureAttributeIsArray() + public function testParseFromParametersFailureAttributeIsArray(): void { $parameters = (object) [ 'filter' => [ @@ -338,17 +294,15 @@ public function testParseFromParametersFailureAttributeIsArray() ] ]; + $this->expectException(RequestException::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters ); } - /** - * @covers ::validate - * @expectedException \Phramework\Exceptions\IncorrectParametersException - */ - public function testParseFromParametersFailureAttributeToParse() + public function testParseFromParametersFailureAttributeToParse(): void { $parameters = (object) [ 'filter' => [ @@ -356,17 +310,15 @@ public function testParseFromParametersFailureAttributeToParse() ] ]; + $this->expectException(IncorrectParametersException::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters )->validate(Article::class); } - /** - * @covers ::validate - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureAttributeNotAllowedOperator() + public function testParseFromParametersFailureAttributeNotAllowedOperator(): void { $parameters = (object) [ 'filter' => [ @@ -374,17 +326,15 @@ public function testParseFromParametersFailureAttributeNotAllowedOperator() ] ]; + $this->expectException(RequestException::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters )->validate(Article::class); } - /** - * @covers ::validate - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureAttributeNotAcceptingJSONOperator() + public function testParseFromParametersFailureAttributeNotAcceptingJSONOperator(): void { $parameters = (object) [ 'filter' => [ @@ -392,17 +342,15 @@ public function testParseFromParametersFailureAttributeNotAcceptingJSONOperator( ] ]; + $this->expectException(RequestException::class); + Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters )->validate(Article::class); } - /** - * @covers ::validate - * @expectedException \Phramework\Exceptions\IncorrectParametersException - */ - public function testParseFromParametersFailureAttributeUsingJSONPropertyValidator() + public function testParseFromParametersFailureAttributeUsingJSONPropertyValidator(): void { $parameters = (object) [ 'filter' => [ @@ -415,14 +363,12 @@ public function testParseFromParametersFailureAttributeUsingJSONPropertyValidato Article::class //Use article resource model's filters ); + $this->expectException(IncorrectParametersException::class); + $filter->validate(Article::class); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureAttributeJSONSecondLevel() + public function testParseFromParametersFailureAttributeJSONSecondLevel(): void { $parameters = (object) [ 'filter' => [ @@ -430,18 +376,20 @@ public function testParseFromParametersFailureAttributeJSONSecondLevel() ] ]; + $this->expectException(RequestException::class); + $filter = Filter::parseFromParameters( $parameters, Article::class //Use article resource model's filters ); + + $filter->validate(Article::class); } - /** - * @covers ::validate - */ - public function testValidate() + + public function testValidate(): void { $filter = new Filter( [], @@ -451,13 +399,11 @@ public function testValidate() ); $filter->validate(Article::class); + + $this->assertTrue(true); } - /** - * @covers ::validate - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testValidateFailureRelationshipNotFound() + public function testValidateFailureRelationshipNotFound(): void { $filter = new Filter( [], @@ -466,6 +412,8 @@ public function testValidateFailureRelationshipNotFound() ] ); + $this->expectException(RequestException::class); + $filter->validate(Article::class); } @@ -482,14 +430,13 @@ public function testGet($property, $expected) $this->assertEquals($expected, $filter->{$property}); } - /** - * @covers ::__get - * @expectedException \Exception - */ - public function testGetFailure() + public function testGetFailure(): void { $filter = new Filter(); + + $this->expectException(\Exception::class); + $filter->{'not-found'}; } } diff --git a/tests/src/Model/CacheTest.php b/tests/src/Model/CacheTest.php index 461d126..4c4f2cc 100644 --- a/tests/src/Model/CacheTest.php +++ b/tests/src/Model/CacheTest.php @@ -23,13 +23,14 @@ use Phramework\JSONAPI\Resource; use Phramework\JSONAPI\Viewers\JSONAPI; use Phramework\Phramework; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Model\Cache * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class CacheTest extends \PHPUnit_Framework_TestCase +class CacheTest extends TestCase { /** * Helper method @@ -50,7 +51,7 @@ protected function get($limit = 1, $offset = 0) /** * @covers ::initializeCache */ - public function testInitializeCache() + public function testInitializeCache(): void { Bootstrap::invokeStaticMethod( Article::class, @@ -63,7 +64,7 @@ public function testInitializeCache() * @covers ::setCache * @after testInitializeCache */ - public function testSetCache() + public function testSetCache(): void { $article = clone Article::getById('1'); @@ -97,7 +98,7 @@ public function testSetCache() * @covers ::getCache * @after testInitializeCache */ - public function testGetCache() + public function testGetCache(): void { $this->assertInstanceOf( Resource::class, @@ -119,7 +120,7 @@ public function testGetCache() * @covers ::invalidateCache * @after testGetCache */ - public function testInvalidateCache() + public function testInvalidateCache(): void { Bootstrap::invokeStaticMethod( Article::class, diff --git a/tests/src/Model/DirectivesTest.php b/tests/src/Model/DirectivesTest.php index 2bcc1af..bf802c2 100644 --- a/tests/src/Model/DirectivesTest.php +++ b/tests/src/Model/DirectivesTest.php @@ -28,18 +28,19 @@ use Phramework\JSONAPI\Resource; use Phramework\JSONAPI\Sort; use Phramework\Models\Operator; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Model\Directives * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class DirectivesTest extends \PHPUnit_Framework_TestCase +class DirectivesTest extends TestCase { /** * @covers ::handleSort */ - public function testHandleSort() + public function testHandleSort(): void { $sort = new Sort( Tag::getTable(), @@ -74,7 +75,7 @@ public function testHandleSort() /** * @covers ::handleSort */ - public function testHandleSortNull() + public function testHandleSortNull(): void { $sort = new Sort( null, @@ -108,7 +109,7 @@ public function testHandleSortNull() /** * @covers ::handlePage */ - public function testHandlePage() + public function testHandlePage(): void { $limit = 1; $offset = 2; @@ -131,7 +132,7 @@ public function testHandlePage() $page ); - $this->assertInternalType('string', $query); + $this->assertIsString($query); $pattern = sprintf( '/^SELECT \* FROM "%s"\s+LIMIT %s\s+OFFSET %s$/', @@ -146,7 +147,7 @@ public function testHandlePage() /** * @covers ::handleFields */ - public function testHandleFields() + public function testHandleFields(): void { $additional = 'title'; @@ -225,7 +226,7 @@ public function testHandleFields() * @covers ::handleGet * @todo rewrite */ - public function testHandleGet() + public function testHandleGet(): void { $page = new Page(10, 1); $filter = new Filter( @@ -282,7 +283,7 @@ public function testHandleGet() /** * @covers ::handleFilter */ - public function testHandleFilterViaGet() + public function testHandleFilterViaGet(): void { $this->testHandleGet(); } @@ -290,7 +291,7 @@ public function testHandleFilterViaGet() /** * @covers ::handleFilter */ - public function testHandleFilter() + public function testHandleFilter(): void { $filter = new Filter(); diff --git a/tests/src/Model/GetTest.php b/tests/src/Model/GetTest.php index d960d2d..bb0539f 100644 --- a/tests/src/Model/GetTest.php +++ b/tests/src/Model/GetTest.php @@ -21,6 +21,7 @@ use Phramework\JSONAPI\Page; use Phramework\JSONAPI\Resource; use Phramework\JSONAPI\Sort; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Model\Get @@ -28,7 +29,7 @@ * @author Xenofon Spafaridis * @afterClass CacheTest */ -class GetTest extends \PHPUnit_Framework_TestCase +class GetTest extends TestCase { /** * Helper method @@ -50,7 +51,7 @@ protected function get($limit = 1, $offset = 0) * @covers ::get * @expectedException \Phramework\Exceptions\NotImplementedException */ - public function testGet() + public function testGet(): void { Get::get(); } @@ -61,8 +62,8 @@ public function testGet() * Assuming at least one trend_template exists * @covers ::getById */ - public function testGetById() - { + public function testGetById(): string +{ //Get 2 first items $collection = self::get(2); @@ -73,7 +74,7 @@ public function testGetById() //Request again to access cached $collectionResource = Article::getById($id); - $this->assertInternalType('object', $collectionResource); + $this->assertIsObject($collectionResource); $this->assertSame($id, $collectionResource->id); $this->assertSame(Article::getType(), $collectionResource->type); @@ -90,7 +91,7 @@ public function testGetById() //Request again to access cached $resources = Article::getById($ids); - $this->assertInternalType('object', $resources); + $this->assertIsObject($resources); $resourcesCount = 0; foreach ($resources as $r) { @@ -109,7 +110,7 @@ public function testGetById() $resource = $resources->{$resourceId}; - $this->assertInternalType('object', $resource); + $this->assertIsObject($resource); $this->assertSame($resourceId, $resource->id); $this->assertSame(Article::getType(), $resource->type); } @@ -127,7 +128,7 @@ public function testGetById() //Fetch multiple resources $resources = Article::getById($ids); - $this->assertInternalType('object', $resources); + $this->assertIsObject($resources); $resourcesCount = 0; foreach ($resources as $r) { @@ -147,7 +148,7 @@ public function testGetById() $resourceId = $ids[0]; $resource = $resources->{$resourceId}; - $this->assertInternalType('object', $resource); + $this->assertIsObject($resource); $this->assertSame($resourceId, $resource->id); $this->assertSame(Article::getType(), $resource->type); @@ -167,7 +168,7 @@ public function testGetById() /** * @covers ::parseSort */ - public function testParseSort() + public function testParseSort(): void { $this->assertInstanceOf(Sort::class, Article::parseSort((object) [])); } @@ -175,7 +176,7 @@ public function testParseSort() /** * @covers ::parsePage */ - public function testParsePage() + public function testParsePage(): void { $this->assertNull(Article::parsePage((object) [])); } @@ -183,7 +184,7 @@ public function testParsePage() /** * @covers ::parseFields */ - public function testParseFields() + public function testParseFields(): void { $this->assertNull(Article::parseFields((object) [])); } @@ -191,7 +192,7 @@ public function testParseFields() /** * @covers ::parseFilter */ - public function testParseFilter() + public function testParseFilter(): void { $this->assertNull(Article::parseFilter((object) [])); } diff --git a/tests/src/Model/RelationshipTest.php b/tests/src/Model/RelationshipTest.php index 282a968..51e1591 100644 --- a/tests/src/Model/RelationshipTest.php +++ b/tests/src/Model/RelationshipTest.php @@ -19,18 +19,19 @@ use Phramework\JSONAPI\APP\Models\Article; use Phramework\JSONAPI\APP\Models\Tag; use Phramework\JSONAPI\Page; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Model\Relationship * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class RelationshipTest extends \PHPUnit_Framework_TestCase +class RelationshipTest extends TestCase { /** * @covers ::getRelationshipData */ - public function testGetRelationshipData() + public function testGetRelationshipData(): void { $articles = Article::get(new Page(1, 1))[0]; diff --git a/tests/src/ModelTest.php b/tests/src/ModelTest.php index 6fd1797..6847f27 100644 --- a/tests/src/ModelTest.php +++ b/tests/src/ModelTest.php @@ -21,13 +21,14 @@ use Phramework\JSONAPI\APP\Models\Article; use Phramework\Util\Util; use Phramework\Validate\ObjectValidator; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Model * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class ModelTest extends \PHPUnit_Framework_TestCase +class ModelTest extends TestCase { /** * @covers ::getValidationModel @@ -57,8 +58,8 @@ public function testFilterValidationModel($modelClass) /** * @covers ::collection */ - public function testCollection() - { + public function testCollection(): void +{ $resources = Article::collection([ [ 'id' => 1 @@ -72,8 +73,8 @@ public function testCollection() /** * @covers ::resource */ - public function testResource() - { + public function testResource(): void +{ $resources = Article::resource( [ 'id' => 1 @@ -92,7 +93,7 @@ public function testGetFilterable($modelClass) { $fields = $modelClass::getFilterable(); - $this->assertInternalType('object', $fields); + $this->assertIsObject($fields); $this->assertTrue(Util::isArrayOf((array)$fields, 'integer'), 'Expect object of integers'); } @@ -138,8 +139,8 @@ public function testGetFields($modelClass) /** * @covers ::getSort */ - public function testGetSort() - { + public function testGetSort(): void +{ $sort = Article::getSort(); $this->assertInstanceOf(Sort::class, $sort); diff --git a/tests/src/PageTest.php b/tests/src/PageTest.php index f5f9573..ad78982 100644 --- a/tests/src/PageTest.php +++ b/tests/src/PageTest.php @@ -17,13 +17,14 @@ namespace Phramework\JSONAPI; use Phramework\JSONAPI\APP\Models\Article; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Page * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class PageTest extends \PHPUnit_Framework_TestCase +class PageTest extends TestCase { public function getAvailableProperties() { @@ -36,7 +37,7 @@ public function getAvailableProperties() /** * @covers ::__construct */ - public function testConstruct() + public function testConstruct(): void { $page = new Page(); } @@ -44,7 +45,7 @@ public function testConstruct() /** * @covers ::parseFromParameters */ - public function testParseFromParametersEmpty() + public function testParseFromParametersEmpty(): void { $page = Page::parseFromParameters( [], @@ -57,7 +58,7 @@ public function testParseFromParametersEmpty() /** * @covers ::parseFromParameters */ - public function testParseFromParameters() + public function testParseFromParameters(): void { $parameters = (object) [ 'page' => [ @@ -84,7 +85,7 @@ public function testParseFromParameters() * @covers ::parseFromParameters * @expectedException \Phramework\Exceptions\IncorrectParametersException */ - public function testParseFromParametersFailureToParseLimit() + public function testParseFromParametersFailureToParseLimit(): void { $parameters = (object) [ 'page' => (object) [ @@ -102,7 +103,7 @@ public function testParseFromParametersFailureToParseLimit() * @covers ::parseFromParameters * @expectedException \Phramework\Exceptions\IncorrectParametersException */ - public function testParseFromParametersFailureToParseOffset() + public function testParseFromParametersFailureToParseOffset(): void { $parameters = (object) [ 'page' => [ @@ -133,7 +134,7 @@ public function testGet($property, $expected) * @covers ::__get * @expectedException \Exception */ - public function testGetFailure() + public function testGetFailure(): void { $page = new Page(); diff --git a/tests/src/RelationshipTest.php b/tests/src/RelationshipTest.php index 528db1f..488daa5 100644 --- a/tests/src/RelationshipTest.php +++ b/tests/src/RelationshipTest.php @@ -19,13 +19,14 @@ use Phramework\JSONAPI\APP\Models\Tag; use Phramework\JSONAPI\Relationship; use Phramework\Phramework; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Phramework\JSONAPI\Relationship * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class RelationshipTest extends \PHPUnit_Framework_TestCase +class RelationshipTest extends TestCase { public function getAvailableProperties() { @@ -43,7 +44,7 @@ public function getAvailableProperties() */ protected $relationship; - public function setUp() + public function setUp(): void { $this->relationship = new Relationship( Tag::class @@ -53,7 +54,7 @@ public function setUp() /** * @covers ::__construct */ - public function testConstruct() + public function testConstruct(): void { new Relationship( Tag::class, @@ -121,7 +122,7 @@ public function testConstructFailure2() * @covers ::__construct * @expectedException \Exception */ - public function testConstructFailureInvalidCallbackMethod() + public function testConstructFailureInvalidCallbackMethod(): void { new Relationship( Tag::class, @@ -137,7 +138,7 @@ public function testConstructFailureInvalidCallbackMethod() * @covers ::__construct * @expectedException \Exception */ - public function testConstructFailureInvalidMethodNotCallable() + public function testConstructFailureInvalidMethodNotCallable(): void { new Relationship( Tag::class, @@ -164,7 +165,7 @@ public function testGet($property, $expected) * @covers ::__get * @expectedException \Exception */ - public function testGetFailure() + public function testGetFailure(): void { $this->relationship->{'not-found'}; } @@ -172,7 +173,7 @@ public function testGetFailure() /** * @covers ::__set */ - public function testSet() + public function testSet(): void { $this->relationship->{'flags'} = Relationship::FLAG_INCLUDE_BY_DEFAULT; @@ -183,7 +184,7 @@ public function testSet() * @covers ::__set * @expectedException \Exception */ - public function testSetFailure() + public function testSetFailure(): void { $this->relationship->{'modelClass'} = Tag::class; } diff --git a/tests/src/ResourceTest.php b/tests/src/ResourceTest.php index ba2357d..0a79867 100644 --- a/tests/src/ResourceTest.php +++ b/tests/src/ResourceTest.php @@ -19,13 +19,14 @@ use Phramework\JSONAPI\APP\Models\Article; use Phramework\JSONAPI\APP\Models\Tag; use Phramework\JSONAPI\APP\Models\User; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Resource * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class ResourceTest extends \PHPUnit_Framework_TestCase +class ResourceTest extends TestCase { public function getAvailableProperties() { @@ -42,7 +43,7 @@ public function getAvailableProperties() /** * @covers ::__construct */ - public function testConstruct() + public function testConstruct(): void { new Resource( Article::getType(), @@ -53,7 +54,7 @@ public function testConstruct() /** * @covers ::parseFromRecords */ - public function testParseFromRecords() + public function testParseFromRecords(): void { $articles = Article::get(); } @@ -61,7 +62,7 @@ public function testParseFromRecords() /** * @covers ::parseFromRecord */ - public function testParseFromRecord() + public function testParseFromRecord(): void { $tags = Tag::get(); @@ -71,7 +72,7 @@ public function testParseFromRecord() /** * @covers ::parseFromRecords */ - public function testParseFromRecordsEmpty() + public function testParseFromRecordsEmpty(): void { $this->assertEmpty(Tag::collection(null)); $this->assertEmpty(Tag::collection([])); @@ -80,7 +81,7 @@ public function testParseFromRecordsEmpty() /** * @covers ::parseFromRecord */ - public function testParseFromRecordEmpty() + public function testParseFromRecordEmpty(): void { $this->assertNull(Tag::resource(null)); $this->assertNull(Tag::resource([])); @@ -90,7 +91,7 @@ public function testParseFromRecordEmpty() * @covers ::parseFromRecord * @expectedException \Exception */ - public function testParseFromRecordFailureModelClass() + public function testParseFromRecordFailureModelClass(): void { Resource::parseFromRecord( [ @@ -103,7 +104,7 @@ public function testParseFromRecordFailureModelClass() /** * @covers ::parseFromRecord */ - public function testParseFromRecordSuccessToOnePreloaded() + public function testParseFromRecordSuccessToOnePreloaded(): void { Article::resource([ 'id' => '1', @@ -114,7 +115,7 @@ public function testParseFromRecordSuccessToOnePreloaded() /** * @covers ::parseFromRecord */ - public function testParseFromRecordSuccessToOnePreloadedRelationshipResource() + public function testParseFromRecordSuccessToOnePreloadedRelationshipResource(): void { $creator = RelationshipResource::parseFromRecord(User::$records[0], User::class); @@ -128,7 +129,7 @@ public function testParseFromRecordSuccessToOnePreloadedRelationshipResource() * @covers ::parseFromRecord * @expectedException \Exception */ - public function testParseFromRecordSuccessToOnePreloadedResource() + public function testParseFromRecordSuccessToOnePreloadedResource(): void { $creator = User::resource(User::$records[0]); @@ -141,7 +142,7 @@ public function testParseFromRecordSuccessToOnePreloadedResource() /** * @covers ::parseFromRecord */ - public function testParseFromRecordSuccessToOneUseCallback() + public function testParseFromRecordSuccessToOneUseCallback(): void { Article::resource([ 'id' => '1' @@ -151,7 +152,7 @@ public function testParseFromRecordSuccessToOneUseCallback() /** * @covers ::parseFromRecord */ - public function testParseFromRecordSuccessToManyPreloaded() + public function testParseFromRecordSuccessToManyPreloaded(): void { Article::resource([ 'id' => '1', @@ -163,7 +164,7 @@ public function testParseFromRecordSuccessToManyPreloaded() * @covers ::parseFromRecord * @expectedException \Exception */ - public function testParseFromRecordFailureNoIdAttributeSetInRecord() + public function testParseFromRecordFailureNoIdAttributeSetInRecord(): void { Tag::resource(['title' => 'true']); } @@ -172,7 +173,7 @@ public function testParseFromRecordFailureNoIdAttributeSetInRecord() * @covers ::parseFromRecord * @expectedException \Exception */ - public function testParseFromRecordFailureMetaNotAnObject() + public function testParseFromRecordFailureMetaNotAnObject(): void { Tag::resource([ 'id' => '1', @@ -196,7 +197,7 @@ public function testParseFromRecordFailureMetaNotAnObject2() * @covers ::parseFromRecord * @expectedException \Exception */ - public function testParseFromRecordFailureToManyNotAnStringOrResource() + public function testParseFromRecordFailureToManyNotAnStringOrResource(): void { Article::resource([ 'id' => '1', @@ -208,7 +209,7 @@ public function testParseFromRecordFailureToManyNotAnStringOrResource() * @covers ::parseFromRecord * @expectedException \Exception */ - public function testParseFromRecordFailureToManyNotAnArray() + public function testParseFromRecordFailureToManyNotAnArray(): void { $this->markTestIncomplete(); Article::resource([ @@ -221,7 +222,7 @@ public function testParseFromRecordFailureToManyNotAnArray() * @covers ::parseFromRecord * @expectedException \Exception */ - public function testParseFromRecordFailureToManyNotAnArrayOfStringsOrAttributes() + public function testParseFromRecordFailureToManyNotAnArrayOfStringsOrAttributes(): void { $this->markTestIncomplete(); Article::resource([ @@ -255,7 +256,7 @@ public function testSet($property) /** * @covers ::__set */ - public function testSetId() + public function testSetId(): void { $resource = new Resource(Tag::getType(), '1'); @@ -294,7 +295,7 @@ public function testGet($property, $expected) * @covers ::__get * @expectedException \Exception */ - public function testGetFailure() + public function testGetFailure(): void { $resource = new Resource(Tag::getType(), '1'); diff --git a/tests/src/SortTest.php b/tests/src/SortTest.php index 3639a23..a0744f0 100644 --- a/tests/src/SortTest.php +++ b/tests/src/SortTest.php @@ -16,15 +16,17 @@ */ namespace Phramework\JSONAPI; +use Phramework\Exceptions\RequestException; use Phramework\JSONAPI\APP\Models\Article; use Phramework\JSONAPI\APP\Models\Tag; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\Sort * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class SortTest extends \PHPUnit_Framework_TestCase +class SortTest extends TestCase { public function getAvailableProperties() { @@ -38,7 +40,7 @@ public function getAvailableProperties() /** * @covers ::__construct */ - public function testConstruct() + public function testConstruct(): void { $sort = new Sort( Article::getTable(), @@ -49,7 +51,7 @@ public function testConstruct() /** * @covers ::parseFromParameters */ - public function testParseFromParametersEmpty() + public function testParseFromParametersEmpty(): void { $sort = Sort::parseFromParameters( [], @@ -62,7 +64,7 @@ public function testParseFromParametersEmpty() /** * @covers ::parseFromParameters */ - public function testParseFromParameters() + public function testParseFromParameters(): void { $parameters = (object) [ 'sort' => '-id' @@ -96,64 +98,57 @@ public function testParseFromParameters() $this->assertTrue($sort->ascending); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureNotString() + public function testParseFromParametersFailureNotString(): void { $parameters = (object) [ 'sort' => ['id'] ]; + $this->expectException(RequestException::class); + $sort = Sort::parseFromParameters( $parameters, Article::class ); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureParseExpression() + public function testParseFromParametersFailureParseExpression(): void { $parameters = (object) [ 'sort' => '--id' ]; + $this->expectException(RequestException::class); + $sort = Sort::parseFromParameters( $parameters, Article::class ); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureNotSortable() + public function testParseFromParametersFailureNotSortable(): void { $parameters = (object) [ 'sort' => 'meta' ]; + $this->expectException(RequestException::class); + $sort = Sort::parseFromParameters( $parameters, Article::class ); } - /** - * @covers ::parseFromParameters - * @expectedException \Phramework\Exceptions\RequestException - */ - public function testParseFromParametersFailureNoSortableAttributes() + public function testParseFromParametersFailureNoSortableAttributes(): void { $parameters = (object) [ 'sort' => 'id' ]; + + $this->expectException(RequestException::class); + $sort = Sort::parseFromParameters( $parameters, Tag::class @@ -180,7 +175,7 @@ public function testGet($property, $expected) * @covers ::__get * @expectedException \Exception */ - public function testGetFailure() + public function testGetFailure(): void { $sort = new Sort( Article::getTable(), diff --git a/tests/src/ValidationModelTest.php b/tests/src/ValidationModelTest.php index df029bc..ce6d933 100644 --- a/tests/src/ValidationModelTest.php +++ b/tests/src/ValidationModelTest.php @@ -17,18 +17,19 @@ namespace Phramework\JSONAPI; use Phramework\Validate\ObjectValidator; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass Phramework\JSONAPI\ValidationModel * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class ValidationModelTest extends \PHPUnit_Framework_TestCase +class ValidationModelTest extends TestCase { /** * @covers ::__construct */ - public function testConstruct() + public function testConstruct(): void { new ValidationModel( new ObjectValidator(), diff --git a/tests/src/Viewers/JSONAPITest.php b/tests/src/Viewers/JSONAPITest.php index 592e6f5..ef3a581 100644 --- a/tests/src/Viewers/JSONAPITest.php +++ b/tests/src/Viewers/JSONAPITest.php @@ -19,18 +19,19 @@ use Phramework\JSONAPI\APP\Models\Article; use Phramework\JSONAPI\APP\Models\Tag; use Phramework\JSONAPI\Relationship; +use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Phramework\JSONAPI\Viewers\JSONAPI * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis */ -class JSONAPITest extends \PHPUnit_Framework_TestCase +class JSONAPITest extends TestCase { /** * @covers ::view */ - public function testView() + public function testView(): void { ob_start(); (new JSONAPI())->view((object) [ @@ -53,7 +54,7 @@ public function testView() * @covers ::header * @before testView */ - public function testHeader() + public function testHeader(): void { JSONAPI::header(); }