Skip to content

Commit

Permalink
Merge pull request #7 from gdubost/v3
Browse files Browse the repository at this point in the history
Ajout du provider v3 pour le json
  • Loading branch information
Kumatetsu authored Mar 20, 2019
2 parents 329c527 + 10cee02 commit b3f99f3
Show file tree
Hide file tree
Showing 27 changed files with 8,396 additions and 118 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
cache:
- /root/.composer
env:
- APPLICATION_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
notify:
slack:
webhook_url: $$SLACK_WEBHOOK_URL
username: drone
channel: $$SLACK_CHANNEL
on_started: true
on_failure: true
on_success: true
27 changes: 26 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
bin/
tmp/
vendor/
composer.lock
.DS_Store
doc/
.php_cs.cache

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

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

###> friendsofphp/php-cs-fixer ###
/.php_cs
/.php_cs.cache
###< friendsofphp/php-cs-fixer ###

###> phpunit/phpunit ###
/phpunit.xml
###< phpunit/phpunit ###
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)
;
6 changes: 5 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ tools:
php_sim: true
php_pdepend: true
php_analyzer: true

filter:
paths:
- src/
dependency_paths:
- vendor/
checks:
php:
code_rating: true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Modifier `composer.json` :
{
// ...
"require": {
"etna/json-service-provider": "~0.1"
"etna/json-service-provider": "^3.0"
},
"repositories": [
{
Expand Down
19 changes: 19 additions & 0 deletions TestApp/app/Controller/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace TestApp\Controller;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class BaseController extends Controller
{
/**
* @Route("/", methods={"POST"}, name="home")
*/
public function home(Request $req)
{
return new JsonResponse($req->request->all(), 200);
}
}
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().'/TestApp/tmp/cache/'.$this->environment;
}

public function getLogDir()
{
return $this->getProjectDir().'/TestApp/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');
}
}
42 changes: 42 additions & 0 deletions TestApp/app/Services/ExceptionListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace TestApp\Services;

use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;

use Symfony\Component\DependencyInjection\ContainerInterface;

class ExceptionListener implements EventSubscriberInterface
{
private $debug;

public function __construct(ContainerInterface $container)
{
$this->debug = $container->getParameter("kernel.debug");
}

public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if (is_a($exception, "InvalidArgumentException")) {
$code = 400;
} else {
$code = (method_exists($exception, 'getStatusCode')) ?
$exception->getStatusCode() :
(method_exists($exception, 'getCode') && $exception->getCode() !== 0 ? $exception->getCode() : 500);
}
$event->setResponse(
new JsonResponse((true === $this->debug || 500 !== $code) ? $exception->getMessage() : null, $code)
);
}

public static function getSubscribedEvents()
{
return [
KernelEvents::EXCEPTION => ['onKernelException', 32],
];
}
}
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 [
ETNA\Json\JsonBundle::class => ['all' => true],
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
];
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: '%env(APP_SECRET)%'

php_errors:
log: true

test: true
3 changes: 3 additions & 0 deletions TestApp/config/routes/annotations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
controllers:
resource: ../../app/Controller/
type: annotation
31 changes: 31 additions & 0 deletions TestApp/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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'

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: false # 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,Kernel.php}'

# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
TestApp\Controller\:
resource: '../app/Controller'
tags: ['controller.service_arguments']

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

json_request:
class: 'ETNA\Json\Services\JsonRequestService'
43 changes: 43 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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:
- ETNA\FeatureContext\ApiContext
extensions:
Behat\Symfony2Extension:
kernel:
class: TestApp\Kernel
env: testing

ci:
suites:
default:
paths:
- '%paths.base%/features/suites'
contexts:
- ETNA\FeatureContext\CoverageContext:
coverage_path: /tmp/behat/coverage
whitelist:
- src
blacklist:
- vendor
- bin
- tmp
- Tests
- ETNA\FeatureContext\ApiContext
extensions:
Behat\Symfony2Extension:
kernel:
class: TestApp\Kernel
env: testing
Loading

0 comments on commit b3f99f3

Please sign in to comment.