Skip to content

Commit

Permalink
chore: 🤖 Drop support for stale versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpyw committed Mar 13, 2023
1 parent f4b2c6c commit e9395ca
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 408 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,26 @@ jobs:

strategy:
matrix:
php: [7.3, 7.4, '8.0', 8.1]
php: ['8.0', 8.1, 8.2]
lib:
- { laravel: ^11.0 }
- { laravel: ^10.0 }
- { laravel: ^9.0 }
- { laravel: ^8.0 }
- { laravel: ^7.0 }
- { laravel: ^6.0 }
- { laravel: ^6.0, flags: --prefer-lowest }
exclude:
- { php: 8.1, lib: { laravel: ^7.0 } }
- { php: 8.1, lib: { laravel: ^6.0 } }
- { php: 8.1, lib: { laravel: ^6.0, flags: --prefer-lowest } }
- { php: 8.0, lib: { laravel: ^10.0 } }
- { php: 7.4, lib: { laravel: ^10.0 } }
- { php: 7.4, lib: { laravel: ^9.0 } }
- { php: 7.3, lib: { laravel: ^10.0 } }
- { php: 7.3, lib: { laravel: ^9.0 } }
- { php: 8.0, lib: { laravel: ^11.0 } }
- { php: 8.1, lib: { laravel: ^11.0 } }

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

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

- run: composer require "laravel/framework:${{ matrix.lib.laravel }}" --dev ${{ matrix.lib.flags }}
- run: composer require "laravel/framework:${{ matrix.lib.laravel }}" --dev
- run: mkdir -p build/logs
- run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ composer.lock
/build/logs/
/.idea
.php_cs.cache
.phpunit.result.cache
/.phpunit.cache/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Guarantee database stickiness over the same user's consecutive requests.

## Requirements

- PHP: `^7.3 || ^8.0`
- Laravel: `^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0`
- PHP: `^8.0`
- Laravel: `^9.0 || ^10.0`

## Installing

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
}
},
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.0",
"ext-pdo": "*",
"illuminate/container": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"illuminate/contracts": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"illuminate/queue": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0"
"illuminate/container": "^9.0 || ^10.0 || ^11.0",
"illuminate/contracts": "^9.0 || ^10.0 || ^11.0",
"illuminate/database": "^9.0 || ^10.0 || ^11.0",
"illuminate/queue": "^9.0 || ^10.0 || ^11.0",
"illuminate/support": "^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"orchestra/testbench": "*",
"orchestra/testbench-core": "^4.9 || ^5.9 || >=6.6",
"orchestra/testbench-core": ">=7.0",
"phpunit/phpunit": ">=9.5",
"mockery/mockery": "^1.3.3 || ^1.4.2"
},
Expand Down
21 changes: 6 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
bootstrap="vendor/autoload.php"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
6 changes: 3 additions & 3 deletions src/ApplyingJobInitialization.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function initializeOnResolvedConnections(JobProcessing $event)
{
foreach ($this->db->getConnections() as $connection) {
/* @var \Illuminate\Database\Connection|\Illuminate\Database\ConnectionInterface $connection */
$this->recordsModifiedStates[$connection->getName()] = $this->stickiness->getRecordsModified($connection);
$this->recordsModifiedStates[$connection->getName()] = $connection->hasModifiedRecords();
}

$this->job->initializeOnResolvedConnections($event);
Expand All @@ -73,7 +73,7 @@ public function initializeOnNewConnection(JobProcessing $jobProcessingEvent, Con
{
$connection = $connectionCreatedEvent->connection;

$this->recordsModifiedStates[$connection->getName()] = $this->stickiness->getRecordsModified($connection);
$this->recordsModifiedStates[$connection->getName()] = $connection->hasModifiedRecords();

$this->job->initializeOnNewConnection($jobProcessingEvent, $connectionCreatedEvent);

Expand Down Expand Up @@ -101,7 +101,7 @@ public function __destruct()
foreach ($this->db->getConnections() as $connection) {
/* @var \Illuminate\Database\Connection|\Illuminate\Database\ConnectionInterface $connection */
if (null !== $state = $this->recordsModifiedStates[$connection->getName()] ?? null) {
$this->stickiness->setRecordsModified($connection, $state);
$connection->setRecordModificationState($state);
}
}
}
Expand Down
15 changes: 5 additions & 10 deletions src/JobInitializers/AlwaysFreshInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ public function __construct(StickinessManager $stickiness, DatabaseManager $db)
*/
public function initializeOnResolvedConnections(JobProcessing $event): void
{
if ($this->shouldAssumeModified($event->job)) {
foreach ($this->db->getConnections() as $connection) {
$this->stickiness->setRecordsModified($connection);
}
return;
}
$state = $this->shouldAssumeModified($event->job) ?? false;

foreach ($this->db->getConnections() as $connection) {
$this->stickiness->setRecordsFresh($connection);
$connection->setRecordModificationState($state);
}
}

Expand All @@ -61,8 +56,8 @@ public function initializeOnResolvedConnections(JobProcessing $event): void
*/
public function initializeOnNewConnection(JobProcessing $jobProcessingEvent, ConnectionCreated $connectionCreatedEvent): void
{
$this->shouldAssumeModified($jobProcessingEvent->job)
? $this->stickiness->setRecordsModified($connectionCreatedEvent->connection)
: $this->stickiness->setRecordsFresh($connectionCreatedEvent->connection);
$connectionCreatedEvent->connection->setRecordModificationState(
$this->shouldAssumeModified($jobProcessingEvent->job) ?? false,
);
}
}
15 changes: 5 additions & 10 deletions src/JobInitializers/AlwaysModifiedInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ public function __construct(StickinessManager $stickiness, DatabaseManager $db)
*/
public function initializeOnResolvedConnections(JobProcessing $event): void
{
if ($this->shouldAssumeFresh($event->job)) {
foreach ($this->db->getConnections() as $connection) {
$this->stickiness->setRecordsFresh($connection);
}
return;
}
$state = !($this->shouldAssumeFresh($event->job) ?? false);

foreach ($this->db->getConnections() as $connection) {
$this->stickiness->setRecordsModified($connection);
$connection->setRecordModificationState($state);
}
}

Expand All @@ -61,8 +56,8 @@ public function initializeOnResolvedConnections(JobProcessing $event): void
*/
public function initializeOnNewConnection(JobProcessing $jobProcessingEvent, ConnectionCreated $connectionCreatedEvent): void
{
$this->shouldAssumeFresh($jobProcessingEvent->job)
? $this->stickiness->setRecordsFresh($connectionCreatedEvent->connection)
: $this->stickiness->setRecordsModified($connectionCreatedEvent->connection);
$connectionCreatedEvent->connection->setRecordModificationState(
!($this->shouldAssumeFresh($jobProcessingEvent->job) ?? false),
);
}
}
42 changes: 21 additions & 21 deletions src/StickinessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Mpyw\LaravelCachedDatabaseStickiness;

use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\DatabaseManager;
use Illuminate\Queue\Events\JobProcessing;
use Mpyw\LaravelCachedDatabaseStickiness\JobInitializers\JobInitializerInterface;
use Mpyw\LaravelCachedDatabaseStickiness\StickinessResolvers\StickinessResolverInterface;
use ReflectionProperty;

/**
* Class StickinessManager
Expand Down Expand Up @@ -42,52 +42,52 @@ public function __construct(Container $container, DatabaseManager $db)
/**
* Set DB::$recordsModified state to $bool on $connection.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param bool $bool
* @param \Illuminate\Database\Connection $connection
* @param bool $bool
* @deprecated Directly use Connection::setRecordModificationState().
* @codeCoverageIgnore
*/
public function setRecordsModified(ConnectionInterface $connection, bool $bool = true): void
public function setRecordsModified(Connection $connection, bool $bool = true): void
{
/* @noinspection PhpUnhandledExceptionInspection */
$property = new ReflectionProperty($connection, 'recordsModified');
$property->setAccessible(true);
$property->setValue($connection, $bool);
$connection->setRecordModificationState($bool);
}

/** @noinspection PhpDocMissingThrowsInspection */

/**
* Get DB::$recordsModified state on $connection.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Database\Connection $connection
* @return bool
* @deprecated Directly use Connection::hasModifiedRecords().
* @codeCoverageIgnore
*/
public function getRecordsModified(ConnectionInterface $connection): bool
public function getRecordsModified(Connection $connection): bool
{
/* @noinspection PhpUnhandledExceptionInspection */
$property = new ReflectionProperty($connection, 'recordsModified');
$property->setAccessible(true);
return (bool)$property->getValue($connection);
return $connection->hasModifiedRecords();
}

/**
* Set DB::$recordsModified state to false on $connection.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Database\Connection $connection
* @deprecated Directly use Connection::setRecordsModified().
* @codeCoverageIgnore
*/
public function setRecordsFresh(ConnectionInterface $connection): void
public function setRecordsFresh(Connection $connection): void
{
$this->setRecordsModified($connection, false);
$connection->setRecordModificationState(false);
}

/**
* Resolve DB::$recordsModified state via StickinessResolver on $connection.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Database\Connection $connection
*/
public function resolveRecordsModified(ConnectionInterface $connection): void
public function resolveRecordsModified(Connection $connection): void
{
if (!$this->getRecordsModified($connection) && $this->isRecentlyModified($connection)) {
$this->setRecordsModified($connection);
if (!$connection->hasModifiedRecords() && $this->isRecentlyModified($connection)) {
$connection->setRecordModificationState(true);
}
}

Expand Down
19 changes: 2 additions & 17 deletions src/StickinessResolvers/AuthBasedResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,15 @@ public function markAsModified(ConnectionInterface $connection): void
public function isRecentlyModified(ConnectionInterface $connection): bool
{
/* @noinspection PhpUnhandledExceptionInspection */
return $this->hasUser()
? $this->cache->has(static::getCacheKey($connection, $this->guard->user()))
: false;
return $this->hasUser() && $this->cache->has(static::getCacheKey($connection, $this->guard->user()));
}

/** @noinspection PhpDocMissingThrowsInspection */

/**
* @return bool
*/
protected function hasUser(): bool
{
if (method_exists($this->guard, 'hasUser')) {
return $this->guard->hasUser();
}

if (!property_exists($this->guard, 'user')) {
return false;
}

/* @noinspection PhpUnhandledExceptionInspection */
$property = new ReflectionProperty($this->guard, 'user');
$property->setAccessible(true);
return (bool)$property->getValue($this->guard);
return $this->guard->hasUser();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use ReflectionMethod;
use ReflectionProperty;

abstract class MiddlewareTest extends TestCase
abstract class MiddlewareTestCase extends TestCase
{
/**
* @var null|bool
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Http/Middleware/WithMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Contracts\Cache\Repository as CacheRepository;

class WithMiddlewareTest extends MiddlewareTest
class WithMiddlewareTest extends MiddlewareTestCase
{
protected $withMiddleware = true;

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Http/Middleware/WithoutMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Contracts\Cache\Repository as CacheRepository;

class WithoutMiddlewareTest extends MiddlewareTest
class WithoutMiddlewareTest extends MiddlewareTestCase
{
protected $withMiddleware = false;

Expand Down
15 changes: 5 additions & 10 deletions tests/Feature/InitializingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Mpyw\LaravelCachedDatabaseStickiness\Tests\Stubs\Notifications\ModifiedNotification;
use Orchestra\Testbench\TestCase;
use ReflectionProperty;
use Symfony\Component\Mailer\Transport\TransportInterface;

class InitializingTest extends TestCase
{
Expand Down Expand Up @@ -197,16 +198,10 @@ public function testInitializationForNotifications(): void

public function testInitializationForMailables(): void
{
if (version_compare($this->app->version(), '9.x-dev', '>=')) {
$transport = $this->mock(\Symfony\Component\Mailer\Transport\TransportInterface::class);
$transport->shouldReceive('send')->times(3);
Mail::setSymfonyTransport($transport);
} else {
$swift = $this->mock(\Swift_Mailer::class)->makePartial();
$swift->shouldReceive('send')->times(3)->andReturn(1);
$swift->shouldReceive('getTransport->stop')->times(3);
Mail::setSwiftMailer($swift);
}
$transport = $this->mock(TransportInterface::class);
$transport->shouldReceive('send')->times(3);
assert($transport instanceof TransportInterface);
Mail::setSymfonyTransport($transport);

DB::connection();

Expand Down
Loading

0 comments on commit e9395ca

Please sign in to comment.