Skip to content

Update from master #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4ab85df
Update README
Smolevich Sep 11, 2019
b96c3c3
Delete useless links in markdown
Smolevich Sep 11, 2019
ffa5d14
Remove redundant symbol
Smolevich Sep 11, 2019
ebd3965
Add ci file for GIthub Actions
Smolevich Oct 17, 2019
ffb5698
Update phpunit.xml.dist
Smolevich Oct 17, 2019
3d04f59
Add php-coveralls/php-coveralls, use coverallsapp/github-action@maste…
Smolevich Oct 17, 2019
bd7a019
Use php-coveralls for coveralls
Smolevich Oct 21, 2019
0a6232f
Add using phpcov
Smolevich Oct 21, 2019
8999a03
Downgrade version phpunit/phpcov
Smolevich Oct 21, 2019
002a9ed
Use version 5.0.0
Smolevich Oct 21, 2019
f22075f
Update ci configuration
Smolevich Oct 21, 2019
b5babda
remove no longer maintained package
Smolevich Oct 21, 2019
78d7cbd
Merge pull request #1 from jenssegers/master
manan-jadhav Nov 9, 2019
c084a2c
use Carbon::now for fresh timestamps
manan-jadhav Nov 9, 2019
1d7f2fc
account for millsecond differences in execution
manan-jadhav Nov 9, 2019
9a5b1bd
fix assertion
manan-jadhav Nov 9, 2019
0f14787
Update blank.yml
Smolevich Nov 10, 2019
b6d5346
Update blank.yml
Smolevich Nov 10, 2019
ce1ea38
Update blank.yml
Smolevich Nov 10, 2019
b99dcd2
Rename ci configuration
Smolevich Nov 10, 2019
ff07bef
Update ci file configuration
Smolevich Nov 10, 2019
291cb95
Add echo token
Smolevich Nov 10, 2019
629692f
Update ci configuration
Smolevich Nov 10, 2019
551aaf2
Update ci configuration
Smolevich Nov 10, 2019
b0e7e0a
Add cedx/coveralls
Smolevich Nov 10, 2019
f08f4e9
Update ci configuration
Smolevich Nov 10, 2019
389eb98
Update config
Smolevich Nov 10, 2019
479a97d
Remove docker-compose configuration
Smolevich Nov 10, 2019
0b74edb
Added create index documentation
Jan 16, 2020
c1e02a9
Update README.md
Jan 16, 2020
815708d
Merge pull request #1907 from Giacomo92/patch-1
jenssegers Jan 16, 2020
5beca2b
Update ci file
Smolevich Jan 16, 2020
725fc2a
Fix ci
Smolevich Jan 16, 2020
847efe1
Fix name binary file
Smolevich Jan 16, 2020
a51a266
Update composer.json
Smolevich Jan 16, 2020
c0ca8ab
Merge pull request #1859 from Smolevich/add-support-for-github-actions
jenssegers Jan 17, 2020
87880c0
Merge pull request #1827 from Smolevich/change-readme
jenssegers Jan 17, 2020
811cb3d
Merge pull request #1870 from CurosMJ/fix-fresh-timestamp
jenssegers Jan 17, 2020
03de87d
Refactor build-ci.yml
Smolevich Jan 18, 2020
3b749d1
Merge pull request #1908 from Smolevich/add-improvements-for-ci
jenssegers Jan 20, 2020
6719733
Remove Travis
jenssegers Jan 20, 2020
b7901f3
:pencil2: Replace travis shield with github actions shield
jenssegers Jan 20, 2020
0015e51
Merge pull request #1909 from jenssegers/remove-travis
jenssegers Jan 20, 2020
14170a2
Added StyleCI
rennokki Jan 20, 2020
20d05ad
Merge pull request #1915 from rennokki/feature/style-ci
Smolevich Jan 20, 2020
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
62 changes: 62 additions & 0 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI

on:
push:
branches:
tags:
pull_request:

jobs:
build:
runs-on: ${{matrix.os}}
strategy:
matrix:
php: [7.1, 7.2, 7.3, 7.4]
os: ['ubuntu-latest']
services:
mongo:
image: mongo
ports:
- 27017:27017
mysql:
image: mysql:5.7
ports:
- 3307:3306
env:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_DATABASE: 'unittest'
MYSQL_ROOT_PASSWORD:
name: PHP ${{ matrix.php }} Test ${{ matrix.env }}

steps:
- uses: actions/checkout@v1
- name: Show php version
run: php${{ matrix.php }} -v && composer -V
- name: Debug if needed
run: if [[ "$DEBUG" == "true" ]]; then docker version && env; fi
env:
DEBUG: ${{secrets.DEBUG}}
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ matrix.os }}-composer-
- name: Install dependencies
run: |
composer install --no-interaction
- name: Generating code coverage
run: |
mkdir -p build/logs
./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
env:
MONGO_HOST: 0.0.0.0
MYSQL_HOST: 0.0.0.0
MYSQL_PORT: 3307
- name: Send coveralls
run: vendor/bin/php-coveralls -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: laravel
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Laravel MongoDB
===============

[![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)
[![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)

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.*

Expand All @@ -15,7 +15,6 @@ Table of contents
* [Query Builder](#query-builder)
* [Schema](#schema)
* [Extensions](#extensions)
* [Troubleshooting](#troubleshooting)
* [Examples](#examples)

Installation
Expand Down Expand Up @@ -154,8 +153,8 @@ You can connect to multiple servers or replica sets with the following configura
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'options' => [
'replicaSet' => 'replicaSetName'
]
'replicaSet' => 'replicaSetName'
]
],
```

Expand Down Expand Up @@ -254,7 +253,18 @@ Schema::create('users', function($collection)
$collection->unique('email');
});
```
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:

```
Schema::create('users', function($collection)
{
$collection->index('username',null,null,[
'sparse' => true,
'unique' => true,
'background' => true
]);
});
```
Supported operations are:

- create and drop
Expand All @@ -264,7 +274,7 @@ Supported operations are:
- unique
- background, sparse, expire, geospatial (MongoDB specific)

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
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

### Geospatial indexes

Expand Down Expand Up @@ -313,6 +323,7 @@ If you want to use MongoDB as your database backend, change the driver in `confi
'queue' => 'default',
'expire' => 60,
],
]
```

If you want to use MongoDB to handle failed jobs, change the database in `config/queue.php`:
Expand All @@ -321,7 +332,7 @@ If you want to use MongoDB to handle failed jobs, change the database in `config
'failed' => [
'database' => 'mongodb',
'table' => 'failed_jobs',
],
],
```

And add the service provider in `config/app.php`:
Expand Down Expand Up @@ -602,15 +613,15 @@ $users = User::where('location', 'geoWithin', [
[
-0.1450383,
51.5069158,
],
],
[
-0.1367563,
51.5100913,
],
],
[
-0.1270247,
51.5013233,
],
],
[
-0.1450383,
51.5069158,
Expand Down Expand Up @@ -694,7 +705,7 @@ For more information about model manipulation, check http://laravel.com/docs/elo

### Dates

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
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

Example:

Expand Down Expand Up @@ -771,7 +782,7 @@ class User extends Eloquent {
```


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
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

### EmbedsMany Relations

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

```php
$model = User::raw()->findOne(['age' => array('$lt' => 18)]);
$model = User::raw()->findOne(['age' => ['$lt' => 18]]);
```

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

*From: http://laravel.com/docs/queries#caching-queries*
*From: https://laravel.com/docs/4.2/queries#caching-queries*

### Query Logging

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

*From: http://laravel.com/docs/database#query-logging*
*From: https://laravel.com/docs/4.2/database#query-logging*
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@
"phpunit/phpunit": "^6.0|^7.0|^8.0",
"orchestra/testbench": "^3.1|^4.0",
"mockery/mockery": "^1.0",
"satooshi/php-coveralls": "^2.0",
"doctrine/dbal": "^2.5"
"php-coveralls/php-coveralls": "dev-add-support-for-github-actions",
"doctrine/dbal": "^2.5",
"phpunit/phpcov": "5.0.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Smolevich/php-coveralls"
}
],
"autoload": {
"psr-0": {
"Jenssegers\\Mongodb": "src/"
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@
<file>tests/ValidationTest.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<php>
<env name="MONGO_HOST" value="mongodb"/>
<env name="MONGO_DATABASE" value="unittest"/>
<env name="MONGO_PORT" value="27017"/>
<env name="MYSQL_HOST" value="mysql"/>
<env name="MYSQL_PORT" value="3306"/>
<env name="MYSQL_DATABASE" value="unittest"/>
<env name="MYSQL_USERNAME" value="root"/>
<env name="QUEUE_CONNECTION" value="database"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getDateFormat()
*/
public function freshTimestamp()
{
return new UTCDateTime(time() * 1000);
return new UTCDateTime(Carbon::now());
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ public function testDates(): void
$this->assertEquals((string) $user->getAttribute('entry.date')->format('Y-m-d H:i:s'), $data['entry']['date']);
}

public function testCarbonDateMockingWorks()
{
$fakeDate = \Carbon\Carbon::createFromDate(2000, 01, 01);

Carbon::setTestNow($fakeDate);
$item = Item::create(['name' => 'sword']);

$this->assertLessThan(1, $fakeDate->diffInSeconds($item->created_at));
}

public function testIdAttribute(): void
{
/** @var User $user */
Expand Down
2 changes: 2 additions & 0 deletions tests/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

return [

Expand All @@ -23,6 +24,7 @@
'mysql' => [
'driver' => 'mysql',
'host' => env('MYSQL_HOST', 'mysql'),
'port' => $mysqlPort,
'database' => env('MYSQL_DATABASE', 'unittest'),
'username' => env('MYSQL_USERNAME', 'root'),
'password' => env('MYSQL_PASSWORD', ''),
Expand Down