Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
7e29580d2e | |||
d85b851af4 | |||
6d082f7900 | |||
c1e831be4d | |||
f3451e1c90 | |||
cbcd2c8db5 | |||
5219685987 | |||
9fa8c1bc60 | |||
8c4b19b495 | |||
cfb85dacad | |||
3dc41fd0fe | |||
1588b5bc61 | |||
52badb8ac8 | |||
a807a2f344 |
@ -13,9 +13,5 @@ indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Tab indentation (no size specified)
|
||||
[Makefile,phpstan-baseline.neon]
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
|
||||
[{composer.json,.travis.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
51
.github/workflows/CI.yml
vendored
Normal file
51
.github/workflows/CI.yml
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: Ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
php: ['7.1', '7.2', '7.3', '7.4']
|
||||
DEPENDENCIES: ['', '--prefer-lowest']
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
|
||||
- name: Get composer cache directory
|
||||
id: composer-cache
|
||||
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: ${{ runner.os }}-composer-
|
||||
|
||||
- name: Create project
|
||||
run: composer create-project oxid-esales/graphql-module --repository packages.json --remove-vcs -n --no-plugins
|
||||
|
||||
- name: Syntax Test
|
||||
run: composer test:syntax
|
||||
working-directory: ./graphql-module
|
||||
|
||||
- name: Lint Test
|
||||
run: composer test:lint
|
||||
working-directory: ./graphql-module
|
||||
|
||||
- name: Static Analyzer
|
||||
run: composer test:static
|
||||
working-directory: ./graphql-module
|
||||
|
||||
- name: Unit Tests
|
||||
run: composer test:unit
|
||||
working-directory: ./graphql-module
|
45
.github/workflows/CI.yml.dist
vendored
Normal file
45
.github/workflows/CI.yml.dist
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: Ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
php: ['7.1', '7.2', '7.3', '7.4']
|
||||
DEPENDENCIES: ['', '--prefer-lowest']
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
|
||||
- name: Get composer cache directory
|
||||
id: composer-cache
|
||||
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: ${{ runner.os }}-composer-
|
||||
|
||||
- name: Install
|
||||
run: composer install -n --no-plugins $DEPENDENCIES
|
||||
|
||||
- name: Syntax Test
|
||||
run: composer test:syntax
|
||||
|
||||
- name: Lint Test
|
||||
run: composer test:lint
|
||||
|
||||
- name: Static Analyzer
|
||||
run: composer test:static
|
||||
|
||||
- name: Unit Tests
|
||||
run: composer test:unit
|
37
.php_cs.dist
37
.php_cs.dist
@ -3,39 +3,21 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
$header = <<<'EOF'
|
||||
All rights reserved.
|
||||
Copyright © __Vender__. All rights reserved.
|
||||
See LICENSE file for license details.
|
||||
EOF;
|
||||
|
||||
$finder = PhpCsFixer\Finder::create()
|
||||
->files()
|
||||
->exclude('Codeception/_support/_generated/')
|
||||
->in(__DIR__ . '/src')
|
||||
->in(__DIR__ . '/tests/');
|
||||
->in(__DIR__ . '/tests/')
|
||||
->name('*.stub');
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setFinder($finder)
|
||||
->setRiskyAllowed(true)
|
||||
->setRules([
|
||||
'@PSR2' => true,
|
||||
'blank_line_after_opening_tag' => true,
|
||||
'compact_nullable_typehint' => true,
|
||||
'declare_equal_normalize' => [
|
||||
'space' => 'none'
|
||||
],
|
||||
'function_typehint_space' => true,
|
||||
'method_argument_space' => [
|
||||
'on_multiline' => 'ensure_fully_multiline',
|
||||
],
|
||||
'new_with_braces' => true,
|
||||
'no_empty_statement' => true,
|
||||
'no_leading_import_slash' => true,
|
||||
'no_leading_namespace_whitespace' => true,
|
||||
'no_whitespace_in_blank_line' => true,
|
||||
'return_type_declaration' => [
|
||||
'space_before' => 'none'
|
||||
],
|
||||
'single_trait_insert_per_statement' => true,
|
||||
|
||||
'@PSR12' => true,
|
||||
'align_multiline_comment' => [
|
||||
'comment_type' => 'all_multiline'
|
||||
],
|
||||
@ -90,6 +72,15 @@ return PhpCsFixer\Config::create()
|
||||
],
|
||||
'declare_strict_types' => true,
|
||||
'dir_constant' => true,
|
||||
'final_internal_class' => [
|
||||
'annotation-white-list' => [],
|
||||
'consider-absent-docblock-as-internal-class' => true,
|
||||
'annotation-black-list' => [
|
||||
'@eshopExtension',
|
||||
'@dataType-extension',
|
||||
'@extendable-dataType'
|
||||
],
|
||||
],
|
||||
'global_namespace_import' => [
|
||||
'import_classes' => true,
|
||||
'import_constants' => true,
|
||||
|
30
.travis.yml
30
.travis.yml
@ -1,30 +0,0 @@
|
||||
language: php
|
||||
|
||||
dist: bionic
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
php:
|
||||
- "7.1"
|
||||
- "7.2"
|
||||
- "7.3"
|
||||
- "7.4"
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache/files
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
before_script:
|
||||
- composer create-project oxid-esales/graphql-module --repository packages.json --remove-vcs -n
|
||||
|
||||
script:
|
||||
- cd graphql-module
|
||||
- composer test:syntax
|
||||
- composer test:lint
|
||||
- composer test:lint-fixer
|
||||
- composer test:static
|
||||
- composer test:unit
|
@ -1,29 +0,0 @@
|
||||
language: php
|
||||
|
||||
dist: bionic
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
php:
|
||||
- "7.1"
|
||||
- "7.2"
|
||||
- "7.3"
|
||||
- "7.4"
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache/files
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
before_script:
|
||||
- composer install --prefer-dist
|
||||
|
||||
script:
|
||||
- composer test:syntax
|
||||
- composer test:lint
|
||||
- composer test:lint-fixer
|
||||
- composer test:static
|
||||
- composer test:unit
|
115
composer.json
115
composer.json
@ -1,70 +1,51 @@
|
||||
{
|
||||
"name": "oxid-esales/graphql-module-skeleton",
|
||||
"description": "OXID eSales GraphQL module skeleton",
|
||||
"type": "oxideshop-module",
|
||||
"keywords": ["oxid", "modules", "eShop", "GraphQL"],
|
||||
"license": ["GPL-3.0"],
|
||||
"extra": {
|
||||
"oxideshop": {
|
||||
"target-directory": "oe/graphql-module",
|
||||
"blacklist-filter": [
|
||||
"src/**/*.php",
|
||||
"tests/**/*.php"
|
||||
]
|
||||
"name": "oxid-esales/graphql-module-skeleton",
|
||||
"description": "OXID eSales GraphQL module skeleton",
|
||||
"type": "oxideshop-module",
|
||||
"keywords": ["oxid", "modules", "eShop", "GraphQL"],
|
||||
"license": ["GPL-3.0"],
|
||||
"extra": {
|
||||
"oxideshop": {
|
||||
"target-directory": "oe/graphql-module"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1",
|
||||
"oxid-esales/graphql-base": "^5.1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5.20|^8.5|^9",
|
||||
"friendsofphp/php-cs-fixer": "^2.18.2",
|
||||
"php-parallel-lint/php-parallel-lint": "^1.1",
|
||||
"phpstan/phpstan": "^0.12.26",
|
||||
"oxid-esales/oxideshop-ce": "^6.5",
|
||||
"oxid-esales/oxideshop-unified-namespace-generator": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"OxidEsales\\GraphQL\\Skeleton\\": "src",
|
||||
"OxidEslaes\\GraphQL\\Skeleton\\Tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-create-project-cmd": [
|
||||
"OxidEsales\\GraphQL\\Skeleton\\Installer::postInstall",
|
||||
"composer update",
|
||||
"@fix"
|
||||
],
|
||||
"fix:fixer": "php-cs-fixer fix",
|
||||
"fix": [
|
||||
"@fix:fixer"
|
||||
],
|
||||
"test:lint": "php-cs-fixer fix --dry-run",
|
||||
"test:syntax": "parallel-lint src/ tests/ metadata.php",
|
||||
"test:static": "phpstan --memory-limit=-1 analyse src/",
|
||||
"test:unit": "phpunit -c tests/phpunit.xml tests/Unit/",
|
||||
"test": [
|
||||
"@test:syntax",
|
||||
"@test:lint",
|
||||
"@test:static",
|
||||
"@test:unit"
|
||||
]
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1",
|
||||
"oxid-esales/graphql-base": "^2.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5",
|
||||
"squizlabs/php_codesniffer": "^3.5.2",
|
||||
"jakub-onderka/php-parallel-lint": "^1.0",
|
||||
"phpstan/phpstan": "^0.12",
|
||||
"oxid-esales/oxideshop-ce": "^6.5",
|
||||
"oxid-esales/oxideshop-unified-namespace-generator": "^2.0",
|
||||
"friendsofphp/php-cs-fixer": "^2.16"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"OxidEsales\\GraphQL\\Skeleton\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"OxidEslaes\\GraphQL\\Skeleton\\Tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"pre-install-cmd": [
|
||||
"OxidEsales\\GraphQL\\Skeleton\\Installer::preInstall"
|
||||
],
|
||||
"pre-update-cmd": [
|
||||
"OxidEsales\\GraphQL\\Skeleton\\Installer::preInstall"
|
||||
],
|
||||
"post-create-project-cmd": [
|
||||
"OxidEsales\\GraphQL\\Skeleton\\Installer::postInstall",
|
||||
"composer update",
|
||||
"@fix"
|
||||
],
|
||||
"fix:cbf": "phpcbf",
|
||||
"fix:fixer": "php-cs-fixer fix",
|
||||
"fix": [
|
||||
"@fix:cbf",
|
||||
"@fix:fixer"
|
||||
],
|
||||
"test:syntax": "parallel-lint src/",
|
||||
"test:lint": "phpcs",
|
||||
"test:lint-fixer": "php-cs-fixer fix --dry-run",
|
||||
"test:static": "phpstan analyse src/",
|
||||
"test:unit": "phpunit -c tests/phpunit.xml tests/Unit/",
|
||||
"test": [
|
||||
"@test:syntax",
|
||||
"@test:lint",
|
||||
"@test:lint-fixer",
|
||||
"@test:static",
|
||||
"@test:unit"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
32
depfile.yml
Normal file
32
depfile.yml
Normal file
@ -0,0 +1,32 @@
|
||||
# depfile.yml
|
||||
paths:
|
||||
- ./src/
|
||||
- ./vendor/oxid-esales/oxideshop-ce/source/
|
||||
- ./vendor/oxid-esales/oxideshop-unified-namespace-generator/
|
||||
layers:
|
||||
- name: Controller
|
||||
collectors:
|
||||
- type: className
|
||||
regex: .*GraphQL.*Controller.*
|
||||
- name: Service
|
||||
collectors:
|
||||
- type: className
|
||||
regex: .*GraphQL.*Service.*
|
||||
- name: Infrastructure
|
||||
collectors:
|
||||
- type: className
|
||||
regex: .*GraphQL.*Repository.*
|
||||
- name: Legacy
|
||||
collectors:
|
||||
- type: directory
|
||||
regex: .*vendor/oxid-esales/oxideshop-ce/source/.*
|
||||
- type: directory
|
||||
regex: .*vendor/oxid-esales/oxideshop-unified-namespace-generator/.*
|
||||
ruleset:
|
||||
Controller:
|
||||
- Service
|
||||
Service:
|
||||
- Infrastructure
|
||||
Infrastructure:
|
||||
- Legacy
|
||||
Legacy: ~
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"package": {
|
||||
"name": "oxid-esales/graphql-module",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"source": {
|
||||
"url": "./",
|
||||
"type": "git",
|
||||
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
|
||||
<file>src/</file>
|
||||
<file>tests/</file>
|
||||
<arg name="colors"/>
|
||||
<arg name="parallel" value="75"/>
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg value="np"/>
|
||||
<rule ref="PSR12" />
|
||||
</ruleset>
|
@ -1,6 +1,6 @@
|
||||
parameters:
|
||||
checkMissingIterableValueType: false
|
||||
level: max
|
||||
inferPrivatePropertyTypeFromConstructor: true
|
||||
autoload_files:
|
||||
scanFiles:
|
||||
- vendor/oxid-esales/oxideshop-ce/source/oxfunctions.php
|
||||
- vendor/oxid-esales/oxideshop-ce/source/overridablefunctions.php
|
||||
|
@ -1,13 +1,14 @@
|
||||
services:
|
||||
|
||||
_defaults:
|
||||
public: false
|
||||
autowire: true
|
||||
_defaults:
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
__Vendor__\GraphQL\__Package__\Controller\:
|
||||
resource: 'src/Controller/*'
|
||||
public: true
|
||||
__Vendor__\GraphQL\__Package__\:
|
||||
resource: 'src/*'
|
||||
exclude: 'src/**/DataType'
|
||||
public: true
|
||||
|
||||
__Vendor__\GraphQL\__Package__\Framework\NamespaceMapper:
|
||||
class: __Vendor__\GraphQL\__Package__\Framework\NamespaceMapper
|
||||
tags: ['graphql_namespace_mapper']
|
||||
__Vendor__\GraphQL\__Package__\Shared\Service\NamespaceMapper:
|
||||
class: __Vendor__\GraphQL\__Package__\Shared\Service\NamespaceMapper
|
||||
tags: ['graphql_namespace_mapper']
|
||||
|
34
src/Category/Controller/Category.php
Normal file
34
src/Category/Controller/Category.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Category\Controller;
|
||||
|
||||
use __Vendor__\GraphQL\__Package__\Category\DataType\Category as CategoryDataType;
|
||||
use __Vendor__\GraphQL\__Package__\Category\Service\Category as CategoryService;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Query;
|
||||
|
||||
final class Category
|
||||
{
|
||||
/** @var CategoryService */
|
||||
private $categoryService;
|
||||
|
||||
public function __construct (
|
||||
CategoryService $categoryService
|
||||
) {
|
||||
$this->categoryService = $categoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Query()
|
||||
*/
|
||||
public function category(string $id): CategoryDataType
|
||||
{
|
||||
return $this->categoryService->category($id);
|
||||
}
|
||||
}
|
76
src/Category/DataType/Category.php
Normal file
76
src/Category/DataType/Category.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Category\DataType;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Category as CategoryEshopModel;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Field;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Type;
|
||||
use TheCodingMachine\GraphQLite\Types\ID;
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* @Type()
|
||||
*/
|
||||
final class Category
|
||||
{
|
||||
/** @var CategoryEshopModel */
|
||||
private $category;
|
||||
|
||||
public function __construct(
|
||||
CategoryEshopModel $category
|
||||
) {
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field
|
||||
*/
|
||||
public function id(): ID
|
||||
{
|
||||
return new ID(
|
||||
$this->category->getId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return (string) $this->category->getFieldData('oxtitle');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field()
|
||||
*/
|
||||
public function active(?DateTimeInterface $now = null): bool
|
||||
{
|
||||
$active = (bool) $this->category->getFieldData('oxactive');
|
||||
|
||||
if ($active) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$from = new DateTimeImmutable(
|
||||
(string) $this->category->getFieldData('oxactivefrom')
|
||||
);
|
||||
$to = new DateTimeImmutable(
|
||||
(string) $this->category->getFieldData('oxactiveto')
|
||||
);
|
||||
$now = $now ?? new DateTimeImmutable('now');
|
||||
|
||||
if ($from <= $now && $to >= $now) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Exception;
|
||||
namespace __Vendor__\GraphQL\__Package__\Category\Exception;
|
||||
|
||||
use OxidEsales\GraphQL\Base\Exception\NotFound;
|
||||
|
34
src/Category/Infrastructure/CategoryRepository.php
Normal file
34
src/Category/Infrastructure/CategoryRepository.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Category\Infrastructure;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Category as CategoryEshopModel;
|
||||
use __Vendor__\GraphQL\__Package__\Category\DataType\Category as CategoryDataType;
|
||||
use OxidEsales\GraphQL\Base\Exception\NotFound;
|
||||
|
||||
final class CategoryRepository
|
||||
{
|
||||
/**
|
||||
* @throws NotFound
|
||||
*/
|
||||
public function category(string $id): CategoryDataType
|
||||
{
|
||||
/** @var CategoryEshopModel */
|
||||
$category = oxNew(CategoryEshopModel::class);
|
||||
|
||||
if (!$category->load($id)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
return new CategoryDataType(
|
||||
$category
|
||||
);
|
||||
}
|
||||
}
|
46
src/Category/Service/Category.php
Normal file
46
src/Category/Service/Category.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Category\Service;
|
||||
|
||||
use __Vendor__\GraphQL\__Package__\Category\DataType\Category as CategoryDataType;
|
||||
use __Vendor__\GraphQL\__Package__\Category\Exception\CategoryNotFound;
|
||||
use __Vendor__\GraphQL\__Package__\Category\Infrastructure\CategoryRepository;
|
||||
use OxidEsales\GraphQL\Base\Exception\NotFound;
|
||||
use OxidEsales\GraphQL\Base\Exception\InvalidLogin;
|
||||
|
||||
final class Category
|
||||
{
|
||||
/** @var CategoryRepository */
|
||||
private $categoryRepository;
|
||||
|
||||
public function __construct(
|
||||
CategoryRepository $categoryRepository
|
||||
) {
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CategoryNotFound
|
||||
*/
|
||||
public function category(string $id): CategoryDataType
|
||||
{
|
||||
try {
|
||||
$category = $this->categoryRepository->category($id);
|
||||
} catch (NotFound $e) {
|
||||
throw CategoryNotFound::byId($id);
|
||||
}
|
||||
|
||||
if (!$category->active()) {
|
||||
throw new InvalidLogin('Unauthorized');
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Controller;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Category as CategoryEshopModel;
|
||||
use __Vendor__\GraphQL\__Package__\DataObject\Category as CategoryDataObject;
|
||||
use __Vendor__\GraphQL\__Package__\Exception\CategoryNotFound;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Query;
|
||||
|
||||
class Category
|
||||
{
|
||||
/**
|
||||
* category by ID
|
||||
*
|
||||
* @Query()
|
||||
*/
|
||||
public function category(string $id): CategoryDataObject
|
||||
{
|
||||
/** @var CategoryEshopModel */
|
||||
$category = oxNew(CategoryEshopModel::class);
|
||||
|
||||
if (!$category->load($id)) {
|
||||
throw CategoryNotFound::byId($id);
|
||||
}
|
||||
|
||||
return new CategoryDataObject(
|
||||
$category
|
||||
);
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\DataObject;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Category as CategoryEshopModel;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Field;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Type;
|
||||
use TheCodingMachine\GraphQLite\Types\ID;
|
||||
|
||||
/**
|
||||
* @Type()
|
||||
*/
|
||||
class Category
|
||||
{
|
||||
/** @var CategoryEshopModel */
|
||||
private $category;
|
||||
|
||||
public function __construct(
|
||||
CategoryEshopModel $category
|
||||
) {
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field
|
||||
*/
|
||||
public function getId(): ID
|
||||
{
|
||||
return new ID(
|
||||
$this->category->getId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return (string) $this->category->getFieldData('oxtitle');
|
||||
}
|
||||
}
|
@ -15,6 +15,10 @@ class Installer
|
||||
private static $packageName;
|
||||
|
||||
public static function preInstall(Event $event): void
|
||||
{
|
||||
}
|
||||
|
||||
public static function postInstall(Event $event = null): void
|
||||
{
|
||||
$io = $event->getIO();
|
||||
$vendor = self::ask($io, 'What is the vendor?', 'MyVendor');
|
||||
@ -26,10 +30,9 @@ class Installer
|
||||
// Update composer definition
|
||||
$json->write($composerDefinition);
|
||||
$io->write("<info>composer.json for {$composerDefinition['name']} is created.\n</info>");
|
||||
}
|
||||
|
||||
public static function postInstall(Event $event = null): void
|
||||
{
|
||||
|
||||
|
||||
unset($event);
|
||||
list($vendor, $package, $packageFull) = self::$packageName;
|
||||
$skeletonRoot = dirname(__DIR__);
|
||||
@ -37,10 +40,9 @@ class Installer
|
||||
// remove installer files
|
||||
unlink($skeletonRoot.'/README.md');
|
||||
unlink($skeletonRoot.'/LICENSE');
|
||||
unlink($skeletonRoot.'/.travis.yml');
|
||||
unlink($skeletonRoot.'/packages.json');
|
||||
rename($skeletonRoot.'/README.md.dist', $skeletonRoot.'/README.md');
|
||||
rename($skeletonRoot.'/.travis.yml.dist', $skeletonRoot.'/.travis.yml');
|
||||
rename($skeletonRoot.'/.github/workflows/CI.yml.dist', $skeletonRoot.'/.github/workflows/CI.yml');
|
||||
unlink(__FILE__);
|
||||
}
|
||||
|
||||
@ -74,15 +76,16 @@ class Installer
|
||||
unset(
|
||||
$composerDefinition['autoload']['files'],
|
||||
$composerDefinition['scripts']['pre-install-cmd'],
|
||||
$composerDefinition['scripts']['pre-update-cmd'],
|
||||
$composerDefinition['scripts']['post-create-project-cmd'],
|
||||
$composerDefinition['scripts']['post-install-cmd'],
|
||||
$composerDefinition['homepage']
|
||||
);
|
||||
|
||||
$composerDefinition['name'] = $packageFull;
|
||||
$composerDefinition['description'] = '';
|
||||
$composerDefinition['autoload']['psr-4'] = ["{$vendor}\\GraphQL\\{$package}\\" => 'src/'];
|
||||
$composerDefinition['autoload-dev']['psr-4'] = ["{$vendor}\\GraphQL\\{$package}\\Tests\\" => 'tests/'];
|
||||
$composerDefinition['autoload']['psr-4'] = [
|
||||
"{$vendor}\\GraphQL\\{$package}\\" => 'src/',
|
||||
"{$vendor}\\GraphQL\\{$package}\\Tests\\" => 'tests/'
|
||||
];
|
||||
$composerDefinition['extra']['oxideshop']['target-directory'] = $packageFull;
|
||||
|
||||
return $composerDefinition;
|
||||
@ -93,7 +96,7 @@ class Installer
|
||||
$jobRename = function (\SplFileInfo $file) use ($vendor, $package, $packageFull): void {
|
||||
$fileName = $file->getFilename();
|
||||
$filePath = (string) $file;
|
||||
if ($file->isDir() || strpos($fileName, '.') === 0 || ! is_writable($filePath)) {
|
||||
if ($file->isDir() || !is_writable($filePath)) {
|
||||
return;
|
||||
}
|
||||
$contents = file_get_contents($filePath);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Framework;
|
||||
namespace __Vendor__\GraphQL\__Package__\Shared\Service;
|
||||
|
||||
use OxidEsales\GraphQL\Base\Framework\NamespaceMapperInterface;
|
||||
|
||||
@ -16,14 +16,14 @@ class NamespaceMapper implements NamespaceMapperInterface
|
||||
public function getControllerNamespaceMapping(): array
|
||||
{
|
||||
return [
|
||||
'\\__Vendor__\\GraphQL\\__Package__\\Controller' => __DIR__ . '/../Controller/',
|
||||
'\\__Vendor__\\GraphQL\\__Package__\\Category\\Controller' => __DIR__ . '/../../Category/Controller/',
|
||||
];
|
||||
}
|
||||
|
||||
public function getTypeNamespaceMapping(): array
|
||||
{
|
||||
return [
|
||||
'\\__Vendor__\\GraphQL\\__Package__\\DataObject' => __DIR__ . '/../DataObject/',
|
||||
'\\__Vendor__\\GraphQL\\__Package__\\Category\\DataType' => __DIR__ . '/../../Category/DataType/',
|
||||
];
|
||||
}
|
||||
}
|
38
tests/Codeception/Acceptance/CategoryQueryCest.php
Normal file
38
tests/Codeception/Acceptance/CategoryQueryCest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright © OXID eSales AG. All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Tests\Codeception\Acceptance;
|
||||
|
||||
use __Vendor__\GraphQL\__Package__\Tests\Codeception\AcceptanceTester;
|
||||
|
||||
class CategoryQueryCest
|
||||
{
|
||||
public function testFetchSingleCategoryById(AcceptanceTester $I): void
|
||||
{
|
||||
$I->haveHTTPHeader('Content-Type', 'application/json');
|
||||
$I->sendPOST('/widget.php?cl=graphql', [
|
||||
'query' => 'query {
|
||||
category (id: "943a9ba3050e78b443c16e043ae60ef3") {
|
||||
id
|
||||
title
|
||||
}
|
||||
}'
|
||||
]);
|
||||
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
|
||||
$I->seeResponseIsJson();
|
||||
$I->seeResponseContainsJson([
|
||||
'data' => [
|
||||
'category' => [
|
||||
'id' => '943a9ba3050e78b443c16e043ae60ef3',
|
||||
'title' => 'Kiteboarding'
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
2
tests/Codeception/_output/.gitignore
vendored
Normal file
2
tests/Codeception/_output/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
35
tests/Codeception/_support/AcceptanceTester.php
Normal file
35
tests/Codeception/_support/AcceptanceTester.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright © OXID eSales AG. All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Tests\Codeception;
|
||||
|
||||
/**
|
||||
* 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 \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class AcceptanceTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\AcceptanceTesterActions;
|
||||
|
||||
/*
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
23
tests/Codeception/_support/Helper/Acceptance.php
Normal file
23
tests/Codeception/_support/Helper/Acceptance.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright © OXID eSales AG. All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Tests\Codeception\Helper;
|
||||
|
||||
use OxidEsales\Facts\Facts;
|
||||
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
|
||||
class Acceptance extends \Codeception\Module
|
||||
{
|
||||
public function _beforeSuite($settings = []) {
|
||||
exec((new Facts())->getShopRootPath() . '/bin/oe-console oe:module:activate oe_graphql_base');
|
||||
exec((new Facts())->getShopRootPath() . '/bin/oe-console oe:module:activate __PackageFull__');
|
||||
}
|
||||
}
|
2
tests/Codeception/_support/_generated/.gitignore
vendored
Normal file
2
tests/Codeception/_support/_generated/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
10
tests/Codeception/acceptance.suite.yml
Normal file
10
tests/Codeception/acceptance.suite.yml
Normal file
@ -0,0 +1,10 @@
|
||||
# suite config
|
||||
actor: AcceptanceTester
|
||||
path: Acceptance
|
||||
modules:
|
||||
enabled:
|
||||
- \__Vendor__\GraphQL\__Package__\Tests\Codeception\Helper\Acceptance
|
||||
- REST:
|
||||
url: '%SHOP_URL%'
|
||||
depends: PhpBrowser
|
||||
part: Json
|
10
tests/Codeception/codeception.yml
Normal file
10
tests/Codeception/codeception.yml
Normal file
@ -0,0 +1,10 @@
|
||||
paths:
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
envs: tests/_envs
|
||||
actor_suffix: Tester
|
||||
extensions:
|
||||
enabled:
|
||||
- Codeception\Extension\RunFailed
|
16
tests/Codeception/params.php
Normal file
16
tests/Codeception/params.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright © OXID eSales AG. All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use OxidEsales\Facts\Facts;
|
||||
|
||||
$facts = new Facts();
|
||||
|
||||
return [
|
||||
'SHOP_URL' => $facts->getShopUrl(),
|
||||
];
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* All rights reserved.
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Tests\Integration\Controller;
|
||||
|
||||
use OxidEsales\GraphQL\Base\Tests\Integration\TestCase;
|
||||
|
||||
class CategoryTest extends TestCase
|
||||
{
|
||||
public function testGetSingleCategoryWithoutParam(): void
|
||||
{
|
||||
$result = $this->execQuery('query { category }');
|
||||
$this->assertSame(
|
||||
400,
|
||||
$result['status']
|
||||
);
|
||||
}
|
||||
}
|
@ -7,13 +7,13 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace __Vendor__\GraphQL\__Package__\Tests\Unit\Framework;
|
||||
namespace __Vendor__\GraphQL\__Package__\Tests\Unit\Shared\Service;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use __Vendor__\GraphQL\__Package__\Framework\NamespaceMapper;
|
||||
use __Vendor__\GraphQL\__Package__\Shared\Service\NamespaceMapper;
|
||||
|
||||
/**
|
||||
* @covers __Vendor__\GraphQL\__Package__\Framework\NamespaceMapper
|
||||
* @covers __Vendor__\GraphQL\__Package__\Shared\Service\NamespaceMapper
|
||||
*/
|
||||
class NamespaceMapperTest extends TestCase
|
||||
{
|
21
tests/codeception.yml
Normal file
21
tests/codeception.yml
Normal file
@ -0,0 +1,21 @@
|
||||
namespace: __Vendor__\GraphQL\__Package__\Tests\Codeception
|
||||
|
||||
params:
|
||||
- Codeception/params.php
|
||||
|
||||
paths:
|
||||
tests: Codeception
|
||||
output: Codeception/_output
|
||||
data: Codeception/_data
|
||||
support: Codeception/_support
|
||||
envs: Codeception/_envs
|
||||
actor_suffix: Tester
|
||||
|
||||
settings:
|
||||
colors: true
|
||||
log: true
|
||||
shuffle: true
|
||||
|
||||
extensions:
|
||||
enabled:
|
||||
- Codeception\Extension\RunFailed
|
Reference in New Issue
Block a user