Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 27349ae

Browse files
committed
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
1 parent 2564459 commit 27349ae

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

.github/workflows/run-tests-l10.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ name: "Run Tests - Laravel 10"
22

33
on:
44
push:
5-
branches: [ v5.x, master ]
5+
branches: [ v5.x ]
66

77
pull_request:
8-
branches: [ v5.x, master ]
8+
branches: [ v5.x ]
99

1010
jobs:
1111
tests:
1212

1313
runs-on: ubuntu-latest
14-
14+
1515
services:
1616
mongodb:
1717
image: mongo:7
@@ -22,7 +22,7 @@ jobs:
2222
--health-interval=10s
2323
--health-timeout=5s
2424
--health-retries=3
25-
25+
2626
strategy:
2727
fail-fast: false
2828
matrix:

composer.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
"name": "1ff/laravel-mongodb-session",
33
"description": "A mongodb session driver for laravel",
44
"type": "library",
5-
"version": "5.0.4",
65
"require": {
76
"php": "^8.1",
87
"illuminate/session": "^10.0",
98
"mongodb/laravel-mongodb": "^4.0",
109
"ext-mongodb": "*"
1110
},
11+
"require-dev": {
12+
"phpunit/phpunit": "^10.0",
13+
"orchestra/testbench": "^8.0"
14+
},
1215
"license": "MIT",
1316
"authors": [
1417
{
@@ -26,11 +29,19 @@
2629
"ForFit\\Session\\": "src"
2730
}
2831
},
32+
"autoload-dev": {
33+
"psr-4": {
34+
"ForFit\\Session\\Tests\\": "tests"
35+
}
36+
},
2937
"extra": {
3038
"laravel": {
3139
"providers": [
3240
"ForFit\\Session\\SessionServiceProvider"
3341
]
3442
}
43+
},
44+
"scripts": {
45+
"test": "vendor/bin/phpunit"
3546
}
3647
}

tests/Unit/MongoDbSessionHandlerTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,106 +4,106 @@
44

55
use ForFit\Session\MongoDbSessionHandler;
66
use ForFit\Session\Tests\TestCase;
7-
use Illuminate\Support\Carbon;
87
use MongoDB\BSON\Binary;
8+
use MongoDB\BSON\UTCDateTime;
99

1010
class MongoDbSessionHandlerTest extends TestCase
1111
{
1212
/**
1313
* @var MongoDbSessionHandler
1414
*/
1515
protected $handler;
16-
16+
1717
/**
1818
* @var string
1919
*/
2020
protected $sessionId;
21-
21+
2222
/**
2323
* Set up the test environment.
2424
*/
2525
protected function setUp(): void
2626
{
2727
parent::setUp();
28-
28+
2929
$this->handler = $this->app['session.store']->getHandler();
3030
$this->sessionId = md5(uniqid('test_session'));
3131
}
32-
32+
3333
/**
3434
* Test the open method
3535
*/
3636
public function test_open_method(): void
3737
{
3838
$this->assertTrue($this->handler->open('path', 'name'));
3939
}
40-
40+
4141
/**
4242
* Test the close method
4343
*/
4444
public function test_close_method(): void
4545
{
4646
$this->assertTrue($this->handler->close());
4747
}
48-
48+
4949
/**
5050
* Test reading non-existent session
5151
*/
5252
public function test_read_non_existent_session(): void
5353
{
5454
$this->assertEquals('', $this->handler->read('non_existent_id'));
5555
}
56-
56+
5757
/**
5858
* Test write and read session
5959
*/
6060
public function test_write_and_read_session(): void
6161
{
6262
$data = 'test_data_' . time();
63-
63+
6464
// Write session data
6565
$this->assertTrue($this->handler->write($this->sessionId, $data));
66-
66+
6767
// Read it back
6868
$readData = $this->handler->read($this->sessionId);
69-
69+
7070
$this->assertEquals($data, $readData);
71-
71+
7272
// Check database directly
7373
$session = $this->app['db']->table(config('session.table'))
7474
->where('_id', $this->sessionId)
7575
->first();
76-
76+
7777
$this->assertNotNull($session);
78-
$this->assertInstanceOf(Binary::class, $session->payload);
79-
$this->assertInstanceOf(Carbon::class, $session->expires_at);
80-
$this->assertInstanceOf(Carbon::class, $session->last_activity);
78+
$this->assertInstanceOf(Binary::class, $session['payload']);
79+
$this->assertInstanceOf(UTCDateTime::class, $session['expires_at']);
80+
$this->assertInstanceOf(UTCDateTime::class, $session['last_activity']);
8181
}
82-
82+
8383
/**
8484
* Test destroy session
8585
*/
8686
public function test_destroy_session(): void
8787
{
8888
// First write a session
8989
$this->handler->write($this->sessionId, 'test_data');
90-
90+
9191
// Verify it exists
9292
$exists = $this->app['db']->table(config('session.table'))
9393
->where('_id', $this->sessionId)
9494
->exists();
9595
$this->assertTrue($exists);
96-
96+
9797
// Now destroy it
9898
$this->assertTrue($this->handler->destroy($this->sessionId));
99-
99+
100100
// Verify it's gone
101101
$exists = $this->app['db']->table(config('session.table'))
102102
->where('_id', $this->sessionId)
103103
->exists();
104104
$this->assertFalse($exists);
105105
}
106-
106+
107107
/**
108108
* Test garbage collection
109109
*/
@@ -112,4 +112,4 @@ public function test_garbage_collection(): void
112112
// gc should return a truthy value as it's handled by MongoDB TTL index
113113
$this->assertNotFalse($this->handler->gc(100));
114114
}
115-
}
115+
}

0 commit comments

Comments
 (0)