From 212654816d538085ff2122c0f7f914a6e14cf045 Mon Sep 17 00:00:00 2001 From: Ivaylo Mutafov Date: Fri, 1 Sep 2023 10:25:38 +0300 Subject: [PATCH 1/8] Added support for Laravel 10.x (#15) --- composer.json | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 6ef049a..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.1", "illuminate/session": "^10.0", - "mongodb/laravel-mongodb": "^5.0", - "ext-mongodb": "*" - }, - "require-dev": { - "phpunit/phpunit": "^10.0", - "orchestra/testbench": "^8.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": "vendor/bin/phpunit" } } From 17562f5dba10256068a2dc913e154bf7105a2d37 Mon Sep 17 00:00:00 2001 From: Ivaylo Mutafov Date: Tue, 5 Sep 2023 14:19:22 +0300 Subject: [PATCH 2/8] 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 868de6f4a68f084034145a896aa9896d3bee34d9 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/8] 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 25644597804be10c121ffd1809ef88ca4d9fa1d2 Mon Sep 17 00:00:00 2001 From: Ivaylo Mutafov Date: Wed, 5 Feb 2025 16:32:49 +0200 Subject: [PATCH 4/8] 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 27349ae1a5ddd68042ee3ea2901c13aa58d0bb88 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/8] 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 | 8 ++--- composer.json | 13 ++++++- tests/Unit/MongoDbSessionHandlerTest.php | 44 ++++++++++++------------ 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/.github/workflows/run-tests-l10.yml b/.github/workflows/run-tests-l10.yml index dacb918..1f93cbe 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, master ] + branches: [ v5.x ] pull_request: - branches: [ v5.x, master ] + branches: [ v5.x ] 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: 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/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 14b4c1b9f17c949d9c1fa5075a1f5055dd7c7426 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/8] 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 +- tests/Unit/MongoDbSessionHandlerTest.php | 44 ++++++++++++------------ 2 files changed, 23 insertions(+), 23 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/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 7083f505b5ca74a425738b71b1e2038477238332 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/8] 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 c8a9432ecb9082310494b5ae5c4e4ac66445bf21 Mon Sep 17 00:00:00 2001 From: Ivelin Ivanov <9060426+ivosgem@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:46:42 +0300 Subject: [PATCH 8/8] Update Laravel version to 11.x and PHP version to 8.2, adjust workflow and configuration files accordingly --- .../{run-tests-l10.yml => run-tests-l11.yml} | 14 +++++++------- .phprc | 2 +- README.md | 1 + composer.json | 10 +++++----- phpunit.xml | 4 ++-- src/MongoDbSessionHandler.php | 19 ++++++++----------- src/SessionServiceProvider.php | 3 +-- 7 files changed, 25 insertions(+), 28 deletions(-) rename .github/workflows/{run-tests-l10.yml => run-tests-l11.yml} (88%) diff --git a/.github/workflows/run-tests-l10.yml b/.github/workflows/run-tests-l11.yml similarity index 88% rename from .github/workflows/run-tests-l10.yml rename to .github/workflows/run-tests-l11.yml index dacb918..9abc30c 100644 --- a/.github/workflows/run-tests-l10.yml +++ b/.github/workflows/run-tests-l11.yml @@ -1,11 +1,11 @@ -name: "Run Tests - Laravel 10" +name: "Run Tests - Laravel 11" on: push: - branches: [ v5.x, master ] + branches: [ v6.x, master ] pull_request: - branches: [ v5.x, master ] + branches: [ v6.x, master ] jobs: tests: @@ -26,11 +26,11 @@ jobs: strategy: fail-fast: false matrix: - php: [ 8.1 ] - laravel: [ 10.* ] + php: [ 8.2 ] + laravel: [ 11.* ] include: - - laravel: 10.* - testbench: 10.* + - laravel: 11.* + testbench: 11.* name: P${{ matrix.php }} - L${{ matrix.laravel }} diff --git a/.phprc b/.phprc index 6e3833a..a5a984f 100644 --- a/.phprc +++ b/.phprc @@ -1 +1 @@ -php8.1 +php8.2 diff --git a/README.md b/README.md index 3fb89ec..32a0f6f 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** | |-------------------------|-------------------------|---------------------------------------------------| +| 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 | | 8.x | 3.x.x | composer require 1ff/laravel-mongodb-session:^3.0 | diff --git a/composer.json b/composer.json index 6ef049a..2f1f80f 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": "^11.0", "mongodb/laravel-mongodb": "^5.0", "ext-mongodb": "*" }, "require-dev": { - "phpunit/phpunit": "^10.0", - "orchestra/testbench": "^8.0" + "phpunit/phpunit": "^11.0", + "orchestra/testbench": "^9.0" }, "license": "MIT", "authors": [ @@ -42,6 +42,6 @@ } }, "scripts": { - "test": "vendor/bin/phpunit" + "test": "$(head -1 .phprc) ./vendor/bin/phpunit" } } 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), diff --git a/src/SessionServiceProvider.php b/src/SessionServiceProvider.php index f9d75fe..9242b7d 100644 --- a/src/SessionServiceProvider.php +++ b/src/SessionServiceProvider.php @@ -13,10 +13,9 @@ class SessionServiceProvider extends ParentServiceProvider * Register any application services. * * @throws \Exception - * @return void * */ - public function boot() + public function boot(): void { if (config('session.driver') !== 'mongodb') { return;