Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Move category factory to it's own class
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Nov 7, 2019
1 parent 44a1f43 commit f4bace0
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -13,7 +13,7 @@ indent_size = 4
trim_trailing_whitespace = true

# Tab indentation (no size specified)
[Makefile]
[Makefile,phpstan-baseline.neon]
indent_style = tab

[{composer.json,.travis.yml}]
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### Changed
- move category factory to it's own class
- allow for serverside id generation

## [1.0.1] 2019-11-07

### Changed
Expand Down
9 changes: 5 additions & 4 deletions phpstan-baseline.neon
@@ -1,7 +1,10 @@


parameters:
ignoreErrors:
-
message: "#^Call to static method getUtilsObject\\(\\) on an unknown class OxidEsales\\\\Eshop\\\\Core\\\\Registry\\.$#"
count: 1
path: src/DataObject/CategoryFactory.php

-
message: "#^Property OxidEsales\\\\GraphQL\\\\Example\\\\Dao\\\\CategoryDao\\:\\:\\$queryBuilderFactory has unknown class OxidEsales\\\\EshopCommunity\\\\Internal\\\\Framework\\\\Database\\\\QueryBuilderFactoryInterface as its type\\.$#"
count: 1
Expand All @@ -21,5 +24,3 @@ parameters:
message: "#^Call to static method getInstance\\(\\) on an unknown class OxidEsales\\\\EshopCommunity\\\\Internal\\\\Container\\\\ContainerFactory\\.$#"
count: 2
path: src/DataObject/Category.php


4 changes: 4 additions & 0 deletions services.yaml
Expand Up @@ -12,6 +12,10 @@ services:
resource: 'src/Controller/*'
public: true

OxidEsales\GraphQL\Example\DataObject\:
resource: 'src/DataObject/*Factory.php'
public: true

OxidEsales\GraphQL\Example\Framework\NamespaceMapper:
class: OxidEsales\GraphQL\Example\Framework\NamespaceMapper
tags: ['graphql_namespace_mapper']
Expand Down
14 changes: 0 additions & 14 deletions src/DataObject/Category.php
Expand Up @@ -11,7 +11,6 @@

use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\GraphQL\Example\Dao\CategoryDaoInterface;
use TheCodingMachine\GraphQLite\Annotations\Factory;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;

Expand Down Expand Up @@ -39,19 +38,6 @@ public function __construct(
$this->parentid = $parentid;
}

/**
* @Factory
*/
public static function createCategory(string $id, string $name, ?string $parentid = null): self
{
$parentid = 'oxrootid';
return new self(
$id,
$name,
$parentid
);
}

/**
* @Field(outputType="ID")
*/
Expand Down
35 changes: 35 additions & 0 deletions src/DataObject/CategoryFactory.php
@@ -0,0 +1,35 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\GraphQL\Example\DataObject;

use OxidEsales\Eshop\Core\Registry;
use OxidEsales\GraphQL\Example\DataObject\Category;
use TheCodingMachine\GraphQLite\Annotations\Factory;

class CategoryFactory
{
/**
* @Factory
*/
public static function createCategory(?string $id = null, string $name, ?string $parentid = null): Category
{
if ($id === null) {
$id = Registry::getUtilsObject()->generateUID();
}
if ($parentid === null) {
$parentid = 'oxrootid';
}
return new Category(
$id,
$name,
$parentid
);
}
}
19 changes: 19 additions & 0 deletions tests/Integration/Controller/CategoryTest.php
Expand Up @@ -112,4 +112,23 @@ public function testGetSimpleCategoryJustCreatedWithExtras()
static::$queryResult['body']['data']['categories'][0]['parent']
);
}

public function testCreateSimpleCategoryWithAutoId()
{
$this->execQuery('query { token (username: "admin", password: "admin") }');
$this->setAuthToken(static::$queryResult['body']['data']['token']);
$this->execQuery('mutation { categoryCreate(category: {name: "foobar"}) {id, name} }');
$this->assertEquals(
200,
static::$queryResult['status']
);
$this->assertEquals(
'foobar',
static::$queryResult['body']['data']['categoryCreate']['name']
);
$this->assertInternalType(
'string',
static::$queryResult['body']['data']['categoryCreate']['id']
);
}
}

0 comments on commit f4bace0

Please sign in to comment.