Skip to content

Added support for Laravel 10 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 7 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
operating_system: [ubuntu-latest]
php_versions: ['7.4']
php_versions: ['8.1']
fail-fast: false
env:
PHP_CS_FIXER_FUTURE_MODE: '0'
Expand Down Expand Up @@ -68,31 +68,12 @@ jobs:
strategy:
fail-fast: false
matrix:
coverage: [false]
coverage: [true]
experimental: [false]
operating_system: [ubuntu-latest]
postgres: ['11']
laravel: ['^6.0', '^7.0', '^8.0']
php_versions: ['7.3', '7.4']
include:
- operating_system: ubuntu-latest
postgres: '11'
php_versions: '7.4'
experimental: false
laravel: '^8.0'
coverage: true
- operating_system: ubuntu-latest
postgres: '12'
php_versions: '8.0'
laravel: '^8.0'
experimental: false
coverage: false
- operating_system: ubuntu-latest
postgres: '13'
php_versions: '8.0'
laravel: '^8.0'
experimental: true
coverage: false
postgres: ['11', '12', '13', '14', '15']
laravel: ['^10']
php_versions: ['8.1', '8.2']
runs-on: '${{ matrix.operating_system }}'
services:
postgres:
Expand Down Expand Up @@ -152,9 +133,9 @@ jobs:
-e "s/\${HOST}/${{ env.DB_HOST }}/" \
phpunit.xml.dist > phpunit.xml
if [[ ${{ matrix.coverage }} == true ]]; then
./vendor/bin/phpunit --verbose --stderr --coverage-clover build/logs/clover.xml --coverage-text
./vendor/bin/phpunit --stderr --coverage-clover build/logs/clover.xml --coverage-text
else
./vendor/bin/phpunit --verbose --stderr
./vendor/bin/phpunit --stderr
fi
working-directory: './'
- name: 'Upload coverage results to Coveralls'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ phpunit.xml
.phpunit.result.cache
.DS_Store
composer.lock
/.phpunit.cache
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@


## Installation
```

```shell
composer require umbrellio/php-table-sync
```

## Usage

Let's describe the model that needs to be synchronized using an example `User.php`
```

```php
...
User extends Model implements SyncableModel
{
Expand Down Expand Up @@ -48,15 +51,15 @@ When the model changes, the data will be sent according to the rules of `TableSy
## Logging
Logging based on the Monolog package and contains some extensions for it.
- specify the logging channel in `config/table_sync.php`
```
```php
...
'log' => [
'channel' => 'table_sync',
],
...
```
- and describe this channel in `config/logging.php`
```
```php
...
'table_sync' => [
'driver' => 'stack',
Expand All @@ -80,7 +83,7 @@ Logging based on the Monolog package and contains some extensions for it.
##### You can use the built-in `LineTableSyncFormatter::class` with the available parameters: `%datetime%` `%message%` `%direction%` `%model%` `%event%` `%routing%` `%attributes%` `%exception%`

###### Driver `influxdb` is an additional option and is not required to add in config
```
```php
...
'table_sync' => [
'driver' => 'daily',
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
"license": "MIT",
"type": "library",
"require": {
"php": "^7.3|^7.4|^8.0",
"php": "^8.1",
"ext-json": "*",
"php-amqplib/php-amqplib": "^2.8 || ^3.0",
"laravel/framework": "^5.8|^6.0|^7.0|^8.0|^9.0",
"thecodingmachine/safe": "^0.1.6|^1.0",
"umbrellio/laravel-heavy-jobs": "^1.0.3|^2.0|^3.0",
"monolog/monolog": "^1.1|^2.0",
"ext-posix": "*",
"php-amqplib/php-amqplib": "^3.0",
"laravel/framework": "^10.0",
"thecodingmachine/safe": "^2.0",
"umbrellio/laravel-heavy-jobs": "^3.0",
"monolog/monolog": "^3.0",
"influxdb/influxdb-php": "^1.15"
},
"require-dev": {
"phpunit/phpunit": "^7.3|^8.5|^9.4",
"phpunit/phpunit": "^10.0",
"php-mock/php-mock": "^2.0",
"orchestra/testbench": "^3.8|^4.8|^5.7|^6.2|^7.0",
"orchestra/testbench": "^8.0",
"mockery/mockery": "^1.0",
"mikey179/vfsstream": "^1.6",
"umbrellio/code-style-php": "^1.0",
"symplify/easy-coding-standard": "^9.3.15",
"symplify/easy-coding-standard": "^11.0",
"laravel/legacy-factories": "*",
"php-coveralls/php-coveralls": "^2.1",
"squizlabs/php_codesniffer": "^3.5"
Expand Down
74 changes: 48 additions & 26 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,53 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer;
use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\ClassNotation\SingleTraitInsertPerStatementFixer;
use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocLineSpanFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/vendor/umbrellio/code-style-php/umbrellio-cs.php');

$services = $containerConfigurator->services();

$services->set(PhpUnitTestAnnotationFixer::class)
->call('configure', [[
'style' => 'annotation',
]]);

$services->set(DeclareStrictTypesFixer::class);

$services->set(BinaryOperatorSpacesFixer::class)
->call('configure', [[
'default' => 'single_space',
]]);

$parameters = $containerConfigurator->parameters();

$parameters->set('cache_directory', '.ecs_cache');

$parameters->set('exclude_files', ['vendor/*', 'database/*']);
use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([__DIR__ . '/app', __DIR__ . '/tests']);
$ecsConfig->parallel();

$ecsConfig->sets([SetList::PSR_12]);
$ecsConfig->sets([SetList::CLEAN_CODE]);
$ecsConfig->sets([SetList::COMMON]);
$ecsConfig->sets([SetList::SYMPLIFY]);
$ecsConfig->sets([SetList::STRICT]);

$ecsConfig->skip([
'vendor/*',
'database/*',
'.ecs_cache/*',

ArrayIndentationFixer::class,
MethodArgumentSpaceFixer::class,
SingleTraitInsertPerStatementFixer::class,
PhpdocTrimFixer::class,
AssignmentInConditionSniff::class,
MethodChainingNewlineFixer::class,
ArrayOpenerAndCloserNewlineFixer::class,
NotOperatorWithSuccessorSpaceFixer::class,
PhpdocLineSpanFixer::class,
MethodChainingIndentationFixer::class,
ClassAttributesSeparationFixer::class,
LineLengthFixer::class,
NoSuperfluousPhpdocTagsFixer::class,
ExplicitStringVariableFixer::class,
PhpUnitTestAnnotationFixer::class,
]);
};
15 changes: 0 additions & 15 deletions ecs.yml

This file was deleted.

33 changes: 15 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
colors="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"
>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage>
<include>
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./database</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory suffix=".php">./database</directory>
</exclude>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
<ini name="error_reporting" value="-1" />
<ini name="error_reporting" value="-1"/>
<var name="db_type" value="pdo_pgsql"/>
<var name="db_host" value="${HOST}" />
<var name="db_username" value="${USERNAME}" />
<var name="db_password" value="${PASSWORD}" />
<var name="db_database" value="${DATABASE}" />
<var name="db_host" value="${HOST}"/>
<var name="db_username" value="${USERNAME}"/>
<var name="db_password" value="${PASSWORD}"/>
<var name="db_database" value="${DATABASE}"/>
<var name="db_port" value="5432"/>
</php>
<testsuites>
Expand Down
8 changes: 3 additions & 5 deletions src/Integration/Laravel/Console/PidManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

class PidManager
{
private $pathToPidFile;

public function __construct(string $pathToPidFile)
{
$this->pathToPidFile = $pathToPidFile;
public function __construct(
private readonly string $pathToPidFile
) {
}

public function pidExists(): bool
Expand Down
9 changes: 3 additions & 6 deletions src/Integration/Laravel/Console/ProcessManagerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

abstract class ProcessManagerCommand extends Command
{
protected $pidManager;

public function __construct(PidManager $pidManager)
{
public function __construct(
protected PidManager $pidManager
) {
parent::__construct();

$this->pidManager = $pidManager;
}
}
3 changes: 2 additions & 1 deletion src/Integration/Laravel/InfluxDBLogChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Log\LogManager;
use InfluxDB\Database;
use Monolog\Level;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Umbrellio\TableSync\Monolog\Handler\InfluxDBHandler;
Expand All @@ -17,7 +18,7 @@ public function __invoke(array $config): LoggerInterface
$handler = new InfluxDBHandler(
$this->app->make(Database::class),
$config['measurement'] ?? null,
$config['level'] ?? Logger::INFO,
$config['level'] ?? Level::Info,
$config['bubble'] ?? true
);

Expand Down
11 changes: 4 additions & 7 deletions src/Integration/Laravel/Jobs/PublishJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ final class PublishJob implements ShouldQueue, ShouldStorePayload
use HeavyJobsEnabledTrait;
use Queueable;

private $publisherClass;
private $message;

public function __construct(string $publisherClass, PublishMessage $message)
{
public function __construct(
private readonly string $publisherClass,
private PublishMessage $message
) {
$this->queue = Config::get('table_sync.publish_job_queue', '');
$this->publisherClass = $publisherClass;
$this->message = $message;
}

public function handle(): void
Expand Down
8 changes: 3 additions & 5 deletions src/Integration/Laravel/Jobs/ReceiveMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ final class ReceiveMessage implements ShouldQueue, ShouldStorePayload
use HeavyJobsEnabledTrait;
use Queueable;

private $message;

public function __construct(ReceivedMessage $message)
{
public function __construct(
private readonly ReceivedMessage $message
) {
$this->queue = Config::get('table_sync.receive_job_queue', '');
$this->message = $message;
}

public function handle(Receiver $receiver): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

final class EnsureConsistencyPublisher implements Publisher
{
private $publisher;

public function __construct(Publisher $publisher)
{
$this->publisher = $publisher;
public function __construct(
private readonly Publisher $publisher
) {
}

public function publish(PublishMessage $message): void
Expand Down
Loading