Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 0 additions & 96 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -48798,102 +48798,6 @@ parameters:
count: 1
path: tests/lib/MVC/Symfony/Templating/RenderLocationStrategyTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\ContentExtensionTest\:\:getConfigResolverMock\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\ContentExtensionTest\:\:getContent\(\) has parameter \$fieldsData with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\ContentExtensionTest\:\:getContent\(\) has parameter \$namesData with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\ContentExtensionTest\:\:getField\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\ContentExtensionTest\:\:getField\(\) has parameter \$isEmpty with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php

-
message: '#^Parameter \#1 \$repository of class Ibexa\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\ContentExtension constructor expects Ibexa\\Contracts\\Core\\Repository\\Repository, PHPUnit\\Framework\\MockObject\\MockObject given\.$#'
identifier: argument.type
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php

-
message: '#^Property Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\ContentExtensionTest\:\:\$fieldHelperMock \(Ibexa\\Contracts\\Core\\Repository\\ContentTypeService&PHPUnit\\Framework\\MockObject\\MockObject\) does not accept Ibexa\\Core\\Helper\\FieldHelper&PHPUnit\\Framework\\MockObject\\MockObject\.$#'
identifier: assign.propertyType
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:getConfigResolverMock\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:getContent\(\) has parameter \$fieldsData with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:getContent\(\) has parameter \$namesData with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:getFieldDefinition\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:getFieldDefinition\(\) has parameter \$id with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:getFieldDefinition\(\) has parameter \$settings with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:getFieldDefinition\(\) has parameter \$typeIdentifier with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Method Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:getTemplatePath\(\) has parameter \$tpl with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Property Ibexa\\Tests\\Core\\MVC\\Symfony\\Templating\\Twig\\Extension\\FieldRenderingExtensionIntegrationTest\:\:\$fieldDefinitions has no type specified\.$#'
identifier: missingType.property
count: 1
path: tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php

-
message: '#^Argument of an invalid type string supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Core\MVC\Symfony\Templating\Twig\Extension;

Expand All @@ -13,35 +14,28 @@
use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Field;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Ibexa\Core\Helper\FieldHelper;
use Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList;
use Ibexa\Core\Helper\TranslationHelper;
use Ibexa\Core\MVC\Symfony\Templating\Twig\Extension\ContentExtension;
use Ibexa\Core\Repository\Values\Content\Content;
use Ibexa\Core\Repository\Values\Content\VersionInfo;
use Ibexa\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\Repository\Values\ContentType\FieldDefinitionCollection;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

/**
* Integration tests for ContentExtension templates.
* Tests ContentExtension in the context of site with "fre-FR, eng-US" configured as languages.

*
* Tests ContentExtension in context of site with "fre-FR, eng-US" configured as languages.
* @phpstan-import-type TFieldsData from \Ibexa\Tests\Core\MVC\Symfony\Templating\Twig\Extension\FileSystemTwigIntegrationTestCase
*/
class ContentExtensionTest extends FileSystemTwigIntegrationTestCase
{
/** @var \Ibexa\Contracts\Core\Repository\ContentTypeService|\PHPUnit\Framework\MockObject\MockObject */
private $fieldHelperMock;

/** @var array<int, \Ibexa\Core\Repository\Values\ContentType\FieldDefinition[]> */
private $fieldDefinitions = [];
private FieldHelper & MockObject $fieldHelperMock;

/** @var int[] */
private $identityMap = [];

public function getExtensions()
public function getExtensions(): array
{
$this->fieldHelperMock = $this->createMock(FieldHelper::class);
$configResolver = $this->getConfigResolverMock();
Expand Down Expand Up @@ -69,39 +63,16 @@ protected static function getFixturesDirectory(): string
/**
* Creates content with initial/main language being fre-FR.
*
* @param string $contentTypeIdentifier
* @param array $fieldsData
* @param array $namesData
*
* @return \Ibexa\Core\Repository\Values\Content\Content
* @param TFieldsData $fieldsData
* @param array<string, string> $namesData
*/
protected function getContent(string $contentTypeIdentifier, array $fieldsData, array $namesData = [])
protected function getContent(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): Content
{
if (!array_key_exists($contentTypeIdentifier, $this->identityMap)) {
$this->identityMap[$contentTypeIdentifier] = count($this->identityMap) + 1;
}

$contentTypeId = $this->identityMap[$contentTypeIdentifier];

$fields = [];
foreach ($fieldsData as $fieldTypeIdentifier => $fieldsArray) {
$fieldsArray = isset($fieldsArray['id']) ? [$fieldsArray] : $fieldsArray;
foreach ($fieldsArray as $fieldInfo) {
// Save field definitions in property for mocking purposes
$this->fieldDefinitions[$contentTypeId][$fieldInfo['fieldDefIdentifier']] = new FieldDefinition(
[
'identifier' => $fieldInfo['fieldDefIdentifier'],
'id' => $fieldInfo['id'],
'fieldTypeIdentifier' => $fieldTypeIdentifier,
'names' => isset($fieldInfo['fieldDefNames']) ? $fieldInfo['fieldDefNames'] : [],
'descriptions' => isset($fieldInfo['fieldDefDescriptions']) ? $fieldInfo['fieldDefDescriptions'] : [],
]
);
unset($fieldInfo['fieldDefNames'], $fieldInfo['fieldDefDescriptions']);
$fields[] = new Field($fieldInfo);
}
}
$content = new Content(
$contentTypeId = $this->getContentTypeId($contentTypeIdentifier);

$fields = $this->buildFieldsFromData($fieldsData, $contentTypeIdentifier);

return new Content(
[
'internalFields' => $fields,
'versionInfo' => new VersionInfo(
Expand All @@ -120,12 +91,10 @@ protected function getContent(string $contentTypeIdentifier, array $fieldsData,
]
),
'contentType' => new ContentType([
'fieldDefinitions' => new FieldDefinitionCollection($this->fieldDefinitions[$contentTypeId] ?? []),
'fieldDefinitions' => new FieldDefinitionCollection($this->fieldDefinitions[$contentTypeIdentifier] ?? []),
]),
]
);

return $content;
}

/**
Expand All @@ -142,28 +111,6 @@ protected function getContentAwareObject(string $contentTypeIdentifier, array $f
return $mock;
}

private function getConfigResolverMock()
{
$mock = $this->createMock(ConfigResolverInterface::class);
// Signature: ConfigResolverInterface->getParameter( $paramName, $namespace = null, $scope = null )
$mock->expects(self::any())
->method('getParameter')
->will(
self::returnValueMap(
[
[
'languages',
null,
null,
['fre-FR', 'eng-US'],
],
]
)
);

return $mock;
}

private function getFieldsGroupsListMock(): FieldsGroupsList
{
$fieldsGroupsList = $this->createMock(FieldsGroupsList::class);
Expand All @@ -174,55 +121,49 @@ private function getFieldsGroupsListMock(): FieldsGroupsList
return $fieldsGroupsList;
}

protected function getField($isEmpty)
protected function getField(bool $isEmpty): Field
{
$field = new Field(['fieldDefIdentifier' => 'testfield', 'value' => null]);

$this->fieldHelperMock
->expects(self::once())
->method('isFieldEmpty')
->will(self::returnValue($isEmpty));
->willReturn($isEmpty);

return $field;
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject
*/
protected function getRepositoryMock()
protected function getRepositoryMock(): Repository & MockObject
{
$mock = $this->createMock(Repository::class);

$mock->expects(self::any())
$mock
->method('getContentTypeService')
->will(self::returnValue($this->getContentTypeServiceMock()));
->willReturn($this->getContentTypeServiceMock());

return $mock;
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject
*/
protected function getContentTypeServiceMock()
protected function getContentTypeServiceMock(): ContentTypeService & MockObject
{
$mock = $this->createMock(ContentTypeService::class);

$mock->expects(self::any())
$mock
->method('loadContentType')
->will(
self::returnCallback(
function ($contentTypeId) {
return new ContentType(
[
'identifier' => $contentTypeId,
'mainLanguageCode' => 'fre-FR',
'fieldDefinitions' => new FieldDefinitionCollection(
$this->fieldDefinitions[$contentTypeId]
),
]
);
}
)
->willReturnCallback(
function ($contentTypeId): ContentType {
$contentTypeIdentifier = $this->getContentTypeIdentifier($contentTypeId);

return new ContentType(
[
'identifier' => $contentTypeId,
'mainLanguageCode' => 'fre-FR',
'fieldDefinitions' => new FieldDefinitionCollection(
$this->fieldDefinitions[$contentTypeIdentifier]
),
]
);
}
);

return $mock;
Expand Down
Loading
Loading