Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Oct 25, 2021
1 parent 3ab7421 commit aa64a4f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"autoload-dev": {
"psr-4": {
"spec\\EzSystems\\EzPlatformGraphQL\\Tools\\": "spec/Tools",
"spec\\EzSystems\\EzPlatformGraphQL\\": "spec/EzSystems/EzPlatformGraphQL"
"spec\\EzSystems\\EzPlatformGraphQL\\": "spec/EzSystems/EzPlatformGraphQL",
"sepc\\Ibexa\\GraphQL\\": "spec/Ibexa/GraphQL"
}
},
"extra": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace spec\EzSystems\EzPlatformGraphQL\Schema\Domain\Content;

use Ibexa\GraphQL\Schema\Domain\NameValidator;
use spec\EzSystems\EzPlatformGraphQL\Tools\TypeArgument;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\Core\Repository\Values\ContentType\ContentType;
Expand All @@ -14,9 +15,10 @@
class ContentDomainIteratorSpec extends ObjectBehavior
{
public function let(
ContentTypeService $contentTypeService
ContentTypeService $contentTypeService,
NameValidator $nameValidator
) {
$this->beConstructedWith($contentTypeService);
$this->beConstructedWith($contentTypeService, $nameValidator);
}

function it_is_initializable()
Expand All @@ -36,8 +38,10 @@ function it_initializes_the_schema_with_the_Platform_root_type(Builder $schema)
)->shouldHaveBeenCalled();
}

function it_yields_content_type_groups(ContentTypeService $contentTypeService)
function it_yields_content_type_groups(ContentTypeService $contentTypeService, NameValidator $nameValidator)
{
$nameValidator->isValidName(Argument::any())->willReturn(true);

$contentTypeService->loadContentTypeGroups()->willReturn([
$group1 = new ContentTypeGroup(['identifier' => 'Group 1']),
$group2 = new ContentTypeGroup(['identifier' => 'Group 2']),
Expand All @@ -54,8 +58,12 @@ function it_yields_content_type_groups(ContentTypeService $contentTypeService)
);
}

function it_yields_content_types_with_their_group_from_a_content_type_group(ContentTypeService $contentTypeService)
{
function it_yields_content_types_with_their_group_from_a_content_type_group(
ContentTypeService $contentTypeService,
NameValidator $nameValidator
) {
$nameValidator->isValidName(Argument::any())->willReturn(true);

$contentTypeService->loadContentTypeGroups()->willReturn([
$group = new ContentTypeGroup(['identifier' => 'Group']),
]);
Expand All @@ -75,18 +83,22 @@ function it_yields_content_types_with_their_group_from_a_content_type_group(Cont
);
}

function it_yields_fields_definitions_with_their_content_types_and_group_from_a_content_type(ContentTypeService $contentTypeService)
{
function it_yields_fields_definitions_with_their_content_types_and_group_from_a_content_type(
ContentTypeService $contentTypeService,
NameValidator $nameValidator
) {
$nameValidator->isValidName(Argument::any())->willReturn(true);

$contentTypeService->loadContentTypeGroups()->willReturn([
$group = new ContentTypeGroup(),
$group = new ContentTypeGroup(['identifier' => 'Group']),
]);
$contentTypeService->loadContentTypes(Argument::any())->willReturn([
$type = new ContentType([
'identifier' => 'type',
'fieldDefinitions' => [
'field1' => $field1 = new FieldDefinition(),
'field2' => $field2 = new FieldDefinition(),
'field3' => $field3 = new FieldDefinition(),
'field1' => $field1 = new FieldDefinition(['identifier' => 'foo']),
'field2' => $field2 = new FieldDefinition(['identifier' => 'bar']),
'field3' => $field3 = new FieldDefinition(['identifier' => 'faz']),
]
]),
]);
Expand All @@ -102,23 +114,29 @@ function it_yields_fields_definitions_with_their_content_types_and_group_from_a_
);
}

function it_only_yields_fields_definitions_from_the_current_content_type(ContentTypeService $contentTypeService)
{
function it_only_yields_fields_definitions_from_the_current_content_type(
ContentTypeService $contentTypeService,
NameValidator $nameValidator
) {
$nameValidator->isValidName(Argument::any())->willReturn(true);

$contentTypeService->loadContentTypeGroups()->willReturn([
$group = new ContentTypeGroup(),
$group = new ContentTypeGroup([
'identifier' => 'group'
]),
]);

$contentTypeService->loadContentTypes(Argument::any())->willReturn([
$type1 = new ContentType([
'identifier' => 'type1',
'fieldDefinitions' => [
'type1_field1' => ($type1field1 = new FieldDefinition()),
'type1_field1' => ($type1field1 = new FieldDefinition(['identifier' => 'foo'])),
]
]),
$type2 = new ContentType([
'identifier' => 'type2',
'fieldDefinitions' => [
'type2_field1' => ($type2field1 = new FieldDefinition()),
'type2_field1' => ($type2field1 = new FieldDefinition(['identifier' => 'bar'])),
]
]),
]);
Expand Down
16 changes: 16 additions & 0 deletions spec/Ibexa/GraphQL/Schema/Domain/NameValidatorSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace spec\Ibexa\GraphQL\Schema\Domain;

use Ibexa\GraphQL\Schema\Domain\NameValidator;
use PhpSpec\ObjectBehavior;

final class NameValidatorSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(NameValidator::class);
}
}
2 changes: 1 addition & 1 deletion src/Schema/Domain/NameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Validates given name according to GraphQL specification. See http://spec.graphql.org/June2018/#sec-Names.
*/
final class NameValidator
class NameValidator
{
private const NAME_PATTERN = '/^[_a-zA-Z][_a-zA-Z0-9]*$/';

Expand Down

0 comments on commit aa64a4f

Please sign in to comment.