Skip to content

Commit

Permalink
Merge pull request #36 from visto9259/update-testing
Browse files Browse the repository at this point in the history
Update testing and doctrine
  • Loading branch information
visto9259 authored Apr 26, 2024
2 parents 7b6b3cd + c8bbd1c commit 40a0f4f
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 82 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Continuous Integration

on:
push:
# Avoid running tests on changes to documentation
paths-ignore:
- 'docs/**'
pull_request:
paths-ignore:
- 'docs/**'

env:
COMPOSER_ARGS: '--no-progress'

jobs:
build:
strategy:
matrix:
php_version: ['8.1', '8.2', '8.3']
deps: ['--prefer-lowest --prefer-dist', '']
include:
- code-coverage: 'yes'
php_version: '8.2'
deps: ''
runs-on: ubuntu-latest

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{matrix.php_version}}

- name: Show PHP version
run: php -v

- uses: actions/checkout@v4
name: Checkout branch

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php_version }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php--${{matrix.php_version}}-
- name: Install/update dependencies
run: composer update ${{matrix.deps}} $COMPOSER_ARGS

- name: Run PHPUnit test suite
if: ${{ matrix.code-coverage != 'yes' }}
run: composer run-script test

- name: Run PHPUnit test suite with coverage
if: ${{ matrix.code-coverage == 'yes' }}
run: composer run-script test-coverage

- name: Upload coverage results to Coverall
if: ${{ matrix.code-coverage == 'yes' }}
uses: coverallsapp/github-action@v2


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
.php_cs.cache
build
.phpunit.result.cache
/.phpunit.cache
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@
"php": "^7.3 || ^8.0",
"laminas/laminas-servicemanager": "^3.3",
"laminas/laminas-stdlib": "^3.1",
"doctrine/persistence": "^2.0"
"doctrine/persistence": "^2.0 || ^3.0"
},
"require-dev": {
"malukenho/docheader": "^0.1.7",
"phpunit/phpunit": "^9.5.0",
"phpunit/phpunit": "^10.0",
"phpspec/prophecy": "^1.10",
"friendsofphp/php-cs-fixer": "^2.9.3",

"php-coveralls/php-coveralls": "^2.0"
"phpspec/prophecy-phpunit": "^2.0",
"friendsofphp/php-cs-fixer": "^3.43",
"php-coveralls/php-coveralls": "^2.0",
"doctrine/collections": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -75,7 +76,8 @@
],
"cs": "php-cs-fixer fix -v --diff --dry-run",
"cs-fix": "php-cs-fixer fix -v --diff",
"test": "phpunit",
"header": "docheader check src test"
"test": "phpunit --colors=always",
"header": "docheader check src test",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
}
25 changes: 16 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" verbose="true" stopOnFailure="false" processIsolation="false" backupGlobals="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="./build/coverage" lowUpperBound="80" highLowerBound="90"/>
</report>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./vendor/autoload.php"
colors="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
displayDetailsOnTestsThatTriggerDeprecations="false"
>
<testsuite name="LmcRbac tests">
<directory>./test</directory>
</testsuite>
<logging/>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
23 changes: 16 additions & 7 deletions test/Assertion/AssertionSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ public function testWhenNoConditionIsGivenAndIsUsed()
$assertionContainer = $this->getMockBuilder(AssertionContainerInterface::class)->getMock();
$assertionSet = new AssertionSet($assertionContainer, ['fooFactory', 'barFactory']);

$assertionContainer->expects($this->at(0))->method('get')->with('fooFactory')->willReturn($fooAssertion);
$assertionContainer->expects($this->at(1))->method('get')->with('barFactory')->willReturn($barAssertion);
$matcher = $this->exactly(2);
$assertionContainer->expects($matcher)
->method('get')
->willReturnCallback(fn (string $key) => match ($key) {
'fooFactory' => $fooAssertion,
'barFactory' => $barAssertion,
});

$this->assertFalse($assertionSet->assert('permission'));

Expand All @@ -98,7 +103,7 @@ public function testAndConditionWillBreakEarlyWithFailure()
$assertionContainer = $this->getMockBuilder(AssertionContainerInterface::class)->getMock();
$assertionSet = new AssertionSet($assertionContainer, ['fooFactory', 'barFactory', 'condition' => AssertionSet::CONDITION_AND]);

$assertionContainer->expects($this->at(0))->method('get')->with('fooFactory')->willReturn($fooAssertion);
$assertionContainer->expects($this->once())->method('get')->with('fooFactory')->willReturn($fooAssertion);

$this->assertFalse($assertionSet->assert('permission'));

Expand All @@ -114,7 +119,7 @@ public function testOrConditionWillBreakEarlyWithSuccess()
$assertionContainer = $this->getMockBuilder(AssertionContainerInterface::class)->getMock();
$assertionSet = new AssertionSet($assertionContainer, ['fooFactory', 'barFactory', 'condition' => AssertionSet::CONDITION_OR]);

$assertionContainer->expects($this->at(0))->method('get')->with('fooFactory')->willReturn($fooAssertion);
$assertionContainer->expects($this->once())->method('get')->with('fooFactory')->willReturn($fooAssertion);

$this->assertTrue($assertionSet->assert('permission'));

Expand Down Expand Up @@ -189,8 +194,12 @@ public function testUsesAssertionsAsArrays()
$assertionContainer = $this->getMockBuilder(AssertionContainerInterface::class)->getMock();
$assertionSet = new AssertionSet($assertionContainer, ['fooFactory', ['barFactory']]);

$assertionContainer->expects($this->at(0))->method('get')->with('fooFactory')->willReturn($fooAssertion);
$assertionContainer->expects($this->at(1))->method('get')->with('barFactory')->willReturn($barAssertion);
$assertionContainer->expects($this->exactly(2))
->method('get')
->willReturnCallback(fn (string $key) => match ($key) {
'fooFactory' => $fooAssertion,
'barFactory' => $barAssertion,
});

$this->assertTrue($assertionSet->assert('permission'));

Expand Down Expand Up @@ -235,7 +244,7 @@ private function assertionsCalled(array $assertions, array $assertionCalledCount
}
}

public function dpMatrix()
static public function dpMatrix(): array
{
return [
// no assertions will fail
Expand Down
3 changes: 3 additions & 0 deletions test/Container/AuthorizationServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
use LmcRbac\Service\AuthorizationService;
use LmcRbac\Service\RoleServiceInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Container\ContainerInterface;

/**
* @covers \LmcRbac\Container\AuthorizationServiceFactory
*/
class AuthorizationServiceFactoryTest extends TestCase
{
use ProphecyTrait;

public function testCanCreateAuthorizationService(): void
{
$container = $this->prophesize(ContainerInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion test/Service/AuthorizationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
class AuthorizationServiceTest extends TestCase
{
public function grantedProvider(): array
static function grantedProvider(): array
{
return [
// Simple is granted
Expand Down
3 changes: 3 additions & 0 deletions test/Service/RoleServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
use LmcRbacTest\Asset\Identity;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;

/**
* @covers \LmcRbac\Service\RoleService
*/
class RoleServiceTest extends TestCase
{
use ProphecyTrait;

public function testReturnGuestRoleIfNoIdentityIsGiven(): void
{
$roleService = new RoleService(new InMemoryRoleProvider([]), 'guest');
Expand Down

0 comments on commit 40a0f4f

Please sign in to comment.