From f0b51b2147eafc1cba9a0298a0eeff7be8e15348 Mon Sep 17 00:00:00 2001 From: Ivaylo Mutafov Date: Fri, 1 Sep 2023 10:25:38 +0300 Subject: [PATCH 1/9] Added support for Laravel 10.x (#15) --- composer.json | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 2f1f80f..54b388c 100644 --- a/composer.json +++ b/composer.json @@ -2,15 +2,11 @@ "name": "1ff/laravel-mongodb-session", "description": "A mongodb session driver for laravel", "type": "library", + "version": "5.0.0", "require": { - "php": "^8.2", - "illuminate/session": "^11.0", - "mongodb/laravel-mongodb": "^5.0", - "ext-mongodb": "*" - }, - "require-dev": { - "phpunit/phpunit": "^11.0", - "orchestra/testbench": "^9.0" + "php": "^8.1", + "illuminate/session": "^10.0", + "mongodb/laravel-mongodb": "dev-master" }, "license": "MIT", "authors": [ @@ -29,19 +25,11 @@ "ForFit\\Session\\": "src" } }, - "autoload-dev": { - "psr-4": { - "ForFit\\Session\\Tests\\": "tests" - } - }, "extra": { "laravel": { "providers": [ "ForFit\\Session\\SessionServiceProvider" ] } - }, - "scripts": { - "test": "$(head -1 .phprc) ./vendor/bin/phpunit" } } From 7540c3b719e741baa3027433981ffa3a1fd16e94 Mon Sep 17 00:00:00 2001 From: Ivaylo Mutafov Date: Tue, 5 Sep 2023 14:19:22 +0300 Subject: [PATCH 2/9] Updated mongodb/laravel-mongodb package (#16) --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 54b388c..d56f5da 100644 --- a/composer.json +++ b/composer.json @@ -2,11 +2,11 @@ "name": "1ff/laravel-mongodb-session", "description": "A mongodb session driver for laravel", "type": "library", - "version": "5.0.0", + "version": "5.0.1", "require": { "php": "^8.1", "illuminate/session": "^10.0", - "mongodb/laravel-mongodb": "dev-master" + "mongodb/laravel-mongodb": "4.0.0-ALPHA2" }, "license": "MIT", "authors": [ From aa11deb6f39ee09884c10a36ff117c0adee5bc57 Mon Sep 17 00:00:00 2001 From: Ivelin Ivanov <9060426+ivosgem@users.noreply.github.com> Date: Wed, 5 Feb 2025 15:56:15 +0200 Subject: [PATCH 3/9] Refactor method signatures in MongoDbSessionHandler for clarity and type safety. Add .editorconfig for consistent coding style across files. Update composer.json to include ext-mongodb requirement. (#23) --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d56f5da..d0fc37e 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "require": { "php": "^8.1", "illuminate/session": "^10.0", - "mongodb/laravel-mongodb": "4.0.0-ALPHA2" + "mongodb/laravel-mongodb": "4.0.0-ALPHA2", + "ext-mongodb": "*" }, "license": "MIT", "authors": [ From ab81fb008ba5c9e5fa502421b08c0ad63732aca9 Mon Sep 17 00:00:00 2001 From: Ivaylo Mutafov Date: Wed, 5 Feb 2025 16:32:49 +0200 Subject: [PATCH 4/9] V5.x rebase (#25) * v5.x to master (#17) * Added support for Laravel 10.x (#15) * Updated mongodb/laravel-mongodb package (#16) # Conflicts: # composer.json * Update laravel mongodb to rc1 (#18) * Added support for Laravel 10.x (#15) * Updated mongodb/laravel-mongodb package (#16) * Updated mongodb/laravel-mongodb to rc1. * Updated mongodb/laravel-mongodb to stable version 4. (#19) * Changed package version --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d0fc37e..3a86eee 100644 --- a/composer.json +++ b/composer.json @@ -2,11 +2,11 @@ "name": "1ff/laravel-mongodb-session", "description": "A mongodb session driver for laravel", "type": "library", - "version": "5.0.1", + "version": "5.0.4", "require": { "php": "^8.1", "illuminate/session": "^10.0", - "mongodb/laravel-mongodb": "4.0.0-ALPHA2", + "mongodb/laravel-mongodb": "^4.0", "ext-mongodb": "*" }, "license": "MIT", From 49965c91bb3279e103b7380d760a62adc52582ea Mon Sep 17 00:00:00 2001 From: Ivelin Ivanov <9060426+ivosgem@users.noreply.github.com> Date: Fri, 25 Apr 2025 13:54:40 +0300 Subject: [PATCH 5/9] Update deprecated MongoDB read preference constants to use current values (#28) * Update deprecated MongoDB read preference constants to use current values * Bump version to 5.0.5 in composer.json for updated dependencies * Update session testing suite, add MongoDB test cases, and configure PHPUnit - Enhance `.gitignore` to exclude `.phpunit.cache`. - Update GitHub workflow to include Testbench version for Laravel 10.x. - Create new feature tests: `TestHelperIntegrationTest`, `HttpSessionTest`, and `MongoDbSessionHandlerTest` to validate session handling with MongoDB. - Refactor MongoDB session command files to remove unnecessary docblocks. - Document testing process in `README.md`, including setup and expected results. - Add basic PHPUnit configuration file. - Define session environment in the base `TestCase`. - Ensure session operations like reading, writing, and destruction are tested against MongoDB. * Update GitHub Actions workflow to use MongoDB 7 and improve caching - Add MongoDB 7 service to CI workflow - Upgrade checkout action to v3 - Include MongoDB extension in PHP setup - Implement Composer dependency caching for faster builds - Modify composer install command for better performance - Set environment variables for MongoDB connection during test execution - Update README.md to reflect changes in the CI process * Remove deprecated MongoDB version constraint from composer.json --- .github/workflows/run-tests-l10.yml | 67 ++++++++++++++++++++++++ composer.json | 13 ++++- phpunit.xml | 4 +- tests/Unit/MongoDbSessionHandlerTest.php | 44 ++++++++-------- 4 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/run-tests-l10.yml diff --git a/.github/workflows/run-tests-l10.yml b/.github/workflows/run-tests-l10.yml new file mode 100644 index 0000000..1f93cbe --- /dev/null +++ b/.github/workflows/run-tests-l10.yml @@ -0,0 +1,67 @@ +name: "Run Tests - Laravel 10" + +on: + push: + branches: [ v5.x ] + + pull_request: + branches: [ v5.x ] + +jobs: + tests: + + runs-on: ubuntu-latest + + services: + mongodb: + image: mongo:7 + ports: + - 27017:27017 + options: >- + --health-cmd="mongosh --quiet --eval 'db.runCommand({ping:1})'" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + strategy: + fail-fast: false + matrix: + php: [ 8.1 ] + laravel: [ 10.* ] + include: + - laravel: 10.* + testbench: 10.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: pdo, sqlite, pdo_sqlite, mongodb + coverage: none + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction --no-progress + + - name: Execute tests + run: vendor/bin/phpunit + env: + MONGODB_HOST: 127.0.0.1 + MONGODB_PORT: 27017 + MONGODB_DATABASE: laravel_session_test diff --git a/composer.json b/composer.json index 3a86eee..459bdda 100644 --- a/composer.json +++ b/composer.json @@ -2,13 +2,16 @@ "name": "1ff/laravel-mongodb-session", "description": "A mongodb session driver for laravel", "type": "library", - "version": "5.0.4", "require": { "php": "^8.1", "illuminate/session": "^10.0", "mongodb/laravel-mongodb": "^4.0", "ext-mongodb": "*" }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "orchestra/testbench": "^8.0" + }, "license": "MIT", "authors": [ { @@ -26,11 +29,19 @@ "ForFit\\Session\\": "src" } }, + "autoload-dev": { + "psr-4": { + "ForFit\\Session\\Tests\\": "tests" + } + }, "extra": { "laravel": { "providers": [ "ForFit\\Session\\SessionServiceProvider" ] } + }, + "scripts": { + "test": "vendor/bin/phpunit" } } diff --git a/phpunit.xml b/phpunit.xml index 2f53548..41f3b6a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ colors="true" processIsolation="false" stopOnFailure="false" - xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false" > @@ -24,4 +24,4 @@ - + \ No newline at end of file diff --git a/tests/Unit/MongoDbSessionHandlerTest.php b/tests/Unit/MongoDbSessionHandlerTest.php index a008442..2c2c784 100644 --- a/tests/Unit/MongoDbSessionHandlerTest.php +++ b/tests/Unit/MongoDbSessionHandlerTest.php @@ -4,8 +4,8 @@ use ForFit\Session\MongoDbSessionHandler; use ForFit\Session\Tests\TestCase; -use Illuminate\Support\Carbon; use MongoDB\BSON\Binary; +use MongoDB\BSON\UTCDateTime; class MongoDbSessionHandlerTest extends TestCase { @@ -13,23 +13,23 @@ class MongoDbSessionHandlerTest extends TestCase * @var MongoDbSessionHandler */ protected $handler; - + /** * @var string */ protected $sessionId; - + /** * Set up the test environment. */ protected function setUp(): void { parent::setUp(); - + $this->handler = $this->app['session.store']->getHandler(); $this->sessionId = md5(uniqid('test_session')); } - + /** * Test the open method */ @@ -37,7 +37,7 @@ public function test_open_method(): void { $this->assertTrue($this->handler->open('path', 'name')); } - + /** * Test the close method */ @@ -45,7 +45,7 @@ public function test_close_method(): void { $this->assertTrue($this->handler->close()); } - + /** * Test reading non-existent session */ @@ -53,33 +53,33 @@ public function test_read_non_existent_session(): void { $this->assertEquals('', $this->handler->read('non_existent_id')); } - + /** * Test write and read session */ public function test_write_and_read_session(): void { $data = 'test_data_' . time(); - + // Write session data $this->assertTrue($this->handler->write($this->sessionId, $data)); - + // Read it back $readData = $this->handler->read($this->sessionId); - + $this->assertEquals($data, $readData); - + // Check database directly $session = $this->app['db']->table(config('session.table')) ->where('_id', $this->sessionId) ->first(); - + $this->assertNotNull($session); - $this->assertInstanceOf(Binary::class, $session->payload); - $this->assertInstanceOf(Carbon::class, $session->expires_at); - $this->assertInstanceOf(Carbon::class, $session->last_activity); + $this->assertInstanceOf(Binary::class, $session['payload']); + $this->assertInstanceOf(UTCDateTime::class, $session['expires_at']); + $this->assertInstanceOf(UTCDateTime::class, $session['last_activity']); } - + /** * Test destroy session */ @@ -87,23 +87,23 @@ public function test_destroy_session(): void { // First write a session $this->handler->write($this->sessionId, 'test_data'); - + // Verify it exists $exists = $this->app['db']->table(config('session.table')) ->where('_id', $this->sessionId) ->exists(); $this->assertTrue($exists); - + // Now destroy it $this->assertTrue($this->handler->destroy($this->sessionId)); - + // Verify it's gone $exists = $this->app['db']->table(config('session.table')) ->where('_id', $this->sessionId) ->exists(); $this->assertFalse($exists); } - + /** * Test garbage collection */ @@ -112,4 +112,4 @@ public function test_garbage_collection(): void // gc should return a truthy value as it's handled by MongoDB TTL index $this->assertNotFalse($this->handler->gc(100)); } -} +} \ No newline at end of file From 0ec6933f8b89e99a23ca9b2f3225325ec1aedb2e Mon Sep 17 00:00:00 2001 From: Ivelin Ivanov <9060426+ivosgem@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:10:27 +0300 Subject: [PATCH 6/9] Update mongodb/laravel-mongodb package to version 5.0 in composer.json (#27) * Update mongodb/laravel-mongodb package to version 5.0 in composer.json * Update MongoDB commands and improve session handling Refactor the command to use `getDatabase()` instead of `getMongoDB()`. Update payload access in `MongoDbSessionHandler` from array syntax to object syntax for better readability. Adjust test assertions to match the new access methodology and ensure compatibility with Carbon instances for expiration and last activity timestamps. Clean up formatting inconsistencies throughout the code. * Update MongoDB connection method to use getDatabase() instead of getMongoDB() in MongodbSessionIndex command --- composer.json | 2 +- src/MongoDbSessionHandler.php | 19 +++++----- tests/Unit/MongoDbSessionHandlerTest.php | 44 ++++++++++++------------ 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 459bdda..6ef049a 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "php": "^8.1", "illuminate/session": "^10.0", - "mongodb/laravel-mongodb": "^4.0", + "mongodb/laravel-mongodb": "^5.0", "ext-mongodb": "*" }, "require-dev": { diff --git a/src/MongoDbSessionHandler.php b/src/MongoDbSessionHandler.php index 00465c3..507fc46 100644 --- a/src/MongoDbSessionHandler.php +++ b/src/MongoDbSessionHandler.php @@ -2,8 +2,6 @@ namespace ForFit\Session; -use Illuminate\Database\ConnectionInterface; -use Illuminate\Database\Query\Builder; use MongoDB\BSON\Binary; use MongoDB\BSON\UTCDateTime; use MongoDB\Driver\Exception\BulkWriteException; @@ -11,11 +9,16 @@ class MongoDbSessionHandler implements SessionHandlerInterface { - protected ConnectionInterface $connection; - protected int $minutes; - protected string $table; + protected $connection; + protected $minutes; + protected $table; - public function __construct(ConnectionInterface $connection, string $table = 'sessions', int $minutes = 60) + /** + * @param \Illuminate\Database\ConnectionInterface $connection + * @param string $table + * @param integer $minutes + */ + public function __construct($connection, $table = 'sessions', $minutes = 60) { $this->connection = $connection; $this->minutes = (int)$minutes; @@ -86,7 +89,7 @@ public function gc($max_lifetime): false|int * Returns the query builder * */ - protected function query(): Builder + protected function query() { return $this->connection->table($this->table); } @@ -97,7 +100,7 @@ protected function query(): Builder * @param string|null $data * @return array */ - protected function buildPayload($data): array + protected function buildPayload($data) { return [ 'payload' => new Binary($data, Binary::TYPE_OLD_BINARY), diff --git a/tests/Unit/MongoDbSessionHandlerTest.php b/tests/Unit/MongoDbSessionHandlerTest.php index 2c2c784..a008442 100644 --- a/tests/Unit/MongoDbSessionHandlerTest.php +++ b/tests/Unit/MongoDbSessionHandlerTest.php @@ -4,8 +4,8 @@ use ForFit\Session\MongoDbSessionHandler; use ForFit\Session\Tests\TestCase; +use Illuminate\Support\Carbon; use MongoDB\BSON\Binary; -use MongoDB\BSON\UTCDateTime; class MongoDbSessionHandlerTest extends TestCase { @@ -13,23 +13,23 @@ class MongoDbSessionHandlerTest extends TestCase * @var MongoDbSessionHandler */ protected $handler; - + /** * @var string */ protected $sessionId; - + /** * Set up the test environment. */ protected function setUp(): void { parent::setUp(); - + $this->handler = $this->app['session.store']->getHandler(); $this->sessionId = md5(uniqid('test_session')); } - + /** * Test the open method */ @@ -37,7 +37,7 @@ public function test_open_method(): void { $this->assertTrue($this->handler->open('path', 'name')); } - + /** * Test the close method */ @@ -45,7 +45,7 @@ public function test_close_method(): void { $this->assertTrue($this->handler->close()); } - + /** * Test reading non-existent session */ @@ -53,33 +53,33 @@ public function test_read_non_existent_session(): void { $this->assertEquals('', $this->handler->read('non_existent_id')); } - + /** * Test write and read session */ public function test_write_and_read_session(): void { $data = 'test_data_' . time(); - + // Write session data $this->assertTrue($this->handler->write($this->sessionId, $data)); - + // Read it back $readData = $this->handler->read($this->sessionId); - + $this->assertEquals($data, $readData); - + // Check database directly $session = $this->app['db']->table(config('session.table')) ->where('_id', $this->sessionId) ->first(); - + $this->assertNotNull($session); - $this->assertInstanceOf(Binary::class, $session['payload']); - $this->assertInstanceOf(UTCDateTime::class, $session['expires_at']); - $this->assertInstanceOf(UTCDateTime::class, $session['last_activity']); + $this->assertInstanceOf(Binary::class, $session->payload); + $this->assertInstanceOf(Carbon::class, $session->expires_at); + $this->assertInstanceOf(Carbon::class, $session->last_activity); } - + /** * Test destroy session */ @@ -87,23 +87,23 @@ public function test_destroy_session(): void { // First write a session $this->handler->write($this->sessionId, 'test_data'); - + // Verify it exists $exists = $this->app['db']->table(config('session.table')) ->where('_id', $this->sessionId) ->exists(); $this->assertTrue($exists); - + // Now destroy it $this->assertTrue($this->handler->destroy($this->sessionId)); - + // Verify it's gone $exists = $this->app['db']->table(config('session.table')) ->where('_id', $this->sessionId) ->exists(); $this->assertFalse($exists); } - + /** * Test garbage collection */ @@ -112,4 +112,4 @@ public function test_garbage_collection(): void // gc should return a truthy value as it's handled by MongoDB TTL index $this->assertNotFalse($this->handler->gc(100)); } -} \ No newline at end of file +} From 50b111e760b732b46254c0061fa2d6f1664bb2da Mon Sep 17 00:00:00 2001 From: Ivelin Ivanov <9060426+ivosgem@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:29:19 +0300 Subject: [PATCH 7/9] Update GitHub Actions workflow to trigger on the master branch --- .github/workflows/run-tests-l10.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-tests-l10.yml b/.github/workflows/run-tests-l10.yml index 1f93cbe..dacb918 100644 --- a/.github/workflows/run-tests-l10.yml +++ b/.github/workflows/run-tests-l10.yml @@ -2,16 +2,16 @@ name: "Run Tests - Laravel 10" on: push: - branches: [ v5.x ] + branches: [ v5.x, master ] pull_request: - branches: [ v5.x ] + branches: [ v5.x, master ] jobs: tests: runs-on: ubuntu-latest - + services: mongodb: image: mongo:7 @@ -22,7 +22,7 @@ jobs: --health-interval=10s --health-timeout=5s --health-retries=3 - + strategy: fail-fast: false matrix: From ae48d906fc657f2a2aac54cb23db40cc20cf0552 Mon Sep 17 00:00:00 2001 From: Ivelin Ivanov <9060426+ivosgem@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:55:59 +0300 Subject: [PATCH 8/9] Update Laravel version to 12.x in workflows and dependencies - Rename GitHub Actions workflow for Laravel version 12 - Change branch references from v6.x to v7.x - Update Laravel dependency from 11.* to 12.* - Adjust TestBench requirement to version 10.x in composer.json - Modify README to reflect updated package installation command for Laravel 12.x --- .../workflows/{run-tests-l11.yml => run-tests-l12.yml} | 10 +++++----- README.md | 1 + composer.json | 10 +++++----- 3 files changed, 11 insertions(+), 10 deletions(-) rename .github/workflows/{run-tests-l11.yml => run-tests-l12.yml} (91%) diff --git a/.github/workflows/run-tests-l11.yml b/.github/workflows/run-tests-l12.yml similarity index 91% rename from .github/workflows/run-tests-l11.yml rename to .github/workflows/run-tests-l12.yml index 9abc30c..9e927b4 100644 --- a/.github/workflows/run-tests-l11.yml +++ b/.github/workflows/run-tests-l12.yml @@ -2,10 +2,10 @@ name: "Run Tests - Laravel 11" on: push: - branches: [ v6.x, master ] + branches: [ v7.x, master ] pull_request: - branches: [ v6.x, master ] + branches: [ v7.x, master ] jobs: tests: @@ -27,10 +27,10 @@ jobs: fail-fast: false matrix: php: [ 8.2 ] - laravel: [ 11.* ] + laravel: [ 12.* ] include: - - laravel: 11.* - testbench: 11.* + - laravel: 12.* + testbench: 12.* name: P${{ matrix.php }} - L${{ matrix.laravel }} diff --git a/README.md b/README.md index 32a0f6f..eccc01c 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ A MongoDB session driver for Laravel | **Laravel
Version** | **Package
Version** | **Install using
this command** | |-------------------------|-------------------------|---------------------------------------------------| +| 12.x | 7.x.x | composer require 1ff/laravel-mongodb-session:^7.0 | | 11.x | 6.x.x | composer require 1ff/laravel-mongodb-session:^6.0 | | 10.x | 5.x.x | composer require 1ff/laravel-mongodb-session:^5.0 | | 9.x | 4.x.x | composer require 1ff/laravel-mongodb-session:^4.0 | diff --git a/composer.json b/composer.json index 6ef049a..c56996f 100644 --- a/composer.json +++ b/composer.json @@ -3,14 +3,14 @@ "description": "A mongodb session driver for laravel", "type": "library", "require": { - "php": "^8.1", - "illuminate/session": "^10.0", + "php": "^8.2", + "illuminate/session": "^12.0", "mongodb/laravel-mongodb": "^5.0", "ext-mongodb": "*" }, "require-dev": { - "phpunit/phpunit": "^10.0", - "orchestra/testbench": "^8.0" + "phpunit/phpunit": "^11.0", + "orchestra/testbench": "^10.0" }, "license": "MIT", "authors": [ @@ -42,6 +42,6 @@ } }, "scripts": { - "test": "vendor/bin/phpunit" + "test": "$(head -1 .phprc) ./vendor/bin/phpunit" } } From 1d187f2ea3b6356cf64200897056eede775c3a28 Mon Sep 17 00:00:00 2001 From: Ivelin Ivanov <9060426+ivosgem@users.noreply.github.com> Date: Tue, 20 May 2025 08:48:03 +0300 Subject: [PATCH 9/9] Remove obsolete Laravel 10 test workflow, update PHPUnit schema, and refactor MongoDbSessionHandler - Delete the GitHub Actions workflow for running Laravel 10 tests as it is no longer needed. - Update the PHPUnit XML schema location to version 12.0 for compatibility. - Refactor `MongoDbSessionHandler` class constructor and method signatures to use type hints for improved type safety and clarity. --- .github/workflows/run-tests-l10.yml | 67 ----------------------------- .github/workflows/run-tests-l12.yml | 4 +- phpunit.xml | 4 +- src/MongoDbSessionHandler.php | 19 ++++---- 4 files changed, 12 insertions(+), 82 deletions(-) delete mode 100644 .github/workflows/run-tests-l10.yml diff --git a/.github/workflows/run-tests-l10.yml b/.github/workflows/run-tests-l10.yml deleted file mode 100644 index dacb918..0000000 --- a/.github/workflows/run-tests-l10.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: "Run Tests - Laravel 10" - -on: - push: - branches: [ v5.x, master ] - - pull_request: - branches: [ v5.x, master ] - -jobs: - tests: - - runs-on: ubuntu-latest - - services: - mongodb: - image: mongo:7 - ports: - - 27017:27017 - options: >- - --health-cmd="mongosh --quiet --eval 'db.runCommand({ping:1})'" - --health-interval=10s - --health-timeout=5s - --health-retries=3 - - strategy: - fail-fast: false - matrix: - php: [ 8.1 ] - laravel: [ 10.* ] - include: - - laravel: 10.* - testbench: 10.* - - name: P${{ matrix.php }} - L${{ matrix.laravel }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: pdo, sqlite, pdo_sqlite, mongodb - coverage: none - - - name: Get composer cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install Dependencies - run: composer install --prefer-dist --no-interaction --no-progress - - - name: Execute tests - run: vendor/bin/phpunit - env: - MONGODB_HOST: 127.0.0.1 - MONGODB_PORT: 27017 - MONGODB_DATABASE: laravel_session_test diff --git a/.github/workflows/run-tests-l12.yml b/.github/workflows/run-tests-l12.yml index 9e927b4..7a64ac9 100644 --- a/.github/workflows/run-tests-l12.yml +++ b/.github/workflows/run-tests-l12.yml @@ -1,4 +1,4 @@ -name: "Run Tests - Laravel 11" +name: "Run Tests - Laravel 12" on: push: @@ -30,7 +30,7 @@ jobs: laravel: [ 12.* ] include: - laravel: 12.* - testbench: 12.* + testbench: 10.* name: P${{ matrix.php }} - L${{ matrix.laravel }} diff --git a/phpunit.xml b/phpunit.xml index 41f3b6a..2f53548 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ colors="true" processIsolation="false" stopOnFailure="false" - xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false" > @@ -24,4 +24,4 @@ - \ No newline at end of file + diff --git a/src/MongoDbSessionHandler.php b/src/MongoDbSessionHandler.php index 507fc46..00465c3 100644 --- a/src/MongoDbSessionHandler.php +++ b/src/MongoDbSessionHandler.php @@ -2,6 +2,8 @@ namespace ForFit\Session; +use Illuminate\Database\ConnectionInterface; +use Illuminate\Database\Query\Builder; use MongoDB\BSON\Binary; use MongoDB\BSON\UTCDateTime; use MongoDB\Driver\Exception\BulkWriteException; @@ -9,16 +11,11 @@ class MongoDbSessionHandler implements SessionHandlerInterface { - protected $connection; - protected $minutes; - protected $table; + protected ConnectionInterface $connection; + protected int $minutes; + protected string $table; - /** - * @param \Illuminate\Database\ConnectionInterface $connection - * @param string $table - * @param integer $minutes - */ - public function __construct($connection, $table = 'sessions', $minutes = 60) + public function __construct(ConnectionInterface $connection, string $table = 'sessions', int $minutes = 60) { $this->connection = $connection; $this->minutes = (int)$minutes; @@ -89,7 +86,7 @@ public function gc($max_lifetime): false|int * Returns the query builder * */ - protected function query() + protected function query(): Builder { return $this->connection->table($this->table); } @@ -100,7 +97,7 @@ protected function query() * @param string|null $data * @return array */ - protected function buildPayload($data) + protected function buildPayload($data): array { return [ 'payload' => new Binary($data, Binary::TYPE_OLD_BINARY),