Вынес в отдельный бандл трансформер по документам

master v0.0.1
Rinsvent 3 years ago
commit 4ea2e4a3c4
  1. 7
      .gitignore
  2. 18
      .gitlab-ci.yml
  3. 33
      Makefile
  4. 3
      Readme.md
  5. 9
      bin/docker/ci.sh
  6. 8
      bin/docker/prepare-ci.sh
  7. 16
      codeception.yml
  8. 33
      composer.json
  9. 6338
      composer.lock
  10. 15
      docker-compose-ci.yml
  11. 16
      docker-compose.yml
  12. 10
      src/Data2DTODoctrineDocumentBundle.php
  13. 17
      src/DependencyInjection/Data2DTODoctrineDocumentExtension.php
  14. 12
      src/Resources/config/services.yaml
  15. 16
      src/Service/Document.php
  16. 30
      src/Service/DocumentTransformer.php
  17. 0
      tests/_data/.gitkeep
  18. 2
      tests/_output/.gitignore
  19. 0
      tests/_support/.gitkeep
  20. 10
      tests/_support/Helper/Unit.php
  21. 27
      tests/_support/UnitTester.php
  22. 2
      tests/_support/_generated/.gitignore
  23. 10
      tests/unit.suite.yml

7
.gitignore vendored

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

@ -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

@ -0,0 +1,33 @@
auth:
docker exec -it -u1000:1000 data2dtodoctrinedocumentbundle_php bash
auth-root:
docker exec -it data2dtodoctrinedocumentbundle_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

@ -0,0 +1,3 @@
Data2dto bundle
=

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

@ -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

@ -0,0 +1,16 @@
namespace: Rinsvent\Data2DTODoctrineDocumentBundle\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/*

@ -0,0 +1,33 @@
{
"name": "rinsvent/data2dto-doctrine-docuemnt-bundle",
"description": "Doctrine entity bridge for data2dto bundle",
"license": "MIT",
"require": {
"php": "^8.0",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"rinsvent/data2dto": "^0.0",
"rinsvent/data2dto-bundle": "^0.0",
"symfony/http-kernel": "^5.3",
"symfony/config": "^5.3",
"symfony/dependency-injection": "^5.3",
"doctrine/mongodb-odm": "^2"
},
"require-dev": {
"codeception/codeception": "^4.1",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0"
},
"autoload": {
"psr-4": {
"tests\\": "tests/",
"Rinsvent\\Data2DTODoctrineDocumentBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rinsvent\\Data2DTODoctrineDocumentBundle\\Tests\\": "tests/"
}
}
}

6338
composer.lock generated

File diff suppressed because it is too large Load Diff

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

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

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

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

@ -0,0 +1,12 @@
services:
_defaults:
autoconfigure: true
public: false
autowire: true
Rinsvent\Data2DTODoctrineDocumentBundle\Service\:
resource: '../../../src/Service'
_instanceof:
Rinsvent\Data2DTOBundle\Service\AbstractTransformer:
tags: [ 'rinsvent.transformer' ]

@ -0,0 +1,16 @@
<?php
namespace Rinsvent\Data2DTODoctrineDocumentBundle\Service;
use Rinsvent\Data2DTO\Transformer\Meta;
#[\Attribute]
class Document extends Meta
{
public const TYPE = 'service';
public function __construct(
public string $class,
public string $primaryType = 'id',
) {}
}

@ -0,0 +1,30 @@
<?php
namespace Rinsvent\Data2DTODoctrineDocumentBundle\Service;
use Doctrine\ODM\MongoDB\DocumentManager;
use Rinsvent\Data2DTO\Transformer\Meta;
use Rinsvent\Data2DTOBundle\Service\AbstractTransformer;
class DocumentTransformer extends AbstractTransformer
{
public function __construct(
protected DocumentManager $dm
) {}
/**
* @param $data
* @param Document $meta
*/
public function transform(&$data, Meta $meta): void
{
if ($meta->primaryType === 'id' && !is_int($data)) {
return;
}
if ($meta->primaryType === 'uuid' && !is_string($data)) {
return;
}
$repository = $this->dm->getRepository($meta->class);
$data = $repository->find($data);
}
}

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

@ -0,0 +1,10 @@
<?php
namespace Rinsvent\Data2DTODoctrineDocumentBundle\Tests\Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
}

@ -0,0 +1,27 @@
<?php
namespace Rinsvent\Data2DTODoctrineDocumentBundle\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
*/
}

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

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