Skip to content

Commit

Permalink
Added laravel 10 support, strict types, GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Feb 16, 2023
1 parent 1c9cdc9 commit d1ac6cc
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 152 deletions.
11 changes: 5 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
/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
46 changes: 46 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Unit Test

on: [ push ]

jobs:
PHPUnit:
strategy:
matrix:
include:
# Laravel 10.*
- php: 8.1
laravel: 10.*
composer-flag: '--prefer-stable'
- php: 8.2
laravel: 10.*
composer-flag: '--prefer-stable'
- php: 8.1
laravel: 10.*
composer-flag: '--prefer-lowest'
- php: 8.2
laravel: 10.*
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 }}" --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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
.Trashes
ehthumbs.db
Thumbs.db
vendor
/vendor
coverage
composer.lock
.php-cs-fixer.cache
.phpunit.result.cache
/coverage
.phpunit.cache

10 changes: 6 additions & 4 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

return (new PhpCsFixer\Config())
->setRiskyAllowed(false)
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@PSR12' => true,
'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.

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

This file was deleted.

8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
],
"minimum-stability": "stable",
"require": {
"php": "^7.1|^8",
"illuminate/database": "^6|^7|^8|^9"
"php": ">=8.1",
"illuminate/database": "^10"
},
"require-dev": {
"phpunit/phpunit": "^7.0|^8.0|^9.0",
"friendsofphp/php-cs-fixer": "^2.16|3.*",
"phpunit/phpunit": "^10",
"friendsofphp/php-cs-fixer": "^3",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
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
5 changes: 4 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?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>
Expand Down
61 changes: 25 additions & 36 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Feature">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<server name="APP_ENV" value="testing"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="QUEUE_DRIVER" value="sync"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Feature">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<server name="APP_ENV" value="testing"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="QUEUE_DRIVER" value="sync"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
21 changes: 12 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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

Custom relationship for Eloquent that merges/combines multiple one-to-may (hasMany) relationships.
This relation fully supports lazy and eager loading.
Expand All @@ -17,14 +17,17 @@ You can install the package via composer with following command:
composer require korridor/laravel-has-many-merged
```

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

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

### Requirements

This package is tested for the following Laravel versions:

- 9.* (PHP 8.0, 8.1)
- 8.* (PHP 7.3, 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 examples

Expand All @@ -47,23 +50,23 @@ class User extends Model
/**
* @return HasManyMerged|Message
*/
public function messages()
public function messages(): HasManyMerged
{
return $this->hasManyMerged(Message::class, ['sender_user_id', 'receiver_user_id']);
}

/**
* @return HasMany|Message
*/
public function sentMessages()
public function sentMessages(): HasMany
{
return $this->hasMany(Message::class, 'sender_user_id');
}

/**
* @return HasMany|Message
*/
public function receivedMessages()
public function receivedMessages(): HasMany
{
return $this->hasMany(Message::class, 'receiver_user_id');
}
Expand Down
Loading

0 comments on commit d1ac6cc

Please sign in to comment.