Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: upgrade to PHP 8.0 and PHP-Casbin 4.0 #6

Merged
merged 1 commit into from
Nov 29, 2024
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
8 changes: 3 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ 7.2, 7.3,7.4,8.0 ]
php: [8.1, 8.2, 8.3]

stability: [ prefer-lowest, prefer-stable ]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
name: PHP ${{ matrix.php }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -57,7 +55,7 @@ jobs:
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: ${{ runner.os }} - ${{ matrix.php }}
run: |
composer global require php-coveralls/php-coveralls:^2.4
composer global require php-coveralls/php-coveralls:^2.7
php-coveralls --coverage_clover=build/logs/clover.xml -v

upload-coverage:
Expand Down
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@
"test": "vendor/bin/phpunit"
},
"require": {
"php": ">=7.2",
"codeigniter4/framework": "^4",
"casbin/casbin": "^3.21.6",
"casbin/psr3-bridge": "^1.1"
"php": "^8.1",
"codeigniter4/framework": "^4.5",
"casbin/casbin": "^4.0.2"
},
"autoload": {
"psr-4": {
"Casbin\\CodeIgniter\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^7.0|^8.0|^9.0",
"php-coveralls/php-coveralls": "^2.1"
"phpunit/phpunit": "^10.0|^11.0"
},
"autoload-dev": {
"psr-4": {
Expand Down
29 changes: 17 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<phpunit bootstrap="vendor/codeigniter4/framework/system/Test/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
Expand All @@ -14,15 +11,23 @@
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-html" target="build/html"/>
</logging>

<coverage includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/html" lowUpperBound="50" highLowerBound="90"/>
</report>
</coverage>

<source>
<include>
<directory>./src</directory>
</include>
</source>

<php>
<env name="app.baseURL" value="http://example.com"/>
<env name="database.tests.hostname" value="127.0.0.1"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Config/Enforcer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class Enforcer extends BaseConfig
// changes whether Casbin will log messages to the Logger.
'enabled' => false,

// Casbin Logger
'logger' => \Casbin\CodeIgniter\Logger::class,
// Casbin Logger, Supported: \Psr\Log\LoggerInterface|string
'logger' => 'logger',
],

'cache' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Services extends BaseService
*
* @return \Casbin\CodeIgniter\EnforcerManager
*/
public static function enforcer(Enforcer $config = null, bool $getShared = true)
public static function enforcer(?Enforcer $config = null, bool $getShared = true)
{
if ($getShared) {
return static::getSharedInstance('enforcer', $config);
Expand Down
10 changes: 8 additions & 2 deletions src/EnforcerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Casbin\Enforcer;
use Casbin\Model\Model;
use Casbin\Log\Log;
use Casbin\Log\Logger\DefaultLogger;
use Config\Services;
use InvalidArgumentException;
use Casbin\CodeIgniter\Config\Enforcer as EnforcerConfig;

Expand Down Expand Up @@ -75,7 +77,11 @@ protected function resolve($name)
}

if ($logger = $config['log']['logger']) {
Log::setLogger(new $logger());
if (is_string($logger)) {
$logger = new DefaultLogger(Services::$logger());
}

Log::setLogger($logger);
}

$model = new Model();
Expand All @@ -92,7 +98,7 @@ protected function resolve($name)
}
}

return new Enforcer($model, $adapter, $config['log']['enabled']);
return new Enforcer($model, $adapter, $logger, $config['log']['enabled']);
}

/**
Expand Down
18 changes: 0 additions & 18 deletions src/Logger.php

This file was deleted.

7 changes: 5 additions & 2 deletions tests/EnforcerManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

namespace Casbin\CodeIgniter\Tests;

use CodeIgniter\Test\CIDatabaseTestCase;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use Config\Services
;
use Config\Autoload;
use Config\Modules;

class EnforcerManagerTest extends CIDatabaseTestCase
class EnforcerManagerTest extends CIUnitTestCase
{
use DatabaseTestTrait;

protected function createApplication()
{
$app = parent::createApplication();
Expand Down