71 Commits

Author SHA1 Message Date
Ismo Vuorinen
8c6bcd068b fix(ci): drop php 8.4, deps don't support it 2024-12-11 14:00:03 +02:00
Ismo Vuorinen
ae5828cc3f fix(deps): relax constrains to work with php 8.0 2024-12-11 13:55:12 +02:00
Ismo Vuorinen
38c451fa1c chore: remove and ignore composer.lock 2024-12-11 13:52:11 +02:00
Ismo Vuorinen
3d1a5da432 fix(ci): forgot we are using master branch 2024-12-11 13:50:30 +02:00
Ismo Vuorinen
0be2ed7c16 fix(ci): phpunit action fixes, added php 8.4 2024-12-11 13:49:39 +02:00
Ismo Vuorinen
da3eab90c5 fix(ci): validated phpunit action 2024-12-11 13:25:12 +02:00
d39a0020b1 Merge pull request #38 from nullthoughts/feat/updates-and-upgrades
* Bump php to ^8.0, add tooling, linting, fixes
* chore: add pull_request to github workflow
* chore: tweak triggers in github workflow
2024-12-11 13:09:11 +02:00
Ismo Vuorinen
70ae10137c chore: tweak triggers in github workflow 2024-12-11 13:07:02 +02:00
Ismo Vuorinen
e9e95871a1 chore: add pull_request to github workflow 2024-12-11 13:04:39 +02:00
Ismo Vuorinen
aec5ec026a Bump php to ^8.0, add tooling, linting, fixes 2024-12-11 12:58:22 +02:00
dependabot[bot]
e12085be2c Bump symfony/http-kernel from 6.0.8 to 6.0.20 (#34)
Bumps [symfony/http-kernel](https://github.com/symfony/http-kernel) from 6.0.8 to 6.0.20.
- [Release notes](https://github.com/symfony/http-kernel/releases)
- [Changelog](https://github.com/symfony/http-kernel/blob/6.2/CHANGELOG.md)
- [Commits](https://github.com/symfony/http-kernel/compare/v6.0.8...v6.0.20)

---
updated-dependencies:
- dependency-name: symfony/http-kernel
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-07 09:37:07 +02:00
Jani Gyllenberg
261e47bf7f V3.1 testing details 2022-09-07 12:50:18 -04:00
Jani Gyllenberg
311cf155c5 V3.1 branch link 2022-09-07 12:44:50 -04:00
Jani Gyllenberg
f14dc0a5c2 V3.1 details 2022-09-07 12:42:16 -04:00
Victor Gonzalez
9980bc7e9a update to Testbench v7 & composer update 2022-05-17 07:02:05 -05:00
Jani Gyllenberg
9935cb78cb Merge pull request #32 from nullthoughts/dependabot/composer/league/flysystem-1.1.4
Bump league/flysystem from 1.1.3 to 1.1.4
2021-07-02 12:17:42 -04:00
Jani Gyllenberg
9ade30325c Merge pull request #33 from nullthoughts/github-actions-phpunit
Github Actions: PHPUnit
2021-07-02 12:16:48 -04:00
Ismo Vuorinen
effd3be10f composer update on php 7.4 2021-06-29 14:37:23 +03:00
412a03516b Github Actions: PHPUnit
Added Github Actions runner for PHPUnit tests.
It runs on every push and makes sure all contributions (be it from humans, or bots) pass our existing tests.
2021-06-29 13:49:20 +03:00
dependabot[bot]
730fe0e2ac Bump league/flysystem from 1.1.3 to 1.1.4
Bumps [league/flysystem](https://github.com/thephpleague/flysystem) from 1.1.3 to 1.1.4.
- [Release notes](https://github.com/thephpleague/flysystem/releases)
- [Changelog](https://github.com/thephpleague/flysystem/blob/2.x/CHANGELOG.md)
- [Commits](https://github.com/thephpleague/flysystem/compare/1.1.3...1.1.4)

---
updated-dependencies:
- dependency-name: league/flysystem
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-29 04:05:34 +00:00
Victor Gonzalez
f830c5b264 update to accept php 8 2021-06-23 09:41:47 -04:00
95635719d6 Merge pull request #30 from nullthoughts/dependabot/composer/laravel/framework-7.30.4
Bump laravel/framework from 7.2.0 to 7.30.4
2021-02-02 19:53:59 +02:00
dependabot[bot]
e57f989c68 Bump laravel/framework from 7.2.0 to 7.30.4
Bumps [laravel/framework](https://github.com/laravel/framework) from 7.2.0 to 7.30.4.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/8.x/CHANGELOG-6.x.md)
- [Commits](https://github.com/laravel/framework/compare/v7.2.0...v7.30.4)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-02 17:51:33 +00:00
3a54f48c65 Removed non-existing Feature tests 2021-02-02 19:42:03 +02:00
c0f21612fc Merge pull request #28 from nullthoughts/dependabot/composer/symfony/http-foundation-5.0.7
Bump symfony/http-foundation from 5.0.5 to 5.0.7
2020-04-06 08:59:44 +03:00
dependabot[bot]
8007b2ae88 Bump symfony/http-foundation from 5.0.5 to 5.0.7
Bumps [symfony/http-foundation](https://github.com/symfony/http-foundation) from 5.0.5 to 5.0.7.
- [Release notes](https://github.com/symfony/http-foundation/releases)
- [Changelog](https://github.com/symfony/http-foundation/blob/master/CHANGELOG.md)
- [Commits](https://github.com/symfony/http-foundation/compare/v5.0.5...v5.0.7)

Signed-off-by: dependabot[bot] <support@github.com>
2020-03-30 22:43:51 +00:00
Victor Gonzalez
000f1e3851 Merge pull request #27 from vicgonvt/update_travis_php
Updates the travis CI and bumps PHP version
2020-03-18 09:52:34 -04:00
Victor Gonzalex
7bcec7872f allow for custom namespacing 2020-03-18 09:50:03 -04:00
Victor Gonzalez
449dafcb89 Merge pull request #26 from vicgonvt/feature_namespace_custom
Allow for custom namespacing
2020-03-18 09:01:02 -04:00
Victor Gonzalex
af513debec allow for custom namespacing 2020-03-18 08:50:45 -04:00
Victor Gonzalez
5759629d34 Merge pull request #25 from vicgonvt/feature_storage_json
Adds the ability to have the json files stored remotely
2020-03-18 08:19:29 -04:00
Victor Gonzalex
0ab4a4f053 change tests name to be unique for remote test 2020-03-18 07:59:34 -04:00
Victor Gonzalex
163be72b86 fixes all tests 2020-03-18 07:57:45 -04:00
Victor Gonzalex
20b07aeea8 fix broken tests 2020-03-18 07:30:40 -04:00
Victor Gonzalex
168923d3da wip getting the Storage driver to work for remote json files 2020-03-17 16:31:17 -04:00
Victor Gonzalez
b177e8de2c Merge pull request #24 from vicgonvt/update_testbench
updates testbench to 5.0 and phpunit 9
2020-03-17 14:37:46 -04:00
Victor Gonzalex
cd3adf1a96 updates testbench to 5.0 and phpunit 9 2020-03-17 14:33:40 -04:00
nullthoughts
8a987b89c5 Update namespace 2020-03-17 14:01:56 -04:00
nullthoughts
552bc8fba8 Update namespace 2020-03-17 13:55:24 -04:00
nullthoughts
7b89add86e Update namespace from distinctm to nullthoughts 2020-03-17 13:51:26 -04:00
Jani Gyllenberg
8c69fe4d27 Merge pull request #22 from nullthoughts/dependabot/composer/symfony/http-foundation-4.4.1
Bump symfony/http-foundation from 4.2.2 to 4.4.1
2019-12-05 17:13:59 -05:00
dependabot[bot]
a6b0d7aa66 Bump symfony/http-foundation from 4.2.2 to 4.4.1
Bumps [symfony/http-foundation](https://github.com/symfony/http-foundation) from 4.2.2 to 4.4.1.
- [Release notes](https://github.com/symfony/http-foundation/releases)
- [Changelog](https://github.com/symfony/http-foundation/blob/master/CHANGELOG.md)
- [Commits](https://github.com/symfony/http-foundation/compare/v4.2.2...v4.4.1)

Signed-off-by: dependabot[bot] <support@github.com>
2019-12-03 03:31:39 +00:00
Jani Gyllenberg
6dbf71adbc Merge pull request #19 from nullthoughts/issue-templates
Update issue templates
2019-10-16 10:18:42 -04:00
Jani Gyllenberg
0a462f9193 Merge pull request #21 from nullthoughts/contributing-guide
Contributing guide
2019-10-16 10:17:57 -04:00
Jani Gyllenberg
ec73547e7a Merge pull request #20 from nullthoughts/add-code-of-conduct-1
Contributor Covenant Code of Conduct
2019-10-16 10:16:50 -04:00
f478df70c4 Contributing guide
Parsed together from Laravel [contributions.md](https://raw.githubusercontent.com/laravel/docs/6.x/contributions.md) (MIT) and [readme.md](https://raw.githubusercontent.com/laravel/laravel/master/readme.md) (MIT)

Relates to #15
2019-10-16 10:09:29 +03:00
382c4a152d Contributor Covenant Code of Conduct
Used template provided by GitHub and used @nullthoughts public email address.

Relates to #15
2019-10-16 09:58:44 +03:00
27e8683874 Update issue templates
Bug report template (with added Laravel specific fields) and Feature request template.
2019-10-16 09:55:49 +03:00
Jani Gyllenberg
6f826afe71 Merge pull request #17 from nullthoughts/add-license
Create LICENSE
2019-10-15 13:26:26 -04:00
Jani Gyllenberg
de80308447 Merge pull request #18 from nullthoughts/dev
Fix case-sensitive namespace issues & update Readme
2019-10-15 12:39:03 -04:00
nullthoughts
5f7fa84914 Manually merge PR 16 from @vicgonvt 2019-10-15 12:29:30 -04:00
Jani Gyllenberg
ee3f13ec2b Create LICENSE 2019-10-15 12:24:33 -04:00
nullthoughts
5acf52b9f4 Update case-sensitive namespace for fakes 2019-10-15 12:21:45 -04:00
nullthoughts
6b3ff0ebdf Fix Travis CI link (namespace change) 2019-10-15 12:21:23 -04:00
nullthoughts
862a15b95c Merge fakes & Fakes (case sensitive) 2019-10-15 12:21:01 -04:00
Jani Gyllenberg
325667f1f7 Merge pull request #16 from vicgonvt/master
Great work 👍, Thank you

Even though Travis CI tests are failing in the PR, they are passing in your fork.
2019-10-15 12:01:33 -04:00
Victor Gonzalez
cdd675a862 fix broken tests with removal of str_studly 2019-10-15 11:38:11 -04:00
Victor Gonzalez
dafbb6cb6a Update readme.md 2019-10-15 11:25:09 -04:00
Jani Gyllenberg
aa9d2905fb Merge pull request #14 from distinctm/php71-support
Support for PHP 7.1
2019-08-23 10:08:47 -04:00
distinctm
916f203c5b Switches type hinting of objects to stdClass for 7.1 backwards compatibility 2019-08-23 10:03:26 -04:00
distinctm
9dd3e29601 Rename 2019-08-23 09:53:05 -04:00
distinctm
e6200c346a Implements void return types for PHPUnit 2019-08-23 09:45:52 -04:00
Jani Gyllenberg
12ba3008cc Merge pull request #13 from ivuorinen/travis-config
Travis CI Configuration and README badge
2019-08-23 09:30:05 -04:00
Ismo Vuorinen
a64f17891f Travis CI Configuration and README badge
This commit adds travis-ci.com configuration and the related build status badge to the README header.
2019-08-23 09:22:36 +03:00
Jani Gyllenberg
c601bee490 Merge pull request #12 from atefBB/patch-1
Update readme.md
2019-06-20 16:18:03 -04:00
Atef Ben Ali
d081af525c Update readme.md 2019-06-20 19:34:12 +02:00
Jani Gyllenberg
82e5865831 Merge pull request #11 from mateusjunges/junges-patch-1
Apply fixes from StyleCI and refactor readme
2019-06-20 13:32:35 -04:00
Mateus Junges
b5eacfb0f7 Refactor README.md 2019-06-20 13:37:33 -03:00
Mateus Junges
ec80e79b01 Merge pull request #1 from mateusjunges/analysis-XZENyb
Apply fixes from StyleCI
2019-06-20 13:23:47 -03:00
Mateus Junges
2b27089c60 Apply fixes from StyleCI 2019-06-20 16:23:30 +00:00
Jani Gyllenberg
bd682f0d78 Typo fixes 2019-06-13 10:08:23 -04:00
39 changed files with 817 additions and 4695 deletions

18
.editorconfig Normal file
View File

@@ -0,0 +1,18 @@
# EditorConfig is awesome: https://editorconfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2

43
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,43 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Laravel (please complete the following information):**
- Host OS: [e.g. Linux]
- Version [e.g. 6.1.0]
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

69
.github/workflows/phpunit.yml vendored Normal file
View File

@@ -0,0 +1,69 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: PHPUnit
on:
push:
branches: [master, main]
pull_request:
branches: [master, main]
jobs:
build-test:
runs-on: ubuntu-latest
permissions:
contents: write
statuses: write
strategy:
fail-fast: true
matrix:
php: [ '8.0', '8.1', '8.2', '8.3' ]
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
extensions: json, dom, curl, libxml, mbstring
coverage: xdebug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get composer cache directory
id: composer-cache-dir
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Get composer.lock or composer.json hash for caching
id: hash
shell: bash
run: |
if [ -f composer.lock ]; then
echo "lock=${{ hashFiles('**/composer.lock') }}" >> $GITHUB_OUTPUT
else
echo "lock=${{ hashFiles('**/composer.json') }}" >> $GITHUB_OUTPUT
fi
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ steps.hash.outputs.lock }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-${{ steps.hash.outputs.lock }}
${{ runner.os }}-php-${{ matrix.php }}-
${{ runner.os }}-php-
- name: Install Dependencies (prefer-${{ matrix.stability }})
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress
- name: Configure matchers
uses: mheap/phpunit-matcher-action@v1
- name: Execute composer test (Unit and Feature tests)
run: composer test:ci

3
.gitignore vendored
View File

@@ -12,4 +12,5 @@ Homestead.yaml
npm-debug.log
yarn-error.log
.env
.phpunit.result.cache
*.cache
composer.lock

30
.travis.yml Normal file
View File

@@ -0,0 +1,30 @@
language: php
env:
global:
- setup=stable
matrix:
fast_finish: true
include:
- php: 8.0
- php: 8.0
env: setup=lowest
- php: 8.1
- php: 8.1
env: setup=lowest
- php: 8.2
- php: 8.2
env: setup=lowest
sudo: false
cache:
directories:
- $HOME/.composer/cache
install:
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi
script: vendor/bin/phpunit

76
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at jani@nullincorporated.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

19
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,19 @@
# Contribution Guide
<a name="bug-reports"></a>
## Bug Reports
To encourage active collaboration, we strongly encourages pull requests, not just bug reports. "Bug reports" may also be sent in the form of a pull request containing a failing test.
However, if you file a bug report, your issue should contain a title and a clear description of the issue. You should also include as much relevant information as possible and a code sample that demonstrates the issue. The goal of a bug report is to make it easy for yourself - and others - to replicate the bug and develop a fix.
Remember, bug reports are created in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the bug report will automatically see any activity or that others will jump to fix it. Creating a bug report serves to help yourself and others start on the path of fixing the problem.
<a name="coding-style"></a>
## Coding Style
Laravel follows the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) coding standard and the [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md) autoloading standard, so do we.
## Security Vulnerabilities
If you discover a security vulnerability within the package, please send an e-mail to [@nullthoughts](https://github.com/nullthoughts) via [jani@nullincorporated.com](mailto:jani@nullincorporated.com). All security vulnerabilities will be promptly addressed.

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Jani Gyllenberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,34 +1,54 @@
{
"name": "distinctm/laravel-data-sync",
"description": "Laravel utility to keep records synced between enviroments through source control",
"name": "nullthoughts/laravel-data-sync",
"description": "Laravel utility to keep records synced between environments through source control",
"license": "MIT",
"authors": [
{
"name": "distinctm",
"email": "jani@marketdistinctly.com"
"name": "nullthoughts",
"email": "jani@nullincorporated.com"
}
],
"scripts": {
"lint": "pint --test",
"lint:fix": "pint --repair",
"psalm": "psalm",
"psalm:fix": "psalm --alter --issues=MissingReturnType,MissingParamType",
"test": "phpunit --coverage-text",
"test:ci": "phpunit --teamcity"
},
"require": {
"ext-json": "*"
"ext-json": "*",
"php": "^8.0"
},
"require-dev": {
"orchestra/testbench": "^3.7"
"orchestra/testbench": "^7|^8",
"rector/rector": "^1",
"ergebnis/composer-normalize": "^2",
"vimeo/psalm": "^5",
"psalm/plugin-laravel": "^2",
"laravel/pint": "^1"
},
"autoload": {
"psr-4" : {
"distinctm\\LaravelDataSync\\": "src/"
"psr-4": {
"nullthoughts\\LaravelDataSync\\": "src/"
}
},
"autoload-dev": {
"psr-4" : {
"distinctm\\LaravelDataSync\\Tests\\": "tests/"
"psr-4": {
"nullthoughts\\LaravelDataSync\\Tests\\": "tests/",
"nullthoughts\\LaravelDataSync\\Tests\\Fakes\\": "tests/fakes/"
}
},
"extra": {
"laravel": {
"providers": [
"distinctm\\LaravelDataSync\\DataSyncBaseServiceProvider"
"nullthoughts\\LaravelDataSync\\DataSyncBaseServiceProvider"
]
}
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true
}
}
}

4503
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,5 +4,5 @@ return [
'path' => base_path('sync'),
'order' => [
//
]
],
];

View File

@@ -1,25 +1,16 @@
<?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="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>

3
pint.json Normal file
View File

@@ -0,0 +1,3 @@
{
"preset": "laravel"
}

17
psalm.xml Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="true"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>

View File

@@ -1,10 +1,60 @@
<p align="center">
<a href="https://packagist.org/packages/nullthoughts/laravel-data-sync" target="_blank"><img src="https://poser.pugx.org/nullthoughts/laravel-data-sync/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/nullthoughts/laravel-data-sync" target="_blank"><img src="https://poser.pugx.org/nullthoughts/laravel-data-sync/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://travis-ci.com/nullthoughts/laravel-data-sync"><img src="https://api.travis-ci.com/nullthoughts/laravel-data-sync.svg?branch=master" alt="Travis CI Build Status: Master"></a>
</p>
# Laravel Data Sync
Laravel utility to keep records synced between enviroments through source control
Laravel utility to keep records synchronized between environments through source control
## Installation & Usage
- Via composer: `composer require distinctm/laravel-data-sync`
- Run `php artisan vendor:publish --provider="distinctm\LaravelDataSync\DataSyncBaseServiceProvider" --tag="data-sync-config"` to publish config file. Specify directory for sync data files (default is a new sync directory in the project root)
## [V3.1 branch](https://github.com/nullthoughts/laravel-data-sync/tree/v3.1) Notes (Work in progress)
- Adds support for Laravel 8+ models directory in `config/data-sync.php`:
```
'namespace' => '\\App\\Models\\',
```
- Adds ability to export existing Models to data sync files:
```
php artisan data:export User --criteria=name --criteria=email --except=id
```
which generates
```json
[
{
"_name": "Cameron Frye",
"properties->title": "Best Friend",
"phone_numbers->mobile": "555-555-5556",
"_email": "noreply@buellerandco.com",
}
]
```
- Further work is required to support remote disks. For testing & development of new V3.1 features, use `composer require nullthoughts/laravel-data-sync:v3.1.x-dev`
---
## Installation
You can install this package via composer:
```bash
composer require nullthoughts/laravel-data-sync
```
Or add this line in your `composer.json`, inside of the `require` section:
``` json
{
"require": {
"nullthoughts/laravel-data-sync": "^1.0",
}
}
```
then run ` composer install `
## Usage
- Run `php artisan vendor:publish --provider="nullthoughts\LaravelDataSync\DataSyncBaseServiceProvider" --tag="data-sync-config"` to publish config file. Specify directory for sync data files (default is a new sync directory in the project root)
- Create a JSON file for each model, using the model name as the filename. Example: Product.json would update the Product model
- Use nested arrays in place of hardcoded IDs for relationships
- Run `php artisan data:sync` (or `php artisan data:sync --model={model}` with the model flag to specify a model)
@@ -14,8 +64,8 @@ If using Laravel Forge, you can have the data sync run automatically on deploy.
```
if [ -f artisan ]
then
php artisan data:sync
php artisan migrate --force
php artisan data:sync
fi
```
@@ -144,4 +194,4 @@ translates to...
'role_id' => Role::where('slug', 'destroy-ferrari')->first()->id,
]);
```
```

16
rector.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPaths([
__DIR__.'/config',
__DIR__.'/src',
__DIR__.'/tests',
])
->withPhpSets()
->withPreparedSets(deadCode: true, codeQuality: true)
->withImportNames(removeUnusedImports: true)
->withTypeCoverageLevel(0);

View File

@@ -1,12 +1,14 @@
# Dev
- Check if null return from json decode (invalid JSON)
- Check if updateOrCreate returns anything
- Check if null return from json decode (invalid JSON)
- Check if updateOrCreate returns anything
# Usage
- Must have the columsn you are updating as fillable
- In config, specify disk to use (string)
- Document Forge example
- Must have the columsn you are updating as fillable
- In config, specify disk to use (string)
- Document Forge example
# Troubleshooting
- Make sure columns are fillable in model
- Make sure columns are fillable in model

View File

@@ -1,9 +1,9 @@
<?php
namespace distinctm\LaravelDataSync\Console\Commands;
namespace nullthoughts\LaravelDataSync\Console\Commands;
use distinctm\LaravelDataSync\Updater;
use Illuminate\Console\Command;
use nullthoughts\LaravelDataSync\Updater;
class Sync extends Command
{
@@ -11,15 +11,16 @@ class Sync extends Command
protected $description = 'Update Models with respective sync data files';
public function handle()
/** @psalm-api */
public function handle(): void
{
$path = $this->option('path');
$model = $this->option('model');
$this->info('Updating Models with sync data files');
(new Updater($path, $model))->run();
$this->comment('Data sync completed');
}
}

View File

@@ -1,12 +1,14 @@
<?php
namespace distinctm\LaravelDataSync;
namespace nullthoughts\LaravelDataSync;
use Illuminate\Support\ServiceProvider;
use nullthoughts\LaravelDataSync\Console\Commands\Sync;
/** @psalm-api */
class DataSyncBaseServiceProvider extends ServiceProvider
{
public function boot()
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->registerPublishing();
@@ -16,14 +18,14 @@ class DataSyncBaseServiceProvider extends ServiceProvider
public function register()
{
$this->commands([
Console\Commands\Sync::class,
Sync::class,
]);
}
protected function registerPublishing()
protected function registerPublishing(): void
{
$this->publishes([
__DIR__ . '/../config/data-sync.php' => config_path('data-sync.php'),
__DIR__.'/../config/data-sync.php' => config_path('data-sync.php'),
], 'data-sync-config');
}
}

View File

@@ -1,16 +1,16 @@
<?php
namespace distinctm\LaravelDataSync\Exceptions;
namespace nullthoughts\LaravelDataSync\Exceptions;
use Exception;
use Throwable;
class ErrorUpdatingModelException extends Exception
{
public function __construct(string $message = "", int $code = 0, Throwable $previous = null)
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
$this->message = "Error updating the {$message} model.";
}
}
}

View File

@@ -1,10 +1,10 @@
<?php
namespace distinctm\LaravelDataSync\Exceptions;
namespace nullthoughts\LaravelDataSync\Exceptions;
use Exception;
class FileDirectoryNotFoundException extends Exception
{
protected $message = 'Specified sync file directory does not exist';
}
}

View File

@@ -1,10 +1,10 @@
<?php
namespace distinctm\LaravelDataSync\Exceptions;
namespace nullthoughts\LaravelDataSync\Exceptions;
use Exception;
class NoCriteriaException extends Exception
{
protected $message = 'No criteria/attributes detected';
}
}

View File

@@ -1,16 +1,16 @@
<?php
namespace distinctm\LaravelDataSync\Exceptions;
namespace nullthoughts\LaravelDataSync\Exceptions;
use Exception;
use Throwable;
class NoRecordsInvalidJSONException extends Exception
{
public function __construct(string $message = "", int $code = 0, Throwable $previous = null)
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
$this->message = "No records or invalid JSON for {$message} model.";
}
}
}

View File

@@ -1,34 +1,70 @@
<?php
namespace distinctm\LaravelDataSync;
namespace nullthoughts\LaravelDataSync;
use distinctm\LaravelDataSync\Exceptions\FileDirectoryNotFoundException;
use distinctm\LaravelDataSync\Exceptions\NoCriteriaException;
use distinctm\LaravelDataSync\Exceptions\NoRecordsInvalidJSONException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use distinctm\LaravelDataSync\Exceptions\ErrorUpdatingModelException;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use nullthoughts\LaravelDataSync\Exceptions\ErrorUpdatingModelException;
use nullthoughts\LaravelDataSync\Exceptions\FileDirectoryNotFoundException;
use nullthoughts\LaravelDataSync\Exceptions\NoCriteriaException;
use nullthoughts\LaravelDataSync\Exceptions\NoRecordsInvalidJSONException;
use stdClass;
class Updater
{
private string $directory;
private Collection $files;
private bool $remote;
private string $disk;
private string $baseNamespace = '\\App\\';
/**
* Get files in sync directory
* Get files in sync directory.
*
* @param string|null $path
* @param string|null $model
* @param string|null $path
* @param string|null $model
* @param bool $remote
* @param string $disk
*
* @throws \distinctm\LaravelDataSync\Exceptions\FileDirectoryNotFoundException
* @throws \nullthoughts\LaravelDataSync\Exceptions\FileDirectoryNotFoundException
*/
public function __construct($path = null, $model = null)
public function __construct($path = null, $model = null, $remote = false, $disk = 's3')
{
$directory = $this->getDirectory($path);
$this->files = $this->getFiles($directory, $model);
$this->remote = $remote;
$this->disk = $disk;
$this->directory = $this->getDirectory($path);
$this->files = $this->getFiles($this->directory, $model);
}
/**
* Execute syncModel for each file
* Override the default namespace for the class.
*
* @return mixed
* @psalm-api
*/
public function setNamespace(string $namespace): void
{
$this->baseNamespace = $namespace;
}
/**
* Override the default directory for the class.
*
* @psalm-api
*/
public function setDirectory(string $directory): void
{
$this->directory = $directory;
}
/**
* Execute syncModel for each file.
*/
public function run()
{
@@ -37,7 +73,7 @@ class Updater
return $files->map(function ($file) {
try {
return $this->syncModel($file);
} catch (\ErrorException $e) {
} catch (\ErrorException) {
$model = pathinfo($file, PATHINFO_FILENAME);
throw new ErrorUpdatingModelException(ucwords($model));
@@ -46,12 +82,13 @@ class Updater
}
/**
* Parse each record for criteria/values and update/create model
* Parse each record for criteria/values and update/create model.
*
* @param string $file
*
* @return \Illuminate\Support\Collection
* @throws \distinctm\LaravelDataSync\Exceptions\NoRecordsInvalidJSONException
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
* @throws \nullthoughts\LaravelDataSync\Exceptions\NoRecordsInvalidJSONException
*/
protected function syncModel(string $file)
{
@@ -74,79 +111,86 @@ class Updater
}
/**
* Get directory path for sync files
* Get directory path for sync files.
*
* @param $path
*
* @return string
* @throws \distinctm\LaravelDataSync\Exceptions\FileDirectoryNotFoundException
*
* @throws \nullthoughts\LaravelDataSync\Exceptions\FileDirectoryNotFoundException
*/
protected function getDirectory($path)
protected function getDirectory(?string $path)
{
$directory = $path ?? config('data-sync.path', base_path('sync'));
if (!file_exists($directory)) {
if ($this->directoryMissingLocally($directory) || $this->directoryMissingRemotely($directory)) {
throw new FileDirectoryNotFoundException;
}
return $directory;
$this->directory = $directory;
return $this->directory;
}
/**
* Get list of files in directory
*
* @param string $directory
* @param string|null $model
* Get list of files in directory.
*
* @param string|null $model
* @return \Illuminate\Support\Collection
*/
protected function getFiles(string $directory, $model = null)
{
if ($model) {
return Collection::wrap($directory . '/' . $model . '.json');
return Collection::wrap($directory.'/'.$model.'.json');
}
return collect(File::files($directory))
->filter(function($file) {
$files = ($this->remote) ? Storage::disk($this->disk)->files($directory) : File::files($directory);
return collect($files)
->filter(function ($file) {
return pathinfo($file, PATHINFO_EXTENSION) == 'json';
})->map(function ($path) {
if (is_string($path)) {
return $path;
}
return $path->getPathname();
});
}
/**
* Sort Models by pre-configured order
* Sort Models by pre-configured order.
*
*
* @param \Illuminate\Support\Collection $files
* @return \Illuminate\Support\Collection
*/
protected function sortModels(\Illuminate\Support\Collection $files)
{
if(empty(config('data-sync.order'))) {
if (empty(config('data-sync.order'))) {
return $files;
}
return $files->sortBy(function($file) use ($files) {
return $files->sortBy(function ($file) use ($files) {
$filename = pathinfo($file, PATHINFO_FILENAME);
$order = array_search(
studly_case($filename),
Str::studly($filename),
config('data-sync.order')
);
return $order !== false ? $order : (count($files) + 1);
});
}
/**
* Filter record criteria
* Filter record criteria.
*
* @param object $record
*
* @return \Illuminate\Support\Collection
* @throws \distinctm\LaravelDataSync\Exceptions\NoCriteriaException
*
* @throws \nullthoughts\LaravelDataSync\Exceptions\NoCriteriaException
*/
protected function getCriteria(object $record)
protected function getCriteria(stdClass $record)
{
$criteria = collect($record)->filter(function ($value, $key) {
return $this->isCriteria($key);
@@ -162,13 +206,12 @@ class Updater
}
/**
* Filter record values
* Filter record values.
*
* @param object $record
*
* @return \Illuminate\Support\Collection
*/
protected function getValues(object $record)
protected function getValues(stdClass $record)
{
return collect($record)->reject(function ($value, $key) {
if ($this->isCriteria($key)) {
@@ -184,28 +227,30 @@ class Updater
}
/**
* Returns model name for file
* Returns model name for file.
*
* @param string $name
*
* @return string
*/
protected function getModel(string $name)
{
return '\\App\\' . studly_case(pathinfo($name, PATHINFO_FILENAME));
return $this->baseNamespace.Str::studly(pathinfo($name, PATHINFO_FILENAME));
}
/**
* Parses JSON from file and returns collection
* Parses JSON from file and returns collection.
*
* @param string $file
*
* @return \Illuminate\Support\Collection
* @throws \distinctm\LaravelDataSync\Exceptions\NoRecordsInvalidJSONException
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
* @throws \nullthoughts\LaravelDataSync\Exceptions\NoRecordsInvalidJSONException
*/
protected function getRecords(string $file)
{
$records = collect(json_decode(File::get($file)));
$fetchedFile = ($this->remote) ? Storage::disk($this->disk)->get($file) : File::get($file);
$records = collect(json_decode($fetchedFile));
if ($records->isEmpty()) {
throw new NoRecordsInvalidJSONException($file);
@@ -215,11 +260,10 @@ class Updater
}
/**
* Check if column is criteria for a condition match
* Check if column is criteria for a condition match.
*
* @param string $key
*
* @return boolean
* @param string $key
* @return bool
*/
protected function isCriteria($key)
{
@@ -227,19 +271,16 @@ class Updater
}
/**
* Return ID for nested key-value pairs
* Return ID for nested key-value pairs.
*
* @param string $key
* @param object $values
*
* @return array
*/
protected function resolveId(string $key, object $values)
protected function resolveId(string $key, stdClass $values)
{
$model = $this->getModel($key);
$values = collect($values)->mapWithKeys(function ($value, $column) {
if (is_object($value)) {
return $this->resolveId($column, $value);
}
@@ -247,13 +288,12 @@ class Updater
return [$column => $value];
})->toArray();
return [$key . '_id' => $model::where($values)->first()->id];
return [$key.'_id' => $model::where($values)->first()->id];
}
/**
* Detect nested objects and resolve them
* Detect nested objects and resolve them.
*
* @param \Illuminate\Support\Collection $record
*
* @return array
*/
@@ -268,4 +308,21 @@ class Updater
})->toArray();
}
/**
* @param \Illuminate\Config\Repository $directory
* @return bool
*/
protected function directoryMissingLocally($directory)
{
return ! $this->remote && ! file_exists($directory);
}
/**
* @param \Illuminate\Config\Repository $directory
* @return bool
*/
protected function directoryMissingRemotely($directory)
{
return $this->remote && ! Storage::disk($this->disk)->exists($directory);
}
}

View File

@@ -1,8 +1,9 @@
<?php
namespace distinctm\LaravelDataSync\Tests;
namespace nullthoughts\LaravelDataSync\Tests;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Roles extends Model
{
@@ -10,8 +11,8 @@ class Roles extends Model
protected $guarded = [];
public function supervisor()
public function supervisor(): BelongsTo
{
return $this->belongsTo(Supervisor::class);
}
}
}

View File

@@ -1,8 +1,9 @@
<?php
namespace distinctm\LaravelDataSync\Tests;
namespace nullthoughts\LaravelDataSync\Tests;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Supervisor extends Model
{
@@ -10,8 +11,8 @@ class Supervisor extends Model
protected $guarded = [];
public function roles()
public function roles(): HasMany
{
return $this->hasMany(Roles::class);
}
}
}

View File

@@ -1,35 +1,40 @@
<?php
namespace distinctm\LaravelDataSync\Tests;
namespace nullthoughts\LaravelDataSync\Tests;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class TestCase extends \Orchestra\Testbench\TestCase
{
protected function getEnvironmentSetUp($app)
/** @psalm-suppress PropertyNotSetInConstructor */
public string $testDataPath;
protected function getEnvironmentSetUp($app): void
{
$app['config']->set('database.default', 'testdb');
$app['config']->set('database.connections.testdb', [
'driver' => 'sqlite',
'database' => ':memory:'
'database' => ':memory:',
]);
$this->testDataPath = __DIR__.'/test-data';
}
protected function setUp()
protected function setUp(): void
{
parent::setUp();
Schema::create('supervisors', function (Blueprint $table) {
Schema::create('supervisors', static function (Blueprint $table): void {
$table->increments('id');
$table->string('name');
});
Schema::create('roles', function (Blueprint $table) {
Schema::create('roles', static function (Blueprint $table): void {
$table->increments('id');
$table->string('slug');
$table->unsignedInteger('supervisor_id')->nullable();
$table->string('category')->nullable();
});
}
}
}

View File

@@ -0,0 +1,164 @@
<?php
namespace nullthoughts\LaravelDataSync\Tests\Unit;
use Exception;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use nullthoughts\LaravelDataSync\Exceptions\ErrorUpdatingModelException;
use nullthoughts\LaravelDataSync\Tests\Fakes\UpdaterFake;
use nullthoughts\LaravelDataSync\Tests\Roles;
use nullthoughts\LaravelDataSync\Tests\Supervisor;
use nullthoughts\LaravelDataSync\Tests\TestCase;
class UpdaterRemoteTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Storage::fake('s3');
Storage::disk('s3')->put('test-data/roles.json', File::get(__DIR__.'/../test-data/roles.json'));
foreach (File::directories(__DIR__.'/../test-data/') as $directory) {
$files = File::files($directory);
foreach ($files as $file) {
Storage::disk('s3')->put('test-data/'.basename($directory).'/'.$file->getRelativePathname(), File::get($file->getPathname()));
}
}
}
/** @test */
public function it_adds_roles_to_the_database_in_remote()
{
$updater = new UpdaterFake('test-data', 'roles', true, 's3');
$updater->run();
$this->assertDatabaseHas('roles', ['slug' => 'update-student-records']);
$this->assertDatabaseHas('roles', ['slug' => 'borrow-ferrari']);
$this->assertDatabaseHas('roles', ['slug' => 'destroy-ferrari']);
}
/** @test */
public function it_can_default_to_configuration_in_remote()
{
config()->set('data-sync.path', 'test-data');
$updater = new UpdaterFake(null, null, true, 's3');
$updater->run();
$this->assertDatabaseHas('roles', ['slug' => 'update-student-records']);
$this->assertDatabaseHas('roles', ['slug' => 'borrow-ferrari']);
$this->assertDatabaseHas('roles', ['slug' => 'destroy-ferrari']);
}
/** @test */
public function it_can_update_an_existing_record_in_remote()
{
config()->set('data-sync.path', 'test-data');
(new UpdaterFake(null, null, true, 's3'))->run();
config()->set('data-sync.path', 'test-data/valid');
(new UpdaterFake(null, null, true, 's3'))->run();
$this->assertDatabaseHas('roles', ['category' => 'changed']);
$this->assertDatabaseHas('roles', ['category' => 'changed']);
$this->assertDatabaseHas('roles', ['category' => 'changed']);
}
/** @test */
public function it_can_update_the_relationship_in_remote()
{
$supervisor = Supervisor::create([
'name' => 'CEO',
]);
config()->set('data-sync.path', 'test-data/relationship');
(new UpdaterFake(null, null, true, 's3'))->run();
$this->assertEquals($supervisor->id, Roles::first()->supervisor_id);
$this->assertTrue($supervisor->is(Roles::first()->supervisor));
}
/**
* @test
*
* @group current
*/
public function exception_is_thrown_if_the_directory_does_not_exists(): void
{
try {
new UpdaterFake(null, null, true, 's3');
$this->fail('exception was thrown');
} catch (Exception $e) {
$this->assertEquals('Specified sync file directory does not exist', $e->getMessage());
}
}
/** @test */
public function invalid_json_throws_an_exception_in_remote(): void
{
try {
$updater = new UpdaterFake('test-data/invalid-json', null, true, 's3');
$updater->run();
$this->fail('exception was thrown');
} catch (Exception $e) {
$this->assertStringContainsString('No records or invalid JSON for', $e->getMessage());
}
}
/** @test */
public function the_json_must_contain_a_key_with_an_underscore_in_remote(): void
{
try {
$updater = new UpdaterFake('test-data/no-criteria', null, true, 's3');
$updater->run();
$this->fail('exception was thrown');
} catch (Exception $e) {
$this->assertEquals('No criteria/attributes detected', $e->getMessage());
}
}
/** @test */
public function order_of_imports_can_be_defined_in_config_in_remote(): void
{
config()->set('data-sync.order', [
'Supervisor',
'Roles',
]);
$updater = new UpdaterFake('test-data/ordered', null, true, 's3');
$updater->run();
$this->assertDatabaseHas('roles', ['slug' => 'update-student-records']);
$this->assertDatabaseHas('supervisors', ['name' => 'CEO']);
}
/** @test */
public function exception_is_thrown_if_imports_are_in_incorrect_order_in_remote(): void
{
config()->set('data-sync.order', [
'Roles',
'Supervisor',
]);
$this->expectException(ErrorUpdatingModelException::class);
$updater = new UpdaterFake('test-data/ordered', null, true, 's3');
$updater->run();
}
/** @test */
public function it_ignores_non_json_files_in_remote(): void
{
$updater = new UpdaterFake('test-data/not-json', null, true, 's3');
$updater->run();
$this->assertDatabaseMissing('roles', ['slug' => 'update-student-records']);
}
}

View File

@@ -1,17 +1,20 @@
<?php
namespace distinctm\LaravelDataSync\Tests;
namespace nullthoughts\LaravelDataSync\Tests\Unit;
use distinctm\LaravelDataSync\Tests\Fakes\UpdaterFake;
use Exception;
use distinctm\LaravelDataSync\Exceptions\ErrorUpdatingModelException;
use nullthoughts\LaravelDataSync\Exceptions\ErrorUpdatingModelException;
use nullthoughts\LaravelDataSync\Tests\fakes\UpdaterFake;
use nullthoughts\LaravelDataSync\Tests\Roles;
use nullthoughts\LaravelDataSync\Tests\Supervisor;
use nullthoughts\LaravelDataSync\Tests\TestCase;
class UpdaterTest extends TestCase
{
/** @test */
public function it_adds_roles_to_the_database()
public function it_adds_roles_to_the_database(): void
{
$updater = new UpdaterFake(__DIR__ . '/../test-data', 'roles');
$updater = new UpdaterFake($this->testDataPath, 'roles');
$updater->run();
@@ -23,9 +26,9 @@ class UpdaterTest extends TestCase
/** @test */
public function it_can_default_to_configuration()
{
config()->set('data-sync.path', __DIR__ . '/../test-data');
config()->set('data-sync.path', $this->testDataPath);
$updater = new UpdaterFake();
$updater = new UpdaterFake;
$updater->run();
@@ -37,11 +40,11 @@ class UpdaterTest extends TestCase
/** @test */
public function it_can_update_an_existing_record()
{
config()->set('data-sync.path', __DIR__ . '/../test-data');
(new UpdaterFake())->run();
config()->set('data-sync.path', $this->testDataPath);
(new UpdaterFake)->run();
config()->set('data-sync.path', __DIR__ . '/../test-data/valid');
(new UpdaterFake())->run();
config()->set('data-sync.path', $this->testDataPath.'/valid');
(new UpdaterFake)->run();
$this->assertDatabaseHas('roles', ['category' => 'changed']);
$this->assertDatabaseHas('roles', ['category' => 'changed']);
@@ -49,95 +52,91 @@ class UpdaterTest extends TestCase
}
/** @test */
public function it_can_update_the_relationship()
public function it_can_update_the_relationship(): void
{
$supervisor = Supervisor::create([
'name' => 'CEO',
]);
config()->set('data-sync.path', __DIR__ . '/../test-data/relationship', 'roles');
(new UpdaterFake())->run();
config()->set('data-sync.path', $this->testDataPath.'/relationship', 'roles');
(new UpdaterFake)->run();
$this->assertEquals($supervisor->id, Roles::first()->supervisor_id);
$this->assertTrue($supervisor->is(Roles::first()->supervisor));
}
/** @test */
public function exception_is_thrown_if_the_directory_does_not_exists()
public function exception_is_thrown_if_the_directory_does_not_exists(): void
{
try {
new UpdaterFake();
new UpdaterFake;
$this->fail('exception was thrown');
} catch (Exception $e) {
$this->assertEquals('Specified sync file directory does not exist', $e->getMessage());
}
}
/** @test */
public function invalid_json_throws_an_exception()
public function invalid_json_throws_an_exception(): void
{
try {
$updater = new UpdaterFake(__DIR__ . '/../test-data/invalid-json');
$updater = new UpdaterFake($this->testDataPath.'/invalid-json');
$updater->run();
$this->fail('exception was thrown');
} catch (Exception $e) {
$this->assertContains('No records or invalid JSON for', $e->getMessage());
$this->assertStringContainsString('No records or invalid JSON for', $e->getMessage());
}
}
/** @test */
public function the_json_must_contain_a_key_with_an_underscore()
public function the_json_must_contain_a_key_with_an_underscore(): void
{
try {
$updater = new UpdaterFake(__DIR__ . '/../test-data/no-criteria');
$updater = new UpdaterFake($this->testDataPath.'/no-criteria');
$updater->run();
$this->fail('exception was thrown');
} catch (Exception $e) {
$this->assertEquals('No criteria/attributes detected', $e->getMessage());
$this->assertEquals('No criteria/attributes detected', $e->getMessage());
}
}
/** @test */
public function order_of_imports_can_be_defined_in_config()
public function order_of_imports_can_be_defined_in_config(): void
{
config()->set('data-sync.order', [
'Supervisor',
'Roles'
'Roles',
]);
$updater = new UpdaterFake(__DIR__ . '/../test-data/ordered');
$updater = new UpdaterFake($this->testDataPath.'/ordered');
$updater->run();
$this->assertDatabaseHas('roles', ['slug' => 'update-student-records']);
$this->assertDatabaseHas('supervisors', ['name' => 'CEO']);
}
/** @test */
public function exception_is_thrown_if_imports_are_in_incorrect_order()
public function exception_is_thrown_if_imports_are_in_incorrect_order(): void
{
config()->set('data-sync.order', [
'Roles',
'Supervisor'
'Supervisor',
]);
$this->expectException(ErrorUpdatingModelException::class);
$updater = new UpdaterFake(__DIR__ . '/../test-data/ordered');
$updater = new UpdaterFake($this->testDataPath.'/ordered');
$updater->run();
}
/** @test */
public function it_ignores_non_json_files()
public function it_ignores_non_json_files(): void
{
$updater = new UpdaterFake(__DIR__ . '/../test-data/not-json');
$updater = new UpdaterFake($this->testDataPath.'/not-json');
$updater->run();
$this->assertDatabaseMissing('roles', ['slug' => 'update-student-records']);
}
}
}

View File

@@ -1,15 +1,16 @@
<?php
namespace distinctm\LaravelDataSync\Tests\Fakes;
namespace nullthoughts\LaravelDataSync\Tests\Fakes;
use distinctm\LaravelDataSync\Updater;
use Illuminate\Support\Str;
use nullthoughts\LaravelDataSync\Updater;
class UpdaterFake extends Updater
{
protected function getModel(string $name)
{
return '\\distinctm\\LaravelDataSync\\Tests\\' . studly_case(
return '\\nullthoughts\\LaravelDataSync\\Tests\\'.Str::studly(
pathinfo($name, PATHINFO_FILENAME)
);
}
}
}

View File

@@ -1,3 +1 @@
[
]
[]

View File

@@ -2,4 +2,4 @@
{
"string": "update-student-records"
}
]
]

View File

@@ -6,4 +6,4 @@
"name": "CEO"
}
}
]
]

View File

@@ -6,4 +6,4 @@
"name": "CEO"
}
}
]
]

View File

@@ -2,4 +2,4 @@
{
"_name": "CEO"
}
]
]

View File

@@ -6,4 +6,4 @@
"name": "CEO"
}
}
]
]

View File

@@ -11,4 +11,4 @@
"_slug": "destroy-ferrari",
"category": "cars"
}
]
]

View File

@@ -11,4 +11,4 @@
"_slug": "destroy-ferrari",
"category": "changed"
}
]
]