Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
max_line_length = 120

[*.php]
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[{*.html,*.less,*.sass,*.css,*.js,*.json}]
indent_size = 2

[*.{xml,yml,yaml}]
indent_size = 2

[composer.json]
indent_size = 4
68 changes: 68 additions & 0 deletions .github/workflows/run-tests-l11.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: "Run Tests - Laravel 11"

on:
push:
branches: [ v7.x, master ]

pull_request:
branches: [ v7.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.2, 8.3 ]
laravel: [ 11.* ]
include:
- laravel: 11.*
testbench: 9.*

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_mongodb_cache_test
39 changes: 0 additions & 39 deletions .github/workflows/run-tests-l5.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/run-tests-l6.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/run-tests-l7.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/run-tests-l8.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/run-tests-l9.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/vendor/
composer.lock
.phpunit.result.cache
.phpunit.cache
1 change: 1 addition & 0 deletions .phprc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
php8.2
63 changes: 59 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ A MongoDB cache driver for Laravel

| **Laravel<br/>Version** | **Package<br/>Version** | **Install using<br/>this command** |
|-------------------------|-------------------------|----------------------------------------------------|
| 5.7.x | 2.11.x | composer require 1ff/laravel-mongodb-cache:~2.11.0 |
| 5.8.x, 6.x | 2.12.x | composer require 1ff/laravel-mongodb-cache:~2.12.0 |
| 7.x | 3.x.x | composer require 1ff/laravel-mongodb-cache:^3.1 |
| 8.x | 4.x.x | composer require 1ff/laravel-mongodb-cache:^4.1 |
| 11.x | 7.x.x | composer require 1ff/laravel-mongodb-cache:^7.0 |
| 10.x | 6.x.x | composer require 1ff/laravel-mongodb-cache:^6.0 |
| 9.x | 5.x.x | composer require 1ff/laravel-mongodb-cache:^5.0 |
| 8.x | 4.x.x | composer require 1ff/laravel-mongodb-cache:^4.1 |
| 7.x | 3.x.x | composer require 1ff/laravel-mongodb-cache:^3.1 |
| 5.8.x, 6.x | 2.12.x | composer require 1ff/laravel-mongodb-cache:~2.12.0 |
| 5.7.x | 2.11.x | composer require 1ff/laravel-mongodb-cache:~2.11.0 |

Installation
------------
Expand Down Expand Up @@ -65,6 +67,59 @@ Advantages

php artisan mongodb:cache:dropindex

Testing
-------

This package includes tests that interact with a real MongoDB database to verify the functionality of the cache driver. The tests require a MongoDB instance to run successfully.

To run the tests:

1. Make sure you have MongoDB installed and running on your local machine
2. The test configuration is set in `phpunit.xml`:

```xml
<php>
<env name="MONGODB_HOST" value="127.0.0.1"/>
<env name="MONGODB_PORT" value="27017"/>
<env name="MONGODB_DATABASE" value="laravel_mongodb_cache_test"/>
<env name="MONGODB_USERNAME" value=""/>
<env name="MONGODB_PASSWORD" value=""/>
</php>
```

3. Run the tests with:

```
composer test
```

or

```
vendor/bin/phpunit
```

### Test Structure

The test suite is organized into multiple files to test various aspects of the MongoDB cache driver:

- `StoreTest.php`: Tests basic Store class functionality (get, put, forget, flush)
- `AdvancedCacheFeaturesTest.php`: Tests advanced Store features like increment/decrement, forever storage, and handling arrays/objects
- `TaggedCacheTest.php`: Tests tagged cache functionality
- `LaravelIntegrationTest.php`: Tests integration with Laravel's Cache facade

Some functionality (like increment/decrement, forever storage) is intentionally tested in multiple contexts:
1. At the low-level Store implementation
2. Through Laravel's Cache facade
3. With tagged cache operations

This multi-layered approach ensures that all feature functionality works correctly at all levels of integration.

GitHub Actions
-------------

The package includes GitHub Actions workflows that automatically run tests against a MongoDB service. The MongoDB service is started as part of the CI workflow, ensuring tests are executed in an environment with a real MongoDB database.

Warning
-------

Expand Down
Loading