Skip to content

Commit

Permalink
Upgrade to PHPUnit 10
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed May 29, 2023
1 parent e137f4f commit 8198a73
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 457 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/phpunit.xml
/vendor/
.phpcs-cache
.phpunit.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-servicemanager": "^3.21",
"phpbench/phpbench": "^1.2.10",
"phpunit/phpunit": "^9.6.8",
"phpunit/phpunit": "^10.1.3",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.12"
},
Expand Down
582 changes: 229 additions & 353 deletions composer.lock

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
colors="true"
cacheDirectory=".phpunit.cache"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnSkippedTests="true"
failOnNotice="true"
failOnDeprecation="true"
failOnWarning="true"
>
<testsuites>
<testsuite name="laminas-permissions-acl Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
11 changes: 3 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,6 @@
</UnusedForeachValue>
</file>
<file src="test/Assertion/AssertionAggregateTest.php">
<DeprecatedMethod>
<code>setMethods</code>
<code>setMethods</code>
<code>setMethods</code>
<code>setMethods</code>
<code>setMethods</code>
<code>setMethods</code>
</DeprecatedMethod>
<MissingReturnType>
<code>testClearAssertions</code>
</MissingReturnType>
Expand Down Expand Up @@ -480,6 +472,9 @@
<MissingReturnType>
<code>testExpressionsEvaluation</code>
</MissingReturnType>
<PossiblyUnusedMethod>
<code>getExpressions</code>
</PossiblyUnusedMethod>
</file>
<file src="test/TestAsset/ExpressionUseCase/BlogPost.php">
<PossiblyUnusedMethod>
Expand Down
120 changes: 34 additions & 86 deletions test/Assertion/AssertionAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void

public function testAddAssertion(): AssertionAggregate
{
$assertion = $this->getMockForAbstractClass(AssertionInterface::class);
$assertion = $this->createMock(AssertionInterface::class);
$this->assertionAggregate->addAssertion($assertion);

$this->assertEquals([$assertion], $this->assertionAggregate->peakAssertions());
Expand All @@ -46,8 +46,8 @@ public function testAddAssertion(): AssertionAggregate

public function testAddAssertions(): void
{
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);

$aggregate = $this->assertionAggregate->addAssertions($assertions);

Expand Down Expand Up @@ -123,18 +123,10 @@ public function testManagerAccessors(): void

public function testCallingAssertWillFetchAssertionFromManager(): void
{
$acl = $this->getMockBuilder(Acl::class)
->getMock();

$role = $this->getMockBuilder(GenericRole::class)
->setConstructorArgs(['test.role'])
->getMock();

$resource = $this->getMockBuilder(GenericResource::class)
->setConstructorArgs(['test.resource'])
->getMock();

$assertion = $this->getMockForAbstractClass(AssertionInterface::class);
$acl = $this->createMock(Acl::class);
$role = $this->createMock(GenericRole::class);
$resource = $this->createMock(GenericResource::class);
$assertion = $this->createMock(AssertionInterface::class);
$assertion->expects($this->once())
->method('assert')
->will($this->returnValue(true));
Expand Down Expand Up @@ -185,20 +177,12 @@ public function testAssertThrowsAnExceptionWhenReferingToNonExistentAssertion():

public function testAssertWithModeAll(): void
{
$acl = $this->getMockBuilder(Acl::class)
->getMock();

$role = $this->getMockBuilder(GenericRole::class)
->setConstructorArgs(['test.role'])
->getMock();

$resource = $this->getMockBuilder(GenericResource::class)
->setConstructorArgs(['test.resource'])
->getMock();

$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$acl = $this->createMock(Acl::class);
$role = $this->createMock(GenericRole::class);
$resource = $this->createMock(GenericResource::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);

$assertions[0]->expects($this->once())
->method('assert')
Expand All @@ -222,20 +206,12 @@ public function testAssertWithModeAll(): void

public function testAssertWithModeAtLeastOne(): void
{
$acl = $this->getMockBuilder(Acl::class)
->getMock();

$role = $this->getMockBuilder(GenericRole::class)
->setConstructorArgs(['test.role'])
->getMock();

$resource = $this->getMockBuilder(GenericResource::class)
->setConstructorArgs(['test.resource'])
->getMock();

$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$acl = $this->createMock(Acl::class);
$role = $this->createMock(GenericRole::class);
$resource = $this->createMock(GenericResource::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);

$assertions[0]->expects($this->once())
->method('assert')
Expand All @@ -260,22 +236,13 @@ public function testAssertWithModeAtLeastOne(): void

public function testDoesNotAssertWithModeAll(): void
{
$acl = $this->getMockBuilder(Acl::class)
->getMock();

$role = $this->getMockBuilder(GenericRole::class)
->setConstructorArgs(['test.role'])
->setMethods(['assert'])
->getMock();

$resource = $this->getMockBuilder(GenericResource::class)
->setConstructorArgs(['test.resource'])
->setMethods(['assert'])
->getMock();
$acl = $this->createMock(Acl::class);
$role = $this->createMock(GenericRole::class);
$resource = $this->createMock(GenericResource::class);

$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);

$assertions[0]->expects($this->once())
->method('assert')
Expand All @@ -299,22 +266,12 @@ public function testDoesNotAssertWithModeAll(): void

public function testDoesNotAssertWithModeAtLeastOne(): void
{
$acl = $this->getMockBuilder(Acl::class)
->getMock();

$role = $this->getMockBuilder(GenericRole::class)
->setConstructorArgs(['test.role'])
->setMethods(['assert'])
->getMock();

$resource = $this->getMockBuilder(GenericResource::class)
->setConstructorArgs(['test.resource'])
->setMethods(['assert'])
->getMock();

$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$assertions[] = $this->getMockForAbstractClass(AssertionInterface::class);
$acl = $this->createMock(Acl::class);
$role = $this->createMock(GenericRole::class);
$resource = $this->createMock(GenericResource::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);
$assertions[] = $this->createMock(AssertionInterface::class);

$assertions[0]->expects($this->once())
->method('assert')
Expand All @@ -339,18 +296,9 @@ public function testDoesNotAssertWithModeAtLeastOne(): void

public function testAssertThrowsAnExceptionWhenNoAssertionIsAggregated(): void
{
$acl = $this->getMockBuilder(Acl::class)
->getMock();

$role = $this->getMockBuilder(GenericRole::class)
->setConstructorArgs(['test.role'])
->setMethods(['assert'])
->getMock();

$resource = $this->getMockBuilder(GenericResource::class)
->setConstructorArgs(['test.resource'])
->setMethods(['assert'])
->getMock();
$acl = $this->createMock(Acl::class);
$role = $this->createMock(GenericRole::class);
$resource = $this->createMock(GenericResource::class);

$this->expectException(RuntimeException::class);

Expand Down
2 changes: 1 addition & 1 deletion test/Assertion/AssertionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp(): void

public function testValidatePlugin(): void
{
$assertion = $this->getMockForAbstractClass(AssertionInterface::class);
$assertion = $this->createMock(AssertionInterface::class);
$this->manager->validate($assertion);

$this->expectException(InvalidServiceException::class);
Expand Down
5 changes: 3 additions & 2 deletions test/Assertion/ExpressionAssertionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Laminas\Permissions\Acl\Role\RoleInterface;
use LaminasTest\Permissions\Acl\TestAsset\ExpressionUseCase\BlogPost;
use LaminasTest\Permissions\Acl\TestAsset\ExpressionUseCase\User;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

use function serialize;
Expand Down Expand Up @@ -73,9 +74,9 @@ public function testExceptionIsRaisedInCaseOfInvalidExpressionOperator(): void
}

/**
* @dataProvider getExpressions
* @param array<string, mixed> $expression
*/
#[DataProvider('getExpressions')]
public function testExpressionsEvaluation(
array $expression,
RoleInterface $role,
Expand All @@ -99,7 +100,7 @@ public function testExpressionsEvaluation(
* assert: bool
* }>
*/
public function getExpressions(): array
public static function getExpressions(): array
{
$author3 = new User([
'username' => 'author3',
Expand Down

0 comments on commit 8198a73

Please sign in to comment.