Добавил базовую загшотовку для бандла.

Нужно добавить библиотеку для конвертирования и покрыть тестами
This commit is contained in:
Sipachev Igor 2021-08-25 12:52:03 +07:00
commit eaded296aa
24 changed files with 6021 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.idea
/var/
/vendor/
###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

18
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,18 @@
image: dh.rinsvent.ru/ci
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
services:
- docker:dind
before_script:
- bash bin/docker/prepare-ci.sh
build:
stage: build
script:
- docker login --username ${REGISTRY_USERNAME} --password ${REGISTRY_PASSWORD} dh.rinsvent.ru
- bash bin/docker/ci.sh

33
Makefile Normal file
View File

@ -0,0 +1,33 @@
auth:
docker exec -it -u1000:1000 responsebundle_php bash
auth-root:
docker exec -it responsebundle_php bash
test:
bin/codecept run $p
coverage:
bin/codecept run --coverage --coverage-html=/app/var/temp.html
# make out container
coverage-open:
google-chrome var/temp.html/index.html
#docker
start:
docker-compose up -d
stop:
docker-compose down
pull:
docker-compose pull
restart: stop start
restart-php:
docker-compose restart backend-php-fpm
down-clear:
docker-compose down -v --remove-orphans
init: down-clear pull start
#prepare
prepare-environment:
bash bin/docker/prepare.sh

2
Readme.md Normal file
View File

@ -0,0 +1,2 @@
Response bundle
===

9
bin/docker/ci.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
docker-compose -f ./docker-compose-ci.yml up -d
echo 'composer installing'
docker exec -i responsebundle_php composer install -q
echo 'composer installed !!'
docker exec -i responsebundle_php vendor/bin/codecept run --coverage

8
bin/docker/prepare-ci.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
FULL_PROJECT_NETWORK=$(docker network ls | grep full-project)
if [ -z "$FULL_PROJECT_NETWORK" ]
then
docker network create full-project --subnet=192.168.221.0/25
fi

16
codeception.yml Normal file
View File

@ -0,0 +1,16 @@
namespace: Rinsvent\ResponseBundle\Tests
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
coverage:
enabled: true
include:
- src/*

36
composer.json Normal file
View File

@ -0,0 +1,36 @@
{
"name": "rinsvent/request-bundle",
"description": "Request bundle",
"license": "proprietary",
"require": {
"php": "^8.0",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"symfony/validator": "^5.3",
"symfony/cache": "^5.3",
"symfony/string": "^5.3",
"rinsvent/attribute-extractor": "^0.0",
"rinsvent/data2dto": "^0.0",
"doctrine/annotations": "^1.13"
},
"require-dev": {
"codeception/codeception": "^4.1",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0",
"symfony/http-kernel": "^5.3",
"symfony/http-foundation": "^5.3",
"symfony/routing": "^5.3"
},
"autoload": {
"psr-4": {
"tests\\": "tests/",
"Rinsvent\\ResponseBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rinsvent\\ResponseBundle\\Tests\\": "tests/"
}
}
}

5658
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

15
docker-compose-ci.yml Normal file
View File

@ -0,0 +1,15 @@
version: '3.3'
services:
responsebundle_php:
image: dh.rinsvent.ru/php8dev
container_name: responsebundle_php
volumes:
- ./:/app
environment:
USE_COMPOSER_SCRIPTS: 0
networks:
default:
external:
name: full-project

16
docker-compose.yml Normal file
View File

@ -0,0 +1,16 @@
version: '3.3'
services:
responsebundle_php:
image: dh.rinsvent.ru/php8dev
container_name: responsebundle_php
volumes:
- ./:/app
environment:
USE_COMPOSER_SCRIPTS: 1
PHP_IDE_CONFIG: "serverName=responsebundle_php"
networks:
default:
external:
name: full-project

View File

@ -0,0 +1,17 @@
<?php
namespace Rinsvent\ResponseBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class ResponseExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Rinsvent\ResponseBundle\EventListener;
use App\Response\JsonResponse;
use App\Serializer\EntitySchemaSerializer;
class ResponseListener
{
public function onKernelResponse(ResponseEvent $event): void
{
if (!$event->isMainRequest()) {
return;
}
$response = $event->getResponse();
if (!$response instanceof JsonResponse) {
return;
}
$request = $event->getRequest();
$data = $response->getData();
if ($response->getSchema()) {
// $data = $this->entitySchemaSerializer->serializeBySchema($data, $response->getSchema());
}
if ($resultKey = $request->get('_result_key')) {
$data = [$resultKey => $data];
}
$response->setData($data);
}
}

View File

@ -0,0 +1,9 @@
services:
_defaults:
autoconfigure: true
public: false
autowire: true
Rinsvent\ResponseBundle\EventListener\ResponseListener:
tags:
- { name: kernel.event_listener, event: kernel.response }

View File

@ -0,0 +1,17 @@
<?php
namespace Rinsvent\ResponseBundle\Response;
class JsonResponse extends \Symfony\Component\HttpFoundation\JsonResponse
{
public function __construct($data = null, int $status = 200, array $headers = [], bool $json = false)
{
parent::__construct(null, $status, $headers, $json);
$this->data = $data;
}
public function getData()
{
return $this->data;
}
}

10
src/ResponseBundle.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace Rinsvent\ResponseBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ResponseBundle extends Bundle
{
}

0
tests/_data/.gitkeep Normal file
View File

2
tests/_output/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

0
tests/_support/.gitkeep Normal file
View File

View File

@ -0,0 +1,46 @@
<?php
namespace Rinsvent\ResponseBundle\Tests\Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
use Rinsvent\ResponseBundle\EventListener\RequestListener;
use Rinsvent\ResponseBundle\Tests\unit\Listener\fixtures\FillTest\Controller;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class Unit extends \Codeception\Module
{
public function send(Request $request): Response
{
$routes = new RouteCollection();
$controller = new Controller();
$routes->add('hello', new Route('/hello/{name}', [
'_controller' => [$controller, 'hello']
]
));
$matcher = new UrlMatcher($routes, new RequestContext());
$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber(new RouterListener($matcher, new RequestStack()));
$listener = new RequestListener();
$dispatcher->addListener('kernel.request', [$listener, 'onKernelRequest']);
$controllerResolver = new ControllerResolver();
$argumentResolver = new ArgumentResolver();
$kernel = new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);
$response = $kernel->handle($request);
$response->send();
return $response;
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Rinsvent\ResponseBundle\Tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}

2
tests/_support/_generated/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

10
tests/unit.suite.yml Normal file
View File

@ -0,0 +1,10 @@
# Codeception Test Suite Configuration
#
# Suite for unit or integration tests.
actor: UnitTester
modules:
enabled:
- Asserts
- \Rinsvent\ResponseBundle\Tests\Helper\Unit
step_decorators: ~

View File

@ -0,0 +1,29 @@
<?php
namespace Rinsvent\ResponseBundle\Tests\Listener;
use Symfony\Component\HttpFoundation\Request;
use Rinsvent\ResponseBundle\EventListener\RequestListener;
class FillTest extends \Codeception\Test\Unit
{
/**
* @var \UnitTester
*/
protected $tester;
protected function _before()
{
}
protected function _after()
{
}
// tests
public function testSuccessFillRequestData()
{
}
}