Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c8311d8
NGSTACK-1000 upgrade bundle to use Ibexa 5
Oct 22, 2025
5ed6538
NGSTACK-1000 modify multiple classes to use constructor promotion for…
Oct 22, 2025
06074b0
NGSTACK-1000 replace 'mb_strpos' with 'str_starts_with' method in Ima…
Oct 22, 2025
a021bef
NGSTACK-1000 migrate phpunit.xml to a newer version
Oct 22, 2025
94c5750
NGSTACK-1000 modify tests to be compatible with PHP8 and PHPUnit12
Oct 22, 2025
753633c
NGSTACK-1000 add '.phpunit.cache' folder to .gitignore
Oct 22, 2025
81224b9
NGSTACK-1000 bump versions of PHP to 8.3 and Symfony to 7.3 in 'tests…
Oct 22, 2025
469ba37
NGSTACK-1000 set php-cs-fixer rule to allow FQCN in PHPDocs
Oct 22, 2025
f9f2de2
NGSTACK-1000 apply php-cs-fixer fixes to 'Collector' class
Oct 22, 2025
58c25d4
NGSTACK-1000 update php-cs-fixer workflow to use docker image that us…
Oct 22, 2025
9825a71
NGSTACK-1000 remove specific version of php-cs-fixer image from 'codi…
AntePrkacin Oct 23, 2025
f99c165
NGSTACK-1000 apply some php-cs-fixer fixes
AntePrkacin Oct 23, 2025
42852da
NGSTACK-1000 comment out 'mb_str_functions' key in '.php-cs-fixer.php…
AntePrkacin Oct 24, 2025
7c644ab
NGSTACK-1000 add missing 'FieldHelper' property to 'Image' class config
AntePrkacin Oct 24, 2025
efa576a
NGSTACK-1000 downgrade version of PHPUnit in order for Twig Extension…
AntePrkacin Oct 24, 2025
52fc86f
NGSTACK-1000 fix remaining tests that were failing
AntePrkacin Oct 24, 2025
c5c34d2
Revert "NGSTACK-1000 add missing 'FieldHelper' property to 'Image' cl…
AntePrkacin Oct 24, 2025
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
9 changes: 2 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1']
symfony: ['~5.4.0']
php: ['8.3']
symfony: ['~7.3.0']
phpunit: ['phpunit.xml']
deps: ['normal']
include:
- php: '8.1'
symfony: '~5.4.0'
phpunit: 'phpunit.xml'
deps: 'low'

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor
composer.lock
.idea
build
.phpunit.cache
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'single_line_comment_style' => false,
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'match', 'parameters']],
'yoda_style' => false,
'fully_qualified_strict_types' => false,

// Additional rules
'date_time_immutable' => true,
Expand All @@ -39,7 +40,7 @@
'import_functions' => true,
],
'heredoc_indentation' => ['indentation' => 'same_as_start'],
'mb_str_functions' => true,
// 'mb_str_functions' => true,
'native_constant_invocation' => true,
'nullable_type_declaration_for_default_null_value' => true,
'static_lambda' => true,
Expand Down
9 changes: 3 additions & 6 deletions bundle/Handler/FieldType/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@

abstract class Handler extends BaseHandler
{
protected FieldHelper $fieldHelper;

public function __construct(FieldHelper $fieldHelper)
{
$this->fieldHelper = $fieldHelper;
}
public function __construct(
protected FieldHelper $fieldHelper,
) {}

public function getMetaTags(string $tagName, array $params = []): array
{
Expand Down
20 changes: 6 additions & 14 deletions bundle/Handler/FieldType/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,19 @@
use Symfony\Component\HttpFoundation\RequestStack;

use function ltrim;
use function mb_strpos;
use function str_starts_with;

final class Image extends Handler
{
private VariationHandler $imageVariationService;

private RequestStack $requestStack;

private LoggerInterface $logger;

public function __construct(
FieldHelper $fieldHelper,
VariationHandler $imageVariationService,
RequestStack $requestStack,
?LoggerInterface $logger = null,
private readonly VariationHandler $imageVariationService,
private readonly RequestStack $requestStack,
private ?LoggerInterface $logger = null,
) {
parent::__construct($fieldHelper);

$this->imageVariationService = $imageVariationService;
$this->requestStack = $requestStack;
$this->logger = $logger ?? new NullLogger();
$this->logger ??= new NullLogger();
}

protected function getFieldValue(Field $field, string $tagName, array $params = []): string
Expand All @@ -48,7 +40,7 @@ protected function getFieldValue(Field $field, string $tagName, array $params =
try {
$variationUri = $this->imageVariationService->getVariation($field, $this->content->getVersionInfo(), $variationName)->uri;

if (mb_strpos($variationUri, '/') === 0 && ($request = $this->requestStack->getCurrentRequest()) !== null) {
if (str_starts_with($variationUri, '/') && ($request = $this->requestStack->getCurrentRequest()) !== null) {
$variationUri = $request->getUriForPath('/' . ltrim($variationUri, '/'));
}

Expand Down
13 changes: 4 additions & 9 deletions bundle/Handler/Literal/CanonicalUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@

final class CanonicalUrl implements HandlerInterface
{
private RequestStack $requestStack;

private UrlGeneratorInterface $urlGenerator;

public function __construct(RequestStack $requestStack, UrlGeneratorInterface $urlGenerator)
{
$this->requestStack = $requestStack;
$this->urlGenerator = $urlGenerator;
}
public function __construct(
private readonly RequestStack $requestStack,
private readonly UrlGeneratorInterface $urlGenerator,
) {}

public function getMetaTags($tagName, array $params = []): array
{
Expand Down
9 changes: 3 additions & 6 deletions bundle/Handler/Literal/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@

final class Url implements HandlerInterface
{
private RequestStack $requestStack;

public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function __construct(
private readonly RequestStack $requestStack,
) {}

public function getMetaTags(string $tagName, array $params = []): array
{
Expand Down
33 changes: 13 additions & 20 deletions bundle/MetaTag/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,24 @@

final class Collector implements CollectorInterface
{
private Registry $metaTagHandlers;

private ContentTypeService $contentTypeService;

private ConfigResolverInterface $configResolver;

public function __construct(Registry $metaTagHandlers, ContentTypeService $contentTypeService, ConfigResolverInterface $configResolver)
{
$this->metaTagHandlers = $metaTagHandlers;
$this->contentTypeService = $contentTypeService;
$this->configResolver = $configResolver;
}
public function __construct(
private readonly Registry $metaTagHandlers,
private readonly ContentTypeService $contentTypeService,
private readonly ConfigResolverInterface $configResolver,
) {}

public function collect(Content $content): array
{
$metaTags = [];

$allHandlers = $this->configResolver->hasParameter('global_handlers', 'netgen_open_graph') ?
$this->configResolver->getParameter('global_handlers', 'netgen_open_graph') :
[];
$allHandlers = $this->configResolver->hasParameter('global_handlers', 'netgen_open_graph')
? $this->configResolver->getParameter('global_handlers', 'netgen_open_graph')
: [];

$contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
$contentTypeHandlers = $this->configResolver->hasParameter('content_type_handlers', 'netgen_open_graph') ?
$this->configResolver->getParameter('content_type_handlers', 'netgen_open_graph') :
[];
$contentTypeHandlers = $this->configResolver->hasParameter('content_type_handlers', 'netgen_open_graph')
? $this->configResolver->getParameter('content_type_handlers', 'netgen_open_graph')
: [];

if (isset($contentTypeHandlers[$contentType->identifier])) {
$allHandlers = array_merge(
Expand All @@ -61,8 +54,8 @@ public function collect(Content $content): array
foreach ($newMetaTags as $metaTag) {
if (!$metaTag instanceof Item) {
throw new LogicException(
'\'' . $handler['handler'] . '\' handler returned wrong value.' .
' Expected \'Netgen\Bundle\OpenGraphBundle\MetaTag\Item\', got \'' . get_class($metaTag) . '\'.',
'\'' . $handler['handler'] . '\' handler returned wrong value.'
. ' Expected \'Netgen\Bundle\OpenGraphBundle\MetaTag\Item\', got \'' . get_class($metaTag) . '\'.',
);
}

Expand Down
13 changes: 4 additions & 9 deletions bundle/MetaTag/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

final class Item
{
private string $tagName;

private string $tagValue;

public function __construct(string $tagName, string $tagValue)
{
$this->tagName = $tagName;
$this->tagValue = $tagValue;
}
public function __construct(
private readonly string $tagName,
private readonly string $tagValue,
) {}

/**
* Returns tag name.
Expand Down
18 changes: 5 additions & 13 deletions bundle/Templating/Twig/Extension/NetgenOpenGraphRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,18 @@

final class NetgenOpenGraphRuntime
{
private CollectorInterface $tagCollector;

private RendererInterface $tagRenderer;

private LoggerInterface $logger;

private bool $throwExceptions = true;

public function __construct(
CollectorInterface $tagCollector,
RendererInterface $tagRenderer,
?LoggerInterface $logger = null,
private readonly CollectorInterface $tagCollector,
private readonly RendererInterface $tagRenderer,
private ?LoggerInterface $logger = null,
) {
$this->tagCollector = $tagCollector;
$this->tagRenderer = $tagRenderer;
$this->logger = $logger ?? new NullLogger();
$this->logger ??= new NullLogger();
}

/**
* Sets the flag that determines if the exceptions will thrown instead of logged.
* Sets the flag that determines if the exceptions will be thrown instead of logged.
*/
public function setThrowExceptions(bool $throwExceptions = true): void
{
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
}
],
"require": {
"php": "^8.1",
"ibexa/core": "^4.4",
"php": "^8.3",
"ibexa/core": "^5.0",
"twig/twig": "^3.0"
},
"require-dev": {
"ibexa/fieldtype-richtext": "^4.4",
"phpunit/phpunit": "^9.6",
"matthiasnoback/symfony-config-test": "^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^5.0"
"ibexa/fieldtype-richtext": "^5.0",
"phpunit/phpunit": "^10.0",
"matthiasnoback/symfony-config-test": "^6.0",
"matthiasnoback/symfony-dependency-injection-test": "^6.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
31 changes: 14 additions & 17 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.4/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
colors="true"
verbose="true"
processIsolation="false"
stopOnFailure="false"
>
Expand All @@ -15,18 +13,17 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>

<source>
<include>
<directory suffix=".php">bundle</directory>
<exclude>
<directory>bundle/Resources</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory>bundle/Resources</directory>
</exclude>
</source>

<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
5 changes: 2 additions & 3 deletions tests/DependencyInjection/NetgenOpenGraphExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Netgen\Bundle\OpenGraphBundle\DependencyInjection\NetgenOpenGraphExtension;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;

final class NetgenOpenGraphExtensionTest extends AbstractExtensionTestCase
{
/**
* @doesNotPerformAssertions
*/
#[DoesNotPerformAssertions]
public function testItSetsValidContainerParameters(): void
{
$this->container->setParameter('ibexa.site_access.list', []);
Expand Down
34 changes: 33 additions & 1 deletion tests/Handler/FieldType/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,23 @@ public function testGettingTagsWithExceptionThrownByVariationHandler(): void
->method('getField')
->willReturn($this->field);

$this->fieldHelper->expects(self::once())
->method('isFieldEmpty')
->willReturn(false);

$this->variationHandler->expects(self::once())
->method('getVariation')
->willThrowException(new \Exception('Variation handler error'));

$request = Request::create('/');

$this->requestStack->expects(self::once())
->method('getCurrentRequest')
->willReturn($request);

$this->logger->expects(self::once())
->method('error');

$this->image->getMetaTags('some_tag', ['some_value', 'some_value_2', 'some_value_3']);
}

Expand Down Expand Up @@ -221,6 +232,27 @@ public function testGettingTagsWithMultipleArgumentsInArray(): void
->method('getField')
->willReturn($this->field);

$this->image->getMetaTags('some_tag', ['some_value', 'some_value_2']);
$this->fieldHelper->expects(self::once())
->method('isFieldEmpty')
->willReturn(false);

$variation = new Variation(['uri' => '/some/uri']);

$this->variationHandler->expects(self::once())
->method('getVariation')
->willReturn($variation);

$request = Request::create('/');

$this->requestStack->expects(self::exactly(1))
->method('getCurrentRequest')
->willReturn($request);

$result = $this->image->getMetaTags('some_tag', ['some_value', 'some_value_2']);

self::assertCount(1, $result);
self::assertInstanceOf('Netgen\Bundle\OpenGraphBundle\MetaTag\Item', $result[0]);
self::assertSame('some_tag', $result[0]->getTagName());
self::assertSame('http://localhost/some/uri', $result[0]->getTagValue());
}
}
Loading