Skip to content

Commit

Permalink
WIP fix unit tests #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Stich committed May 28, 2024
1 parent 8b2b648 commit b88412a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions Test/Case/Controller/Component/FilterComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
* GPL <http://www.gnu.org/licenses/gpl.html>
*/

use PHPUnit\Framework\TestCase;

App::uses('Router', 'Routing');
App::uses('Component', 'Filter.Filter');
App::uses('Document', 'Filter.Test/Case/MockObjects');
Expand All @@ -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[]
Expand Down Expand Up @@ -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);
}
Expand All @@ -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));

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {

Check failure on line 210 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.1)

Dead catch - InvalidArgumentException is never thrown in the try block.

Check failure on line 210 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.3)

Dead catch - InvalidArgumentException is never thrown in the try block.

Check failure on line 210 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.1)

Dead catch - InvalidArgumentException is never thrown in the try block.
$this->assertSame('Filter model not found: FakeNonexistant', $e1->getMessage());
}

$this->setExpectedException('PHPUnit_Framework_Error_Notice');
$this->Controller->Components->trigger('startup', array($this->Controller));
try {

Check failure on line 214 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.1)

Unreachable statement - code above always terminates.

Check failure on line 214 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.3)

Unreachable statement - code above always terminates.

Check failure on line 214 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.1)

Unreachable statement - code above always terminates.
$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,
Expand Down
2 changes: 1 addition & 1 deletion Test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down

0 comments on commit b88412a

Please sign in to comment.