Skip to content

Commit 431ded7

Browse files
authored
Merge pull request #1 from jenssegers/master
Update from master
2 parents 39ef853 + 20d05ad commit 431ded7

File tree

9 files changed

+116
-44
lines changed

9 files changed

+116
-44
lines changed

.github/workflows/build-ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
tags:
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: ${{matrix.os}}
12+
strategy:
13+
matrix:
14+
php: [7.1, 7.2, 7.3, 7.4]
15+
os: ['ubuntu-latest']
16+
services:
17+
mongo:
18+
image: mongo
19+
ports:
20+
- 27017:27017
21+
mysql:
22+
image: mysql:5.7
23+
ports:
24+
- 3307:3306
25+
env:
26+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
27+
MYSQL_DATABASE: 'unittest'
28+
MYSQL_ROOT_PASSWORD:
29+
name: PHP ${{ matrix.php }} Test ${{ matrix.env }}
30+
31+
steps:
32+
- uses: actions/checkout@v1
33+
- name: Show php version
34+
run: php${{ matrix.php }} -v && composer -V
35+
- name: Debug if needed
36+
run: if [[ "$DEBUG" == "true" ]]; then docker version && env; fi
37+
env:
38+
DEBUG: ${{secrets.DEBUG}}
39+
- name: Get Composer Cache Directory
40+
id: composer-cache
41+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
42+
- name: Cache dependencies
43+
uses: actions/cache@v1
44+
with:
45+
path: ${{ steps.composer-cache.outputs.dir }}
46+
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
47+
restore-keys: ${{ matrix.os }}-composer-
48+
- name: Install dependencies
49+
run: |
50+
composer install --no-interaction
51+
- name: Generating code coverage
52+
run: |
53+
mkdir -p build/logs
54+
./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
55+
env:
56+
MONGO_HOST: 0.0.0.0
57+
MYSQL_HOST: 0.0.0.0
58+
MYSQL_PORT: 3307
59+
- name: Send coveralls
60+
run: vendor/bin/php-coveralls -v
61+
env:
62+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: laravel

.travis.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Laravel MongoDB
22
===============
33

4-
[![Latest Stable Version](http://img.shields.io/github/release/jenssegers/laravel-mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Total Downloads](http://img.shields.io/packagist/dm/jenssegers/mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Build Status](http://img.shields.io/travis/jenssegers/laravel-mongodb.svg)](https://travis-ci.org/jenssegers/laravel-mongodb) [![Coverage Status](http://img.shields.io/coveralls/jenssegers/laravel-mongodb.svg)](https://coveralls.io/r/jenssegers/laravel-mongodb?branch=master) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers)
4+
[![Latest Stable Version](http://img.shields.io/github/release/jenssegers/laravel-mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Total Downloads](http://img.shields.io/packagist/dm/jenssegers/mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Build Status](https://img.shields.io/github/workflow/status/jenssegers/laravel-mongodb/CI)](https://github.com/jenssegers/laravel-mongodb/actions) [![Coverage Status](https://coveralls.io/repos/github/jenssegers/laravel-mongodb/badge.svg?branch=master)](https://coveralls.io/github/jenssegers/laravel-mongodb?branch=master) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers)
55

66
An Eloquent model and Query builder with support for MongoDB, using the original Laravel API. *This library extends the original Laravel classes, so it uses exactly the same methods.*
77

@@ -15,7 +15,6 @@ Table of contents
1515
* [Query Builder](#query-builder)
1616
* [Schema](#schema)
1717
* [Extensions](#extensions)
18-
* [Troubleshooting](#troubleshooting)
1918
* [Examples](#examples)
2019

2120
Installation
@@ -154,8 +153,8 @@ You can connect to multiple servers or replica sets with the following configura
154153
'username' => env('DB_USERNAME'),
155154
'password' => env('DB_PASSWORD'),
156155
'options' => [
157-
'replicaSet' => 'replicaSetName'
158-
]
156+
'replicaSet' => 'replicaSetName'
157+
]
159158
],
160159
```
161160

@@ -254,7 +253,18 @@ Schema::create('users', function($collection)
254253
$collection->unique('email');
255254
});
256255
```
256+
You can also pass all the parameters specified in the MongoDB docs [here](https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#options-for-all-index-types) in the `$options` parameter. For example:
257257

258+
```
259+
Schema::create('users', function($collection)
260+
{
261+
$collection->index('username',null,null,[
262+
'sparse' => true,
263+
'unique' => true,
264+
'background' => true
265+
]);
266+
});
267+
```
258268
Supported operations are:
259269

260270
- create and drop
@@ -264,7 +274,7 @@ Supported operations are:
264274
- unique
265275
- background, sparse, expire, geospatial (MongoDB specific)
266276

267-
All other (unsupported) operations are implemented as dummy pass-through methods, because MongoDB does not use a predefined schema. Read more about the schema builder on http://laravel.com/docs/schema
277+
All other (unsupported) operations are implemented as dummy pass-through methods, because MongoDB does not use a predefined schema. Read more about the schema builder on https://laravel.com/docs/6.0/migrations#tables
268278

269279
### Geospatial indexes
270280

@@ -313,6 +323,7 @@ If you want to use MongoDB as your database backend, change the driver in `confi
313323
'queue' => 'default',
314324
'expire' => 60,
315325
],
326+
]
316327
```
317328

318329
If you want to use MongoDB to handle failed jobs, change the database in `config/queue.php`:
@@ -321,7 +332,7 @@ If you want to use MongoDB to handle failed jobs, change the database in `config
321332
'failed' => [
322333
'database' => 'mongodb',
323334
'table' => 'failed_jobs',
324-
],
335+
],
325336
```
326337

327338
And add the service provider in `config/app.php`:
@@ -602,15 +613,15 @@ $users = User::where('location', 'geoWithin', [
602613
[
603614
-0.1450383,
604615
51.5069158,
605-
],
616+
],
606617
[
607618
-0.1367563,
608619
51.5100913,
609-
],
620+
],
610621
[
611622
-0.1270247,
612623
51.5013233,
613-
],
624+
],
614625
[
615626
-0.1450383,
616627
51.5069158,
@@ -694,7 +705,7 @@ For more information about model manipulation, check http://laravel.com/docs/elo
694705

695706
### Dates
696707

697-
Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields, you will need to manually specify them as described here: http://laravel.com/docs/eloquent#date-mutators
708+
Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields, you will need to manually specify them as described here: https://laravel.com/docs/5.0/eloquent#date-mutators
698709

699710
Example:
700711

@@ -771,7 +782,7 @@ class User extends Eloquent {
771782
```
772783

773784

774-
Other relations are not yet supported, but may be added in the future. Read more about these relations on http://laravel.com/docs/eloquent#relationships
785+
Other relations are not yet supported, but may be added in the future. Read more about these relations on https://laravel.com/docs/master/eloquent-relationships
775786

776787
### EmbedsMany Relations
777788

@@ -970,7 +981,7 @@ $cursor = DB::collection('users')->raw(function($collection)
970981
Optional: if you don't pass a closure to the raw method, the internal MongoCollection object will be accessible:
971982

972983
```php
973-
$model = User::raw()->findOne(['age' => array('$lt' => 18)]);
984+
$model = User::raw()->findOne(['age' => ['$lt' => 18]]);
974985
```
975986

976987
The internal MongoClient and MongoDB objects can be accessed like this:
@@ -1064,7 +1075,7 @@ You may easily cache the results of a query using the remember method:
10641075
$users = User::remember(10)->get();
10651076
```
10661077

1067-
*From: http://laravel.com/docs/queries#caching-queries*
1078+
*From: https://laravel.com/docs/4.2/queries#caching-queries*
10681079

10691080
### Query Logging
10701081

@@ -1074,4 +1085,4 @@ By default, Laravel keeps a log in memory of all queries that have been run for
10741085
DB::connection()->disableQueryLog();
10751086
```
10761087

1077-
*From: http://laravel.com/docs/database#query-logging*
1088+
*From: https://laravel.com/docs/4.2/database#query-logging*

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@
2929
"phpunit/phpunit": "^6.0|^7.0|^8.0",
3030
"orchestra/testbench": "^3.1|^4.0",
3131
"mockery/mockery": "^1.0",
32-
"satooshi/php-coveralls": "^2.0",
33-
"doctrine/dbal": "^2.5"
32+
"php-coveralls/php-coveralls": "dev-add-support-for-github-actions",
33+
"doctrine/dbal": "^2.5",
34+
"phpunit/phpcov": "5.0.0"
3435
},
36+
"repositories": [
37+
{
38+
"type": "vcs",
39+
"url": "https://github.com/Smolevich/php-coveralls"
40+
}
41+
],
3542
"autoload": {
3643
"psr-0": {
3744
"Jenssegers\\Mongodb": "src/"

phpunit.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@
4040
<file>tests/ValidationTest.php</file>
4141
</testsuite>
4242
</testsuites>
43+
<filter>
44+
<whitelist processUncoveredFilesFromWhitelist="true">
45+
<directory suffix=".php">./src</directory>
46+
</whitelist>
47+
</filter>
4348
<php>
4449
<env name="MONGO_HOST" value="mongodb"/>
4550
<env name="MONGO_DATABASE" value="unittest"/>
4651
<env name="MONGO_PORT" value="27017"/>
4752
<env name="MYSQL_HOST" value="mysql"/>
53+
<env name="MYSQL_PORT" value="3306"/>
4854
<env name="MYSQL_DATABASE" value="unittest"/>
4955
<env name="MYSQL_USERNAME" value="root"/>
5056
<env name="QUEUE_CONNECTION" value="database"/>

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function getDateFormat()
118118
*/
119119
public function freshTimestamp()
120120
{
121-
return new UTCDateTime(time() * 1000);
121+
return new UTCDateTime(Carbon::now());
122122
}
123123

124124
/**

tests/ModelTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,16 @@ public function testDates(): void
434434
$this->assertEquals((string) $user->getAttribute('entry.date')->format('Y-m-d H:i:s'), $data['entry']['date']);
435435
}
436436

437+
public function testCarbonDateMockingWorks()
438+
{
439+
$fakeDate = \Carbon\Carbon::createFromDate(2000, 01, 01);
440+
441+
Carbon::setTestNow($fakeDate);
442+
$item = Item::create(['name' => 'sword']);
443+
444+
$this->assertLessThan(1, $fakeDate->diffInSeconds($item->created_at));
445+
}
446+
437447
public function testIdAttribute(): void
438448
{
439449
/** @var User $user */

tests/config/database.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
$mongoHost = env('MONGO_HOST', 'mongodb');
44
$mongoPort = env('MONGO_PORT') ? (int) env('MONGO_PORT') : 27017;
5+
$mysqlPort = env('MYSQL_PORT') ? (int) env('MYSQL_PORT') : 3306;
56

67
return [
78

@@ -23,6 +24,7 @@
2324
'mysql' => [
2425
'driver' => 'mysql',
2526
'host' => env('MYSQL_HOST', 'mysql'),
27+
'port' => $mysqlPort,
2628
'database' => env('MYSQL_DATABASE', 'unittest'),
2729
'username' => env('MYSQL_USERNAME', 'root'),
2830
'password' => env('MYSQL_PASSWORD', ''),

0 commit comments

Comments
 (0)