Первоначальный каркас приложения

master
Rinsvent 3 years ago
commit 23659c989b
  1. 7
      .gitignore
  2. 18
      .gitlab-ci.yml
  3. 33
      Makefile
  4. 4
      Readme.md
  5. 9
      bin/docker/ci.sh
  6. 8
      bin/docker/prepare-ci.sh
  7. 16
      codeception.yml
  8. 30
      composer.json
  9. 5757
      composer.lock
  10. 15
      docker-compose-ci.yml
  11. 16
      docker-compose.yml
  12. 11
      src/Attribute/PropertyPath.php
  13. 46
      src/Data2DtoConverter.php
  14. 0
      tests/_data/.gitkeep
  15. 2
      tests/_output/.gitignore
  16. 0
      tests/_support/.gitkeep
  17. 10
      tests/_support/Helper/Unit.php
  18. 27
      tests/_support/UnitTester.php
  19. 2
      tests/_support/_generated/.gitignore
  20. 10
      tests/unit.suite.yml
  21. 45
      tests/unit/Converter/FillTest.php
  22. 10
      tests/unit/Converter/fixtures/FillTest/BuyRequest.php
  23. 11
      tests/unit/Converter/fixtures/FillTest/HelloRequest.php

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 data2dto_php bash
auth-root:
docker exec -it data2dto_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,4 @@
Data2dto
=

@ -0,0 +1,9 @@
#!/bin/bash
docker-compose -f ./docker-compose-ci.yml up -d
echo 'composer installing'
docker exec -i apisdkgenerator_php composer install -q
echo 'composer installed !!'
docker exec -i apisdkgenerator_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\Data2DTO\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,30 @@
{
"name": "rinsvent/data2dto",
"description": "Convert data to dto object",
"type": "project",
"license": "proprietary",
"require": {
"php": "^8.0",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"symfony/string": "^5.3",
"rinsvent/attribute-extractor": "^0.0.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\\Data2DTO\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rinsvent\\Data2DTO\\Tests\\": "tests/"
}
}
}

5757
composer.lock generated

File diff suppressed because it is too large Load Diff

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

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

@ -0,0 +1,11 @@
<?php
namespace Rinsvent\Data2DTO\Attribute;
#[\Attribute]
class PropertyPath
{
public function __construct(
public string $path
) {}
}

@ -0,0 +1,46 @@
<?php
namespace Rinsvent\Data2DTO;
use Rinsvent\AttributeExtractor\PropertyExtractor;
use Rinsvent\Data2DTO\Attribute\PropertyPath;
class Data2DtoConverter
{
public function convert(array $data, string $class): object
{
$object = new $class;
$reflectionObject = new \ReflectionObject($object);
$properties = $reflectionObject->getProperties();
/** @var \ReflectionProperty $property */
foreach ($properties as $property) {
$propertyName = $property->getName();
$propertyExtractor = new PropertyExtractor($object::class, $propertyName);
/** @var PropertyPath $propertyPath */
if ($propertyPath = $propertyExtractor->fetch(PropertyPath::class)) {
$customPath = $propertyPath->path;
}
/** @var \ReflectionNamedType $reflectionPropertyType */
$reflectionPropertyType = $property->getType();
$propertyType = $reflectionPropertyType->getName();
if(key_exists($propertyName, $data)) {
$value = $data[$propertyName];
if ($value === null && !$reflectionPropertyType->allowsNull()) {
continue;
}
if (class_exists($propertyType)) {
$value = $this->convert($value, $propertyType);
}
$property->setValue($object, $value);
}
}
return $object;
}
}

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

@ -0,0 +1,10 @@
<?php
namespace Rinsvent\Data2DTO\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\Data2DTO\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\Data2DTO\Tests\Helper\Unit
step_decorators: ~

@ -0,0 +1,45 @@
<?php
namespace Rinsvent\Data2DTO\Tests\Listener;
use Rinsvent\Data2DTO\Data2DtoConverter;
use Rinsvent\Data2DTO\Tests\unit\Converter\fixtures\FillTest\HelloRequest;
class FillTest extends \Codeception\Test\Unit
{
/**
* @var \UnitTester
*/
protected $tester;
protected function _before()
{
}
protected function _after()
{
}
// tests
public function testSuccessFillRequestData()
{
$data2DtoConverter = new Data2DtoConverter();
$data2DtoConverter->convert([
'surname' => 'asdf',
'fake_age' => 3,
'emails' => [
'sfdgsa',
'af234f',
'asdf33333'
],
'buy' => [
'phrase' => 'Buy buy!!!',
'length' => 10,
'isFirst' => true,
'extraData2' => '1234'
],
'extraData1' => 'qwer'
], HelloRequest::class);
// $this->assertEquals('Hello igor', $response->getContent());
}
}

@ -0,0 +1,10 @@
<?php
namespace Rinsvent\Data2DTO\Tests\unit\Converter\fixtures\FillTest;
class BuyRequest
{
public string $phrase;
public int $length;
public bool $isFirst;
}

@ -0,0 +1,11 @@
<?php
namespace Rinsvent\Data2DTO\Tests\unit\Converter\fixtures\FillTest;
class HelloRequest
{
public string $surname;
public int $age;
public array $emails;
public BuyRequest $buy;
}
Loading…
Cancel
Save