Skip to content

Commit

Permalink
Merge pull request #10 from aurelienCastellarnau/feature/128384
Browse files Browse the repository at this point in the history
[FEATURE#128384] feat(sprinter_service_provider): Migration vers Symfony4
  • Loading branch information
Kumatetsu authored Jun 27, 2019
2 parents 7c71831 + 5b3a5ee commit f093b7c
Show file tree
Hide file tree
Showing 40 changed files with 8,426 additions and 114 deletions.
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage_clover: tmp/behat/coverage.clover.xml
json_path: tmp/behat/coveralls-upload.json
20 changes: 20 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
image: etna/drone-php7:php71
env:
- APP_ENV=test
- COVERALLS_REPO_TOKEN=$$COVERALLS_TOKEN
- COVERALLS_SERVICE_NAME=drone.io
script:
- composer global require phpdocumentor/phpdocumentor --no-interaction --prefer-dist --no-progress
- composer install --dev --no-interaction --prefer-dist --no-progress --no-scripts
- composer phing
- composer coveralls
services:
- rabbitmq
notify:
slack:
webhook_url: $$SLACK_WEBHOOK_URL
username: drone
channel: $$SLACK_CHANNEL
on_started: true
on_failure: true
on_success: true
Empty file added .env
Empty file.
Empty file added .env.test
Empty file.
23 changes: 22 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
bin/
tmp/
vendor/
composer.lock

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/public/bundles/
/var/
/vendor/

###> phpunit/phpunit ###
/phpunit.xml
###< phpunit/phpunit ###

###> squizlabs/php_codesniffer ###
/.phpcs-cache
/phpcs.xml
###< squizlabs/php_codesniffer ###

###> friendsofphp/php-cs-fixer ###
/.php_cs
/.php_cs.cache
###< friendsofphp/php-cs-fixer ###
55 changes: 55 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . "/src")
;

return PhpCsFixer\Config::create()
->setRules([
"@PSR1" => true,
"@PSR2" => true,
"@Symfony" => true,
"@Symfony:risky" => true,
"@DoctrineAnnotation" => true,
"@PHP56Migration" => true,
"@PHP56Migration:risky" => true,
"@PHP70Migration" => true,
"@PHP70Migration:risky" => true,
"@PHP71Migration" => true,
"@PHP71Migration:risky" => true,
"binary_operator_spaces" => [
"align_double_arrow" => true,
"align_equals" => true
],
"concat_space" => true,
"strict_comparison" => true,
"combine_consecutive_issets" => true,
"combine_consecutive_unsets" => true,
"comment_to_phpdoc" => true,
"compact_nullable_typehint" => true,
"explicit_indirect_variable" => true,
"explicit_string_variable" => true,
"header_comment" => [
"commentType" => "PHPDoc",
"header" => "PHP version 7.1\n@author BLU <dev@etna-alternance.net>",
"location" => "after_open",
"separate" => "bottom"
],
"linebreak_after_opening_tag" => true,
"no_useless_else" => true,
"no_useless_return" => true,
"ordered_imports" => true,
"phpdoc_order" => true,
"psr0" => true,
"return_assignment" => true,
"visibility_required" => [
"elements" => ['property', 'method']
],
"concat_space" => [
"spacing" => "one"
]
])
->setFinder($finder)
->setRiskyAllowed(true)
->setUsingCache(false)
;
8 changes: 7 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ tools:
php_sim: true
php_pdepend: true
php_analyzer: true

external_code_coverage:
timeout: 2000
filter:
paths:
- src/
dependency_paths:
- vendor/
checks:
php:
code_rating: true
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 ETNA SARL
Copyright (c) 2019 ETNA SARL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
58 changes: 48 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
sprinter-service-provider
=========================
Dependency Status Scrutinizer Code Quality

[![Dependency Status](https://www.versioneye.com/user/projects/53dde6d38e78abc422000010/badge.svg)](https://www.versioneye.com/user/projects/53dde6d38e78abc422000010)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/etna-alternance/composer-sprinter-service-provider/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/etna-alternance/composer-sprinter-service-provider/?branch=master)
## Installation
Modifier composer.json :

Installation
------------

Modifier `composer.json` :

```
{
// ...
"require": {
Expand All @@ -18,8 +12,52 @@ Modifier `composer.json` :
"repositories": [
{
"type": "composer",
"url": "http://blu-composer.herokuapp.com"
"url": "https://blu-composer.herokuapp.com"
}
]
}
## Configuration
### Environnement

Dans le fichier d'env :

Une variable RABBITMQ_URL qui contient l'adresse du serveur rabbitMQ
Une variable RABBITMQ_VHOST qui contient le type d'environnement souhaité ```production```||```development```||```/test-behat```

```
RABBITMQ_URL=amqp://development:ieJoh8sa@rabbitmq.etna.local:5672
RABBITMQ_VHOST=development
```

### Sprinter et RabbitMQ

La description de la default routing_key est située dans SprinterServiceProvider/config/packages/sprinter.yaml

La description du producer rabbitMQ est située dans SprinterServiceProvider/config/packages/old_sound_rabbit_mq.yaml

Lors de l'injection de la dépendance, la configuration rabbitMQ est ajoutée (prepend) à la configuration du parent.

Si le parent redéfini la default routing_key ou le producer SPrinter, il écrase la configuration définie au niveau SprinterServiceProvider

*****Exemple de sprinter.yaml:*****

```
default:
routing_key: sprinter.lefran_f
```

*****Exemple de old_sound_rabbit_mq.yaml:*****

```
connections:
default:
url: '%env(RABBITMQ_URL)%'
vhost: '%env(RABBITMQ_VHOST)%'
producers:
# use 'old_sound_rabbit_mq.sprinter_producer' service to send data.
SPrinter:
connection: default
exchange_options: { name: 'SPrinter', type: direct, passive: false, durable: true, auto_delete: false }
```

L'ordre d'appel des bundles n'a pas d'importance.
61 changes: 61 additions & 0 deletions TestApp/app/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace TestApp;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel
{
use MicroKernelTrait;

const CONFIG_EXTS = '.{php,xml,yaml,yml}';

public function getCacheDir()
{
return $this->getProjectDir().'/tmp/cache/'.$this->environment;
}

public function getLogDir()
{
return $this->getProjectDir().'/tmp/log';
}

public function registerBundles()
{
$contents = require $this->getProjectDir().'/TestApp/config/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
$container->addResource(new FileResource($this->getProjectDir().'/TestApp/config/bundles.php'));
// Feel free to remove the "container.autowiring.strict_mode" parameter
// if you are using symfony/dependency-injection 4.0+ as it's the default behavior
$container->setParameter('container.autowiring.strict_mode', true);
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir().'/TestApp/config';

$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
}

protected function configureRoutes(RouteCollectionBuilder $routes)
{
$confDir = $this->getProjectDir().'/TestApp/config';

$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
}
}
7 changes: 7 additions & 0 deletions TestApp/config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [
OldSound\RabbitMqBundle\OldSoundRabbitMqBundle::class => ['all' => true],
ETNA\Sprinter\SprinterBundle::class => ['all' => true],
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
];
5 changes: 5 additions & 0 deletions TestApp/config/packages/RabbitMQ.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
old_sound_rabbit_mq:
connections:
default:
url: 'amqp://guest:guest@localhost:5672'
vhost: '/test-behat'
7 changes: 7 additions & 0 deletions TestApp/config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
framework:
secret: 'toto'

php_errors:
log: true

test: true
3 changes: 3 additions & 0 deletions TestApp/config/packages/sprinter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sprinter:
default:
routing_key: sprinter.lefran_f
21 changes: 21 additions & 0 deletions TestApp/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
application_name: 'test_app'
version: 2.0.0

services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: true # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
TestApp\:
resource: '../app/*'
exclude: '../app/{Entity,Migrations,Tests,Utils,Kernel.php}'

55 changes: 55 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
default:
formatters:
progress:
decorated: true
verbose: true
time: true
language: fr
output_path: null
multiline_arguments: true

suites:
default:
paths:
- '%paths.base%/features/suites'
contexts:
- FeatureContext:
- ETNA\FeatureContext\ApiContext
- ETNA\FeatureContext\RabbitContext
- ETNA\FeatureContext\ExceptionContainerContext
- ETNA\FeatureContext\SymfonyTestKernelContext:
bundles:
- '\ETNA\Sprinter\SprinterBundle'
- '\OldSound\RabbitMqBundle\OldSoundRabbitMqBundle'
extensions:
Behat\Symfony2Extension:
kernel:
class: TestApp\Kernel

ci:
suites:
default:
paths:
- '%paths.base%/features/suites'
contexts:
- ETNA\FeatureContext\CoverageContext:
coverage_path: /tmp/behat/coverage
whitelist:
- src
blacklist:
- vendor
- bin
- tmp
- Tests
- FeatureContext:
- ETNA\FeatureContext\ApiContext
- ETNA\FeatureContext\RabbitContext
- ETNA\FeatureContext\ExceptionContainerContext
- ETNA\FeatureContext\SymfonyTestKernelContext:
bundles:
- '\ETNA\Sprinter\SprinterBundle'
- '\OldSound\RabbitMqBundle\OldSoundRabbitMqBundle'
extensions:
Behat\Symfony2Extension:
kernel:
class: TestApp\Kernel
Loading

0 comments on commit f093b7c

Please sign in to comment.