Добавил базовую загшотовку для бандла.
Нужно добавить библиотеку для конвертирования и покрыть тестами
This commit is contained in:
commit
eaded296aa
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.idea
|
||||||
|
/var/
|
||||||
|
/vendor/
|
||||||
|
###> phpunit/phpunit ###
|
||||||
|
/phpunit.xml
|
||||||
|
.phpunit.result.cache
|
||||||
|
###< phpunit/phpunit ###
|
18
.gitlab-ci.yml
Normal file
18
.gitlab-ci.yml
Normal 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
33
Makefile
Normal 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
|
9
bin/docker/ci.sh
Executable file
9
bin/docker/ci.sh
Executable 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
8
bin/docker/prepare-ci.sh
Executable 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
16
codeception.yml
Normal 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
36
composer.json
Normal 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
5658
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
docker-compose-ci.yml
Normal file
15
docker-compose-ci.yml
Normal 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
16
docker-compose.yml
Normal 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
|
17
src/DependencyInjection/ResponseExtension.php
Normal file
17
src/DependencyInjection/ResponseExtension.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
34
src/EventListener/ResponseListener.php
Normal file
34
src/EventListener/ResponseListener.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
9
src/Resources/config/services.yaml
Normal file
9
src/Resources/config/services.yaml
Normal 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 }
|
17
src/Response/JsonResponse.php
Normal file
17
src/Response/JsonResponse.php
Normal 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
10
src/ResponseBundle.php
Normal 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
0
tests/_data/.gitkeep
Normal file
2
tests/_output/.gitignore
vendored
Normal file
2
tests/_output/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
0
tests/_support/.gitkeep
Normal file
0
tests/_support/.gitkeep
Normal file
46
tests/_support/Helper/Unit.php
Normal file
46
tests/_support/Helper/Unit.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
27
tests/_support/UnitTester.php
Normal file
27
tests/_support/UnitTester.php
Normal 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
2
tests/_support/_generated/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
10
tests/unit.suite.yml
Normal file
10
tests/unit.suite.yml
Normal 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: ~
|
29
tests/unit/Listener/FillTest.php
Normal file
29
tests/unit/Listener/FillTest.php
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user