Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mnphpexpert committed Dec 4, 2020
2 parents dcb5f33 + c63aaeb commit 22059df
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 41 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ on:

jobs:
build:
runs-on: ${{matrix.os}}
runs-on: ${{ matrix.os }}
name: PHP v${{ matrix.php }} with Mongo v${{ matrix.mongodb }}
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
php: ['7.2', '7.3', '7.4']
os: ['ubuntu-latest']
mongodb: ['3.6', '4.0', '4.2', '4.4']
include:
- { os: ubuntu-latest, php: 7.2, mongodb: 3.6, experimental: true}
- { os: ubuntu-latest, php: 7.2, mongodb: '4.0', experimental: true}
- { os: ubuntu-latest, php: 7.2, mongodb: 4.2, experimental: true}
- { os: ubuntu-latest, php: 7.2, mongodb: 4.4, experimental: true}
- { os: ubuntu-latest, php: 7.3, mongodb: 3.6, experimental: false}
- { os: ubuntu-latest, php: 7.3, mongodb: '4.0', experimental: false}
- { os: ubuntu-latest, php: 7.3, mongodb: 4.2, experimental: false}
- { os: ubuntu-latest, php: 7.3, mongodb: 4.4, experimental: false}
- { os: ubuntu-latest, php: 7.4, mongodb: 3.6, experimental: false}
- { os: ubuntu-latest, php: 7.4, mongodb: '4.0', experimental: false}
- { os: ubuntu-latest, php: 7.4, mongodb: 4.2, experimental: false}
- { os: ubuntu-latest, php: 7.4, mongodb: 4.4, experimental: false}
services:
mongo:
image: mongo:${{ matrix.mongodb }}
Expand All @@ -27,7 +39,6 @@ jobs:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_DATABASE: 'unittest'
MYSQL_ROOT_PASSWORD:
name: PHP v${{ matrix.php }} with Mongo v${{ matrix.mongodb }}

steps:
- uses: actions/checkout@v2
Expand All @@ -45,18 +56,22 @@ jobs:
env:
DEBUG: ${{secrets.DEBUG}}
- name: Download Composer cache dependencies from cache
if: (!startsWith(matrix.php, '7.2'))
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache Composer dependencies
if: (!startsWith(matrix.php, '7.2'))
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
if: (!startsWith(matrix.php, '7.2'))
run: |
composer install --no-interaction
- name: Run tests
if: (!startsWith(matrix.php, '7.2'))
run: |
./vendor/bin/phpunit --coverage-clover coverage.xml
env:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added
- Laravel 8 support by [@divine](https://github.com/divine).

### Changed
- Updated versions of all dependencies by [@divine](https://github.com/divine).

## [3.7.0] - 2020-09-18

### Added
- Laravel 7 support by [@divine](https://github.com/divine).

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Make sure you have the MongoDB PHP driver installed. You can find installation i
5.8.x | 3.5.x
6.x | 3.6.x
7.x | 3.7.x
8.x | 3.8.x

Install the package via Composer:

Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
],
"license": "MIT",
"require": {
"illuminate/support": "^7.0",
"illuminate/container": "^7.0",
"illuminate/database": "^7.0",
"illuminate/events": "^7.0",
"illuminate/support": "^8.0",
"illuminate/container": "^8.0",
"illuminate/database": "^8.0",
"illuminate/events": "^8.0",
"mongodb/mongodb": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "^8.4|^9.0",
"orchestra/testbench": "^5.0",
"phpunit/phpunit": "^9.0",
"orchestra/testbench": "^6.0",
"mockery/mockery": "^1.3.1",
"doctrine/dbal": "^2.6"
},
Expand Down
20 changes: 6 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="all">
<directory>tests/</directory>
Expand Down Expand Up @@ -37,11 +34,6 @@
<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"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ protected function compileWhereBasic(array $where)

if (!isset($operator) || $operator == '=') {
if ($is_numeric) {
$query = ['$where' => '/^'.$value->getPattern().'/.test(this.'.$column.')'];
$query = ['$where' => '/^'.$value->getPattern().'/.test(this["'.$column.'"])'];
} else {
$query = [$column => $value];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getResultsByType($type)

$query = $instance->newQuery();

return $query->whereIn($key, $this->gatherKeysByType($type))->get();
return $query->whereIn($key, $this->gatherKeysByType($type, $instance->getKeyType()))->get();
}

/**
Expand Down
30 changes: 17 additions & 13 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function setUp(): void
User::create(['name' => 'Brett Boe', 'age' => 35, 'title' => 'user']);
User::create(['name' => 'Tommy Toe', 'age' => 33, 'title' => 'user']);
User::create(['name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin']);
User::create(['name' => 'John Smith', 'user-age' => 28, 'title' => 'member']);
User::create(['name' => 'Error', 'age' => null, 'title' => null]);
}

Expand All @@ -41,10 +42,10 @@ public function testWhere(): void
$this->assertCount(1, $users);

$users = User::where('age', '!=', 35)->get();
$this->assertCount(6, $users);
$this->assertCount(7, $users);

$users = User::where('age', '<>', 35)->get();
$this->assertCount(6, $users);
$this->assertCount(7, $users);
}

public function testAndWhere(): void
Expand Down Expand Up @@ -78,21 +79,24 @@ public function testLike(): void

$users = User::where('age', 'like', '%3')->get();
$this->assertCount(4, $users);

$users = User::where('user-age', 'like', '%28')->get();
$this->assertCount(1, $users);
}

public function testNotLike(): void
{
$users = User::where('name', 'not like', '%doe')->get();
$this->assertCount(7, $users);
$this->assertCount(8, $users);

$users = User::where('name', 'not like', '%y%')->get();
$this->assertCount(6, $users);
$this->assertCount(7, $users);

$users = User::where('name', 'not LIKE', '%y%')->get();
$this->assertCount(6, $users);
$this->assertCount(7, $users);

$users = User::where('name', 'not like', 't%')->get();
$this->assertCount(8, $users);
$this->assertCount(9, $users);
}

public function testSelect(): void
Expand Down Expand Up @@ -152,7 +156,7 @@ public function testIn(): void
$this->assertCount(6, $users);

$users = User::whereNotIn('age', [33, 35])->get();
$this->assertCount(4, $users);
$this->assertCount(5, $users);

$users = User::whereNotNull('age')
->whereNotIn('age', [33, 35])->get();
Expand All @@ -162,7 +166,7 @@ public function testIn(): void
public function testWhereNull(): void
{
$users = User::whereNull('age')->get();
$this->assertCount(1, $users);
$this->assertCount(2, $users);
}

public function testWhereNotNull(): void
Expand Down Expand Up @@ -195,7 +199,7 @@ public function testOrder(): void
public function testGroupBy(): void
{
$users = User::groupBy('title')->get();
$this->assertCount(3, $users);
$this->assertCount(4, $users);

$users = User::groupBy('age')->get();
$this->assertCount(6, $users);
Expand Down Expand Up @@ -225,11 +229,11 @@ public function testGroupBy(): void
public function testCount(): void
{
$count = User::where('age', '<>', 35)->count();
$this->assertEquals(6, $count);
$this->assertEquals(7, $count);

// Test for issue #165
$count = User::select('_id', 'age', 'title')->where('age', '<>', 35)->count();
$this->assertEquals(6, $count);
$this->assertEquals(7, $count);
}

public function testExists(): void
Expand Down Expand Up @@ -327,12 +331,12 @@ public function testPaginate(): void
$results = User::paginate(2);
$this->assertEquals(2, $results->count());
$this->assertNotNull($results->first()->title);
$this->assertEquals(9, $results->total());
$this->assertEquals(10, $results->total());

$results = User::paginate(2, ['name', 'age']);
$this->assertEquals(2, $results->count());
$this->assertNull($results->first()->title);
$this->assertEquals(9, $results->total());
$this->assertEquals(10, $results->total());
$this->assertEquals(1, $results->currentPage());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testQueueJobLifeCycle(): void
'job' => 'test',
'maxTries' => null,
'maxExceptions' => null,
'delay' => null,
'backoff' => null,
'timeout' => null,
'data' => ['action' => 'QueueJobLifeCycle'],
]), $job->getRawBody());
Expand Down

0 comments on commit 22059df

Please sign in to comment.