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

Commit 49965c9

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 ab81fb0 commit 49965c9

File tree

4 files changed

+103
-25
lines changed

4 files changed

+103
-25
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: "Run Tests - Laravel 10"
2+
3+
on:
4+
push:
5+
branches: [ v5.x ]
6+
7+
pull_request:
8+
branches: [ v5.x ]
9+
10+
jobs:
11+
tests:
12+
13+
runs-on: ubuntu-latest
14+
15+
services:
16+
mongodb:
17+
image: mongo:7
18+
ports:
19+
- 27017:27017
20+
options: >-
21+
--health-cmd="mongosh --quiet --eval 'db.runCommand({ping:1})'"
22+
--health-interval=10s
23+
--health-timeout=5s
24+
--health-retries=3
25+
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
php: [ 8.1 ]
30+
laravel: [ 10.* ]
31+
include:
32+
- laravel: 10.*
33+
testbench: 10.*
34+
35+
name: P${{ matrix.php }} - L${{ matrix.laravel }}
36+
37+
steps:
38+
- name: Checkout code
39+
uses: actions/checkout@v3
40+
41+
- name: Setup PHP
42+
uses: shivammathur/setup-php@v2
43+
with:
44+
php-version: ${{ matrix.php }}
45+
extensions: pdo, sqlite, pdo_sqlite, mongodb
46+
coverage: none
47+
48+
- name: Get composer cache directory
49+
id: composer-cache
50+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
51+
52+
- name: Cache dependencies
53+
uses: actions/cache@v3
54+
with:
55+
path: ${{ steps.composer-cache.outputs.dir }}
56+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
57+
restore-keys: ${{ runner.os }}-composer-
58+
59+
- name: Install Dependencies
60+
run: composer install --prefer-dist --no-interaction --no-progress
61+
62+
- name: Execute tests
63+
run: vendor/bin/phpunit
64+
env:
65+
MONGODB_HOST: 127.0.0.1
66+
MONGODB_PORT: 27017
67+
MONGODB_DATABASE: laravel_session_test

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
}

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
colors="true"
77
processIsolation="false"
88
stopOnFailure="false"
9-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
9+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
1010
cacheDirectory=".phpunit.cache"
1111
backupStaticProperties="false"
1212
>
@@ -24,4 +24,4 @@
2424
<env name="MONGODB_PORT" value="27017"/>
2525
<env name="MONGODB_DATABASE" value="laravel_session_test"/>
2626
</php>
27-
</phpunit>
27+
</phpunit>

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)