Skip to content

Commit b1f4a8c

Browse files
authored
Merge pull request #3 from plank/checkpoint-query-improvements
Checkpoint Query Improvements
2 parents 39dfbab + 16818c2 commit b1f4a8c

25 files changed

+967
-376
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ trim_trailing_whitespace = true
1313

1414
[*.md]
1515
trim_trailing_whitespace = false
16+
17+
[*.{yml,yaml}]
18+
indent_size = 2

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
/.scrutinizer.yml export-ignore
1010
/tests export-ignore
1111
/.editorconfig export-ignore
12+
/.php_cs.dist export-ignore
13+
/.github export-ignore
14+
/psalm.xml export-ignore
15+
/psalm.xml.dist export-ignore
File renamed without changes.

.github/workflows/tests.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
os: [ubuntu-latest]
12+
php: [7.4]
13+
laravel: [6.*, 7.*]
14+
stability: [prefer-stable]
15+
include:
16+
- laravel: 7.*
17+
testbench: 5.*
18+
- laravel: 6.*
19+
testbench: 4.*
20+
21+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: ${{ matrix.php }}
31+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
32+
coverage: none
33+
34+
- name: Setup problem matchers
35+
run: |
36+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
37+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
38+
39+
- name: Cache dependencies
40+
uses: actions/cache@v2
41+
with:
42+
path: ~/.composer/cache/files
43+
key: dependencies-php-${{ matrix.php }}-laravel-${{ matrix.laravel }}-stability-${{ matrix.stability }}-composer-${{ hashFiles('composer.json') }}
44+
45+
- name: Install dependencies
46+
run: |
47+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
48+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
49+
50+
- name: Execute tests
51+
run: vendor/bin/phpunit

.gitignore

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
build
2-
composer.lock
1+
.idea
2+
.DS_Store
33
docs
4-
vendor
4+
build
55
coverage
6-
.idea
6+
vendor
7+
composer.lock
8+
.php_cs
79
.php_cs.cache
8-
.DS_Store
9-
/.phpunit*
10+
.phpunit.result.cache
11+
phpunit.xml
12+
psalm.xml

README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Laravel Checkpoint
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/plank/laravel-checkpoint.svg?style=flat-square)](https://packagist.org/packages/plank/versionable)
4-
[![Build Status](https://img.shields.io/travis/plank/laravel-checkpoint/master.svg?style=flat-square)](https://travis-ci.org/plank/versionable)
5-
[![Quality Score](https://img.shields.io/scrutinizer/g/plank/laravel-checkpoint.svg?style=flat-square)](https://scrutinizer-ci.com/g/plank/versionable)
4+
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/plank/laravel-checkpoint/tests?label=tests)](https://github.com/plank/laravel-checkpoint/actions?query=workflow%3Atests+branch%3Amaster)
65
[![Total Downloads](https://img.shields.io/packagist/dt/plank/laravel-checkpoint.svg?style=flat-square)](https://packagist.org/packages/plank/versionable)
76

87
## Table of Contents
@@ -27,10 +26,10 @@
2726
- [Should Revision](#should-revision)
2827
- [Excluded Columns](#excluded-columns)
2928
- [Excluded Relations](#excluded-relations)
30-
- [Testing](#testing)
31-
- [Changelog](#changelog)
29+
- [Testing](#testing)
30+
- [Changelog](#changelog)
3231
- [Contributing](#contributing)
33-
- [Security](#security)
32+
- [Security](#security)
3433
- [Credits](#credits)
3534
- [License](#license)
3635

@@ -113,8 +112,7 @@ This query scope will limit the query to return the *Model* whose ```Revision```
113112
the ```Revision``` was created at or before the given moment.
114113

115114
The moment can either be an instance of a ```Checkpoint```
116-
using its ```checkpoint_date``` field, or a string representation of a date compatible with ```Carbon::parse```, or a
117-
```Carbon``` instance.
115+
using its ```checkpoint_date``` field, a string representation of a date or a ```Carbon``` instance.
118116

119117
#### since($moment)
120118
```php
@@ -126,24 +124,24 @@ since($moment = null)
126124
This query scope will limit the query to return the *Model* whose ```Revision``` has the max primary key, where
127125
the ```Revision``` was created after the given moment.
128126

129-
The moment can either be an instance of a ```Checkpoint``` using its ```checkpoint_date``` field, or a string
130-
representation of a date compatible with ```Carbon::parse```, or a ```Carbon``` instance.
127+
The moment can either be an instance of a ```Checkpoint``` using its ```checkpoint_date``` field, a string
128+
representation of a date or a ```Carbon``` instance.
131129

132130
#### temporal($upper, $lower)
133131
```php
134132
/**
135133
* @param $upper Checkpoint|Carbon|string
136134
* @param $upper Checkpoint|Carbon|string
137135
*/
138-
temporal($upper = null, $lower = null)
136+
temporal($until = null, $since = null)
139137
```
140138
This query scope will limit the query to return the *Model* whose ```Revision``` has the max primary key created at
141-
or before ```$upper```. This method can also limit the query to the *Model* whose revision has the max primary key
142-
created after ```$lower```.
139+
or before ```$until```. This method can also limit the query to the *Model* whose revision has the max primary key
140+
created after ```$since```.
143141

144-
Each argument operates independently of each other and ```$upper``` and ```$lower``` can
145-
either be an instance of a ```Checkpoint``` using its ```checkpoint_date``` field, or a string representation of a date
146-
compatible with ```Carbon::parse```, or a ```Carbon``` instance.
142+
Each argument operates independently of each other and ```$until``` and ```$since``` can
143+
either be an instance of a ```Checkpoint``` using its ```checkpoint_date``` field, a string representation of a
144+
date or a ```Carbon``` instance.
147145

148146
#### withoutRevisions()
149147
```php
@@ -186,21 +184,21 @@ cases you can add the names of the relations to the``` protected $excludedRelati
186184
revisioning. Excluding all relations to the ```Checkpoint```s and other related ```Revision```s are handled by the
187185
package.
188186

189-
### Testing
187+
## Testing
190188

191189
``` bash
192190
composer test
193191
```
194192

195-
### Changelog
193+
## Changelog
196194

197195
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
198196

199197
## Contributing
200198

201-
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
199+
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
202200

203-
### Security
201+
## Security
204202

205203
If you discover any security related issues, please email massimo@plankdesign.com instead of using the issue tracker.
206204

composer.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
"illuminate/support": "5.8.*|^6.0|^7.0|^8.0"
3131
},
3232
"require-dev": {
33-
"orchestra/testbench": "^4.0",
34-
"phpunit/phpunit": "^8.0"
33+
"orchestra/testbench": "^4.8 || ^5.2",
34+
"phpunit/phpunit": "^9.3",
35+
"vimeo/psalm": "^3.11"
3536
},
3637
"autoload": {
3738
"psr-4": {
@@ -44,9 +45,9 @@
4445
}
4546
},
4647
"scripts": {
47-
"test": "vendor/bin/phpunit",
48+
"psalm": "vendor/bin/psalm",
49+
"test": "vendor/bin/phpunit --colors=always",
4850
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
49-
5051
},
5152
"config": {
5253
"sort-packages": true
@@ -57,5 +58,7 @@
5758
"Plank\\Checkpoint\\CheckpointServiceProvider"
5859
]
5960
}
60-
}
61+
},
62+
"minimum-stability": "dev",
63+
"prefer-stable": true
6164
}

config/checkpoint.php

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11
<?php
22

3-
/*
4-
* You can place your custom package configuration in here.
5-
*/
63
return [
74

85
/*
9-
|
10-
| The full namespace to your User model class.
11-
|
12-
| If your application doesn't have a user class, the value should be "NULL".
13-
|
14-
*/
15-
'user_model' => '\App\User',
6+
* When true, checkpoint will automatically hook its observer to the
7+
* revisionable model events in order to create revisions when needed
8+
*/
9+
'enabled' => env('CHECKPOINT_ENABLED', true),
1610

1711
/*
18-
|
19-
| Concrete implementation for the "version model".
20-
| To extend or replace this functionality, change the value below with your full "version model" FQCN.
21-
|
22-
*/
23-
'checkpoint_model' => \Plank\Checkpoint\Models\Checkpoint::class,
12+
* When true, checkpoint will automatically apply the global revision scope
13+
* onto revisionables for filtering out relevant content based on time
14+
*
15+
* ***warning***
16+
* disabling after using the package will result in query results containing
17+
* duplicate items as they won't automatically be filtered by time
18+
*/
19+
'apply_global_scope' => env('REVISIONS_GLOBAL_SCOPE', env('CHECKPOINT_ENABLED', true)),
2420

2521
/*
26-
|
27-
| Concrete implementation for the "version model".
28-
| To extend or replace this functionality, change the value below with your full "version model" FQCN.
29-
|
30-
*/
31-
'revision_model' => \Plank\Checkpoint\Models\Revision::class,
22+
* Should checkpoint run its default migrations
23+
*/
24+
'run_migrations' => env('RUN_CHECKPOINT_MIGRATIONS', true),
3225

26+
'models' => [
27+
28+
/*
29+
* When using the "HasRevisions" trait from this package, we need to know which model
30+
* should be used to retrieve your revisions. To extend or replace this functionality,
31+
* change the value below with your full "revision model" class name.
32+
*/
33+
'revision' => Plank\Checkpoint\Models\Revision::class,
34+
35+
/*
36+
* When using the "HasRevisions" trait from this package, we need to know which model
37+
* should be used to retrieve your checkpoints. To extend or replace this functionality,
38+
* change the value below with your full "checkpoint model" class name.
39+
*/
40+
'checkpoint' => Plank\Checkpoint\Models\Checkpoint::class,
41+
42+
],
3343

3444
];

phpunit.xml.dist

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
1010
processIsolation="false"
11-
stopOnFailure="false">
11+
stopOnFailure="false"
12+
>
1213
<testsuites>
1314
<testsuite name="Unit">
1415
<directory suffix="Test.php">./tests/Unit</directory>
@@ -17,16 +18,17 @@
1718
<directory suffix="Test.php">./tests/Feature</directory>
1819
</testsuite>
1920
</testsuites>
20-
<filter>
21-
<whitelist processUncoveredFilesFromWhitelist="true">
22-
<directory suffix=".php">src/</directory>
23-
</whitelist>
24-
</filter>
21+
<coverage processUncoveredFiles="true">
22+
<include>
23+
<directory suffix=".php">./src</directory>
24+
</include>
25+
<report>
26+
<clover outputFile="build/logs/clover.xml"/>
27+
<html outputDirectory="build/coverage"/>
28+
<text outputFile="build/coverage.txt"/>
29+
</report>
30+
</coverage>
2531
<logging>
26-
<log type="tap" target="build/report.tap"/>
27-
<log type="junit" target="build/report.junit.xml"/>
28-
<log type="coverage-html" target="build/coverage"/>
29-
<log type="coverage-text" target="build/coverage.txt"/>
30-
<log type="coverage-clover" target="build/logs/clover.xml"/>
32+
<junit outputFile="build/report.junit.xml"/>
3133
</logging>
3234
</phpunit>

psalm.xml.dist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
findUnusedVariablesAndParams="true"
5+
resolveFromConfigFile="true"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xmlns="https://getpsalm.org/schema/config"
8+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
9+
>
10+
<projectFiles>
11+
<directory name="src"/>
12+
<ignoreFiles>
13+
<directory name="vendor"/>
14+
</ignoreFiles>
15+
</projectFiles>
16+
</psalm>

0 commit comments

Comments
 (0)