diff --git a/Test/Case/Controller/Component/FilterComponentTest.php b/Test/Case/Controller/Component/FilterComponentTest.php index 981f2a7..85620de 100644 --- a/Test/Case/Controller/Component/FilterComponentTest.php +++ b/Test/Case/Controller/Component/FilterComponentTest.php @@ -11,8 +11,6 @@ * GPL */ -use PHPUnit\Framework\TestCase; - App::uses('Router', 'Routing'); App::uses('Component', 'Filter.Filter'); App::uses('Document', 'Filter.Test/Case/MockObjects'); @@ -23,7 +21,7 @@ App::uses('Item', 'Filter.Test/Case/MockObjects'); App::uses('Metadata', 'Filter.Test/Case/MockObjects'); -class FilterComponentTest extends TestCase +class FilterComponentTest extends CakeTestCase { /** * @var string[] @@ -82,7 +80,7 @@ public function testNoFilters(): void $this->Controller->Components->trigger('initialize', array($this->Controller)); $this->assertEmpty($this->Controller->Filter->settings); $isBehaviorEnabled = $this->Controller->Document->Behaviors->enabled('Filtered'); - $this->assertInternalType('bool', $isBehaviorEnabled); + $this->assertIsBool($isBehaviorEnabled); if (is_bool($isBehaviorEnabled)) { $this->assertFalse($isBehaviorEnabled); } @@ -105,7 +103,9 @@ public function testNoModelPresentOrNoActionFilters(): void ) ); - $this->setExpectedException('PHPUnit_Framework_Error_Notice'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Filter model not found: DocumentArse'); + $this->Controller->filters = $testSettings; $this->Controller->Components->trigger('initialize', array($this->Controller)); @@ -117,11 +117,10 @@ public function testNoModelPresentOrNoActionFilters(): void ) ); - $this->Controller->filters = $testSettings; $this->Controller->Components->trigger('initialize', array($this->Controller)); $isBehaviorEnabled = $this->Controller->Document->Behaviors->enabled('Filtered'); - $this->assertInternalType('bool', $isBehaviorEnabled); + $this->assertIsBool($isBehaviorEnabled); if (is_bool($isBehaviorEnabled)) { $this->assertFalse($isBehaviorEnabled); } @@ -137,7 +136,7 @@ public function testNoModelPresentOrNoActionFilters(): void $this->Controller->filters = $testSettings; $this->Controller->Components->trigger('initialize', array($this->Controller)); $isBehaviorEnabled = $this->Controller->Document->Behaviors->enabled('Filtered'); - $this->assertInternalType('bool', $isBehaviorEnabled); + $this->assertIsBool($isBehaviorEnabled); if (is_bool($isBehaviorEnabled)) { $this->assertTrue($isBehaviorEnabled); } @@ -205,11 +204,19 @@ public function testSessionStartupData(): void $filterValues = array(); $this->Controller->Session->write($sessionKey, $filterValues); - $this->setExpectedException('PHPUnit_Framework_Error_Notice'); - $this->Controller->Components->trigger('initialize', array($this->Controller)); + try { + $this->Controller->Components->trigger('initialize', array($this->Controller)); + $this->fail('InvalidArgumentException was not thrown'); + } catch (InvalidArgumentException $e1) { + $this->assertSame('Filter model not found: FakeNonexistant', $e1->getMessage()); + } - $this->setExpectedException('PHPUnit_Framework_Error_Notice'); - $this->Controller->Components->trigger('startup', array($this->Controller)); + try { + $this->Controller->Components->trigger('startup', array($this->Controller)); + $this->fail('InvalidArgumentException was not thrown'); + } catch (InvalidArgumentException $e2) { + $this->assertSame('xxxFilter model not found: FakeNonexistant', $e2->getMessage()); + } $actualFilterValues = $this->Controller->Document->getFilterValues(); $this->assertEquals( $filterValues, diff --git a/Test/test.sh b/Test/test.sh index 87256fc..00da225 100755 --- a/Test/test.sh +++ b/Test/test.sh @@ -12,7 +12,7 @@ composer require --prefer-source kba-team/cakephp-filter-plugin:@dev # Either use the test case from the parameter, or run all tests if [ -n "${1}" ]; then # call PHPUnit and remember return code - vendor/bin/phpunit "Plugin/Filter/${1}" + vendor/bin/phpunit ${*} E=$? else (>&2 echo "ERROR: Missing test case!")