21 Commits
v1.0 ... master

Author SHA1 Message Date
a40fee4819 add ids 2024-07-19 18:13:56 +02:00
a54568abad set json 2024-07-19 17:56:27 +02:00
7f5784d710 add php v8 2024-07-19 17:31:08 +02:00
5c5b74fcdf Update README.md
Travis no longer usable
2023-03-20 14:06:23 +01:00
570964309b Merge pull request #1 from hkreuter/master_fixes
Small fixes
2021-08-19 17:26:43 +03:00
8de9123000 Small fixes 2021-06-20 18:28:17 +02:00
6851ddf757 Add install into shop section 2021-04-22 14:03:37 +02:00
7e29580d2e fix packages 2021-04-21 15:22:25 +02:00
d85b851af4 Update to latest base module 2021-04-21 15:20:57 +02:00
6d082f7900 OXDEV-4026 Use new grapql module ids 2020-10-20 11:53:34 +03:00
c1e831be4d Fix packages.json 2020-07-30 07:03:47 +02:00
f3451e1c90 OXDEV-3559 Fix tests autoloader 2020-07-29 11:53:01 +02:00
cbcd2c8db5 OXDEV-3559 Fix parsing dot files 2020-07-29 10:45:42 +02:00
5219685987 OXDEV-3559 Replace vendor in code style 2020-07-29 10:39:32 +02:00
9fa8c1bc60 OXDEV-3559 Fix memory limit issues with PHPStan 2020-07-29 10:38:57 +02:00
8c4b19b495 OXDEV-3559 Add codeception tests 2020-07-09 21:53:54 +02:00
cfb85dacad OXDEV-3559 Add deptrack config file 2020-07-09 21:15:00 +02:00
3dc41fd0fe OXDEV-3559 Refactor to best practices 2020-07-03 16:56:13 +02:00
1588b5bc61 OXDEV-3559 update to latest coding guides 2020-07-03 14:43:21 +02:00
52badb8ac8 OXDEV-3559 update dependencies to latest 2020-07-03 14:32:10 +02:00
a807a2f344 OXDEV-3559 Fix indention 2020-07-03 14:28:20 +02:00
34 changed files with 583 additions and 307 deletions

View File

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

View File

@ -3,39 +3,21 @@
declare(strict_types=1);
$header = <<<'EOF'
All rights reserved.
Copyright © __Vendor__. 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,

View File

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

View File

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

View File

@ -1,7 +1,7 @@
# oxid-esales/graphql-module-skeleton
[![Build Status](https://img.shields.io/travis/com/OXID-eSales/graphql-module-skeleton/master.svg?style=for-the-badge&logo=travis)](https://travis-ci.com/OXID-eSales/graphql-module-skeleton) [![PHP Version](https://img.shields.io/packagist/php-v/oxid-esales/graphql-module-skeleton.svg?style=for-the-badge)](https://github.com/oxid-esales/graphql-module-skeleton) [![Stable Version](https://img.shields.io/packagist/v/oxid-esales/graphql-module-skeleton.svg?style=for-the-badge&label=latest)](https://packagist.org/packages/oxid-esales/graphql-module-skeleton)
[![PHP Version](https://img.shields.io/packagist/php-v/oxid-esales/graphql-module-skeleton.svg?style=for-the-badge)](https://github.com/oxid-esales/graphql-module-skeleton) [![Stable Version](https://img.shields.io/packagist/v/oxid-esales/graphql-module-skeleton.svg?style=for-the-badge&label=latest)](https://packagist.org/packages/oxid-esales/graphql-module-skeleton)
## What is this?
@ -19,7 +19,14 @@ This skeleton will set you up with a
$ composer create-project oxid-esales/graphql-module-skeleton
```
This provides you with a basic GraphQL OXID module, that you may install into the shop via `composer`.
This provides you with a basic GraphQL OXID module. To install this freshly created module into your OXID eShop you can:
```bash
$ composer config repositories.graphql path path-to-module/that-you-just-created
$ composer require my-vendor/my-package
```
Make sure that `my-vendor/my-package` matches the package name in the package `composer.json`.
## License

View File

@ -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|^8",
"oxid-esales/graphql-base": "^8.0"
},
"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": "^7.0",
"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
View 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: ~

View File

@ -13,12 +13,12 @@ $sMetadataVersion = '2.0';
* Module information
*/
$aModule = [
'id' => '__PackageFull__',
'title' => 'GraphQL __Package__',
'id' => 'graphql-module-skeleton',
'title' => 'GraphQL module skeleton',
'description' => '',
'thumbnail' => 'out/pictures/logo.png',
'version' => '0.0.1',
'author' => '__Vendor__',
'author' => 'OxidEsales',
'url' => '',
'email' => '',
'extend' => [

View File

@ -1,7 +1,7 @@
{
"package": {
"name": "oxid-esales/graphql-module",
"version": "1.0.0",
"version": "2.0.0",
"source": {
"url": "./",
"type": "git",

View File

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

View File

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

View File

@ -1,13 +1,14 @@
services:
_defaults:
public: false
autowire: true
_defaults:
public: false
autowire: true
__Vendor__\GraphQL\__Package__\Controller\:
resource: 'src/Controller/*'
public: true
OxidEsales\GraphQL\Skeleton\:
resource: 'src/*'
exclude: 'src/**/{DataType,Exception,Infrastructure}'
public: true
__Vendor__\GraphQL\__Package__\Framework\NamespaceMapper:
class: __Vendor__\GraphQL\__Package__\Framework\NamespaceMapper
tags: ['graphql_namespace_mapper']
OxidEsales\GraphQL\Skeleton\Shared\Service\NamespaceMapper:
class: OxidEsales\GraphQL\Skeleton\Shared\Service\NamespaceMapper
tags: ['graphql_namespace_mapper']

View 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);
}
}

View 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;
}
}

View File

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

View 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($id);
}
return new CategoryDataType(
$category
);
}
}

View 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;
}
}

View File

@ -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
);
}
}

View File

@ -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');
}
}

View File

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

View File

@ -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/',
];
}
}

View 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
View File

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

View 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
*/
}

View 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__');
}
}

View File

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

View 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

View 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

View 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(),
];

View File

@ -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']
);
}
}

View File

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