Skip to content

Commit

Permalink
Laravel 10, namespace change, GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Feb 19, 2023
1 parent 148c5d0 commit 6f7e12f
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 141 deletions.
10 changes: 4 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
/phpunit.xml export-ignore
/phpunit.xml.old export-ignore
/phpcs.xml export-ignore
/phpcs.xml export-ignore
/docker export-ignore
/.travis.yml export-ignore
/.styleci.yml export-ignore
/.php_cs export-ignore
/.editorconfig export-ignore
/.php-cs-fixer.php export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/vendor export-ignore
/.github export-ignore
/coverage export-ignore
/.phpunit.cache export-ignore
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lint

on: [ push ]

jobs:
lint_with_php_cs_fixer:
name: Lint code with PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install dependencies
uses: php-actions/composer@v6
with:
command: install
only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs
php_version: 8.1

- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run

lint_with_phpcs:
name: Lint code with PHP CodeSniffer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install dependencies
uses: php-actions/composer@v6
with:
command: install
only_args: -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --ignore-platform-reqs
php_version: 8.1

- name: Run PHP CodeSniffer
run: vendor/bin/phpcs --extensions=php
50 changes: 50 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Unit Test

on: [ push ]

jobs:
PHPUnit:
strategy:
matrix:
include:
# Laravel 10.*
- php: 8.1
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-stable'
- php: 8.2
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-stable'
- php: 8.1
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-lowest'
- php: 8.2
laravel: 10.*
testbench: 8.*
composer-flag: '--prefer-lowest'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: xdebug

- name: Install dependencies
run: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update

- name: Update dependencies
run: composer update ${{ matrix.composer-flag }} --prefer-dist --no-interaction

- name: Run PHPUnit
run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Custom #
######################
Thumbs.db
vendor
coverage
composer.lock
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
.phpunit.cache
13 changes: 10 additions & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?php

return (new PhpCsFixer\Config())
->setRiskyAllowed(false)
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@PSR12' => true,
'@PSR12:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'declare_strict_types' => true,
'modernize_types_casting' => true,
'void_return' => true,
])
->setUsingCache(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
)
;
;
1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

51 changes: 0 additions & 51 deletions .travis.yml

This file was deleted.

27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

[![Latest Version on Packagist](https://img.shields.io/packagist/v/korridor/laravel-has-many-sync?style=flat-square)](https://packagist.org/packages/korridor/laravel-has-many-sync)
[![License](https://img.shields.io/packagist/l/korridor/laravel-has-many-sync?style=flat-square)](license.md)
[![GitHub Workflow Lint](https://img.shields.io/github/actions/workflow/status/korridor/laravel-has-many-sync/lint.yml?label=lint&style=flat-square)](https://github.com/korridor/laravel-has-many-sync/actions/workflows/lint.yml)
[![GitHub Workflow Tests](https://img.shields.io/github/actions/workflow/status/korridor/laravel-has-many-sync/unittests.yml?label=tests&style=flat-square)](https://github.com/korridor/laravel-has-many-sync/actions/workflows/unittests.yml)
[![Codecov](https://img.shields.io/codecov/c/github/korridor/laravel-has-many-sync?style=flat-square)](https://codecov.io/gh/korridor/laravel-has-many-sync)
[![TravisCI](https://img.shields.io/travis/korridor/laravel-has-many-sync?style=flat-square)](https://travis-ci.org/korridor/laravel-has-many-sync)
[![StyleCI](https://styleci.io/repos/202400425/shield)](https://styleci.io/repos/202400425)

**Note: This package is a fork of [alfa6661/laravel-hasmany-sync](https://github.com/alfa6661/laravel-hasmany-sync). I already added tests and I plan to add more feature in the future.**

Allow sync method for Laravel Has Many Relationship.

Expand All @@ -18,14 +16,19 @@ You can install the package via composer with following command:
composer require korridor/laravel-has-many-sync
```

If you want to use this package with older Laravel/PHP version please install the 1.* version.

```bash
composer require korridor/laravel-has-many-merged "^1"
```

**Warning: The 1.\* versions use a different namespace!**

### Requirements

This package is tested for the following Laravel and PHP versions:

- 9.* (PHP 8.0, 8.1)
- 8.* (PHP 7.4, 8.0, 8.1)
- 7.* (PHP 7.2, 7.3, 7.4)
- 6.* (PHP 7.2, 7.3)
- 10.* (PHP 8.1, 8.2)

## Usage

Expand All @@ -35,9 +38,9 @@ This package is tested for the following Laravel and PHP versions:
class Customer extends Model
{
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
* @return HasMany<CustomerContact>
*/
public function contacts()
public function contacts(): HasMany
{
return $this->hasMany(CustomerContact::class);
}
Expand Down Expand Up @@ -130,6 +133,10 @@ The `composer test-coverage` command runs all tests with phpunit and creates a c
The `composer fix` command formats the code with [php-cs-fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).
The `composer lint` command checks the code with [phpcs](https://github.com/squizlabs/PHP_CodeSniffer).

## Credits

This package is a fork of [alfa6661/laravel-hasmany-sync](https://github.com/alfa6661/laravel-hasmany-sync).

## License

This package is licensed under the MIT License (MIT). Please see [license file](license.md) for more information.
Expand Down
27 changes: 15 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
}
],
"require": {
"php": "^7.1|^8",
"illuminate/database": "^5.8|6.*|7.*|8.*|9.*",
"illuminate/support": "^5.8|6.*|7.*|8.*|9.*"
"php": ">=8.1",
"illuminate/database": "^10",
"illuminate/support": "^10"
},
"require-dev": {
"orchestra/testbench": "^3.8|^4.0|^5.0|^6.0|^7",
"phpunit/phpunit": "^7.0|^8.0|^9.0",
"friendsofphp/php-cs-fixer": "^2.16|^3",
"orchestra/testbench": "^8",
"phpunit/phpunit": "^10.0",
"friendsofphp/php-cs-fixer": "^3",
"squizlabs/php_codesniffer": "^3.5"
},
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Alfa6661\\EloquentHasManySync\\": "src"
"Korridor\\LaravelHasManySync\\": "src"
}
},
"autoload-dev": {
Expand All @@ -40,15 +40,18 @@
"extra": {
"laravel": {
"providers": [
"Alfa6661\\EloquentHasManySync\\ServiceProvider"
"Korridor\\LaravelHasManySync\\ServiceProvider"
]
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
"fix": "./vendor/bin/php-cs-fixer fix",
"lint": "./vendor/bin/phpcs --extensions=php"
"test": "@php vendor/bin/phpunit",
"test-coverage": [
"@putenv XDEBUG_MODE=coverage",
"@php vendor/bin/phpunit --coverage-html coverage"
],
"fix": "@php ./vendor/bin/php-cs-fixer fix",
"lint": "@php ./vendor/bin/phpcs --extensions=php"
},
"config": {
"sort-packages": true
Expand Down
12 changes: 4 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
FROM php:7.4-cli
FROM php:8.1-cli

RUN apt-get update && apt-get install -y \
zlib1g-dev \
libzip-dev
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN docker-php-ext-install zip

RUN pecl install xdebug-2.8.1 \
&& docker-php-ext-enable xdebug
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions zip xdebug

# Install composer and add its bin to the PATH.
RUN curl -s http://getcomposer.org/installer | php && \
Expand Down
6 changes: 5 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0"?>
<ruleset name="ASH2">
<description>The ASH2 coding standard.</description>
<rule ref="PSR2">
<rule ref="PSR12">
<properties>
<property name="lineLimit" value="150"/>
</properties>
</rule>

<file>src/</file>
<file>tests/</file>
</ruleset>
9 changes: 3 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
Expand Down
Loading

0 comments on commit 6f7e12f

Please sign in to comment.