Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions .github/workflows/bc.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
on:
- pull_request
- push
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'
- 'psalm.xml'
push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'
- 'psalm.xml'

name: backwards compatibility

jobs:
roave_bc_check:
uses: yiisoft/actions/.github/workflows/bc.yml@master
with:
extensions: uopz
os: >-
['ubuntu-latest']
php: >-
Expand Down
74 changes: 9 additions & 65 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -23,68 +24,11 @@ name: build

jobs:
phpunit:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest
- windows-latest

php:
- 8.1
- 8.2
- 8.3

exclude:
- os: windows-latest
php: 8.2

- os: windows-latest
php: 8.3

steps:
- name: Checkout.
uses: actions/checkout@v4

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
with:
coverage: pcov
extensions: uopz
ini-values: date.timezone='UTC'
php-version: ${{ matrix.php }}
tools: composer:v2

- name: Determine composer cache directory on Linux.
if: matrix.os == 'ubuntu-latest'
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Determine composer cache directory on Windows.
if: matrix.os == 'windows-latest'
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Cache dependencies installed with composer.
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-

- name: Update composer.
run: composer self-update

- name: Install dependencies with composer.
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit with code coverage.
run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always --configuration phpunit.xml.dist

- name: Upload coverage to Codecov.
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
uses: yiisoft/actions/.github/workflows/phpunit.yml@master
secrets:
codecovToken: ${{ secrets.CODECOV_TOKEN }}
with:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.1', '8.2', '8.3']
3 changes: 1 addition & 2 deletions .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.3']
extensions: uopz
['8.1', '8.2', '8.3']
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -27,7 +28,6 @@ jobs:
['ubuntu-latest']
php: >-
['8.3']
extensions: uopz
min-covered-msi: 100
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
1 change: 0 additions & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ jobs:
['ubuntu-latest']
php: >-
['8.3']
extensions: uopz
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'phpunit.xml.dist'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -29,4 +30,3 @@ jobs:
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3']
extensions: uopz
18 changes: 7 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@
"yiisoft/var-dumper": "^1.7"
},
"require-dev": {
"ext-uopz": "*",
"maglnet/composer-require-checker": "^4.3",
"phpunit/phpunit": "^10.5.2",
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.45",
"psr/clock": "^1.0",
"rector/rector": "^2.0.11",
"roave/infection-static-analysis-plugin": "^1.18",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.17",
"yiisoft/files": "^1.0"
"roave/infection-static-analysis-plugin": "^1.35",
"spatie/phpunit-watcher": "^1.24",
"vimeo/psalm": "^5.26.1",
"yiisoft/files": "^1.0.2"
},
"autoload": {
"psr-4": {
Expand All @@ -52,10 +51,7 @@
"psr-4": {
"Yiisoft\\Rbac\\Php\\Tests\\": "tests",
"Yiisoft\\Rbac\\Tests\\": "vendor/yiisoft/rbac/tests"
},
"files": [
"tests/bootstrap.php"
]
}
},
"config": {
"sort-packages": true,
Expand Down
7 changes: 6 additions & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
}
},
"mutators": {
"@default": true
"@default": true,
"MethodCallRemoval": {
"ignoreSourceCodeByRegex": [
"\\$this->invalidateScriptCache.*"
]
}
}
}
2 changes: 2 additions & 0 deletions src/FileStorageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ private function saveToFile(array $data): void

/**
* Invalidates precompiled script cache (such as OPCache) for the given file.
*
* @infection-ignore-all
*/
private function invalidateScriptCache(): void
{
Expand Down
1 change: 1 addition & 0 deletions tests/ItemsStorage/CreateNestedDirectory/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/runtime
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Rbac\Php\Tests\ItemsStorage\CreateNestedDirectory;

use PHPUnit\Framework\TestCase;
use Yiisoft\Files\FileHelper;
use Yiisoft\Rbac\Permission;
use Yiisoft\Rbac\Php\ItemsStorage;
use Yiisoft\Rbac\Php\Tests\Support\TestHelper;

use function PHPUnit\Framework\assertFileExists;
use function PHPUnit\Framework\assertSame;

final class CreateNestedDirectoryTest extends TestCase
{
private const RUNTIME_DIRECTORY = __DIR__ . '/runtime';

protected function setUp(): void
{
FileHelper::ensureDirectory(self::RUNTIME_DIRECTORY);
FileHelper::clearDirectory(self::RUNTIME_DIRECTORY);
}

protected function tearDown(): void
{
FileHelper::removeDirectory(self::RUNTIME_DIRECTORY);
}

public function testBase(): void
{
$directory = self::RUNTIME_DIRECTORY . '/test/create/nested/directory';

$storage = new ItemsStorage($directory . '/items.php');
$storage->add(new Permission('createPost'));

assertFileExists($directory . '/items.php');
}

public function testRestoreErrorHandler(): void
{
$directory = self::RUNTIME_DIRECTORY . '/test/create/nested/directory';
$errorHandler = static fn() => true;
set_error_handler($errorHandler);

try {
$storage = new ItemsStorage($directory . '/items.php');
$storage->add(new Permission('createPost'));
$currentErrorHandler = TestHelper::getCurrentErrorHandler();
} finally {
restore_error_handler();
}

assertSame($errorHandler, $currentErrorHandler);
}

/**
* @requires OS Linux
*/
public function testDirectoryPermission(): void
{
$directory = self::RUNTIME_DIRECTORY . '/test/create/nested/directory-permissions';

$storage = new ItemsStorage($directory . '/items.php');
$storage->add(new Permission('createPost'));

$this->assertSame(0755, TestHelper::getDirectoryPermissions($directory));
}
}
Loading