Skip to content

Commit

Permalink
strict typing
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed May 4, 2024
1 parent 672024c commit 3b7fb6c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 120 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog
* Drop support for old Symfony versions
* Supprt PHP 8.1 - 8.3
* Drop support for old PHP versions
* TranslatableInterface now uses typehints, adjust your implementations accordingly.
* Use DateTimeInterface instead of DateTime.
* Adjust to doctrine and twig BC breaks. If you extended classes or customized services, check for old `Twig_*` classes or `Doctrine\Common\Persistence` namespace.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function process(ContainerBuilder $container): void

$voters = new \SplPriorityQueue();
foreach ($container->findTaggedServiceIds('cmf_published_voter') as $id => $attributes) {
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$priority = $attributes[0]['priority'] ?? 0;
$voters->insert(new Reference($id), $priority);
}

Expand Down
148 changes: 62 additions & 86 deletions src/Templating/Helper/Cmf.php

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Translatable/TranslatableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ interface TranslatableInterface
* @return string|bool The locale of this model or false if
* translations are disabled in this project
*/
public function getLocale();
public function getLocale(): bool|string;

/**
* @param string|bool $locale The local for this model, or false if
* @param bool|string $locale The local for this model, or false if
* translations are disabled in this project
*/
public function setLocale($locale);
public function setLocale(bool|string $locale): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

class CmfCoreExtensionTest extends TestCase
{
/**
* @var ContainerBuilder
*/
private $container;
private ContainerBuilder $container;

protected function setUp(): void
{
Expand Down
31 changes: 12 additions & 19 deletions tests/Functional/Templating/Helper/CmfHierarchyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@

class CmfHierarchyTest extends BaseTestCase
{
/**
* @var AuthorizationCheckerInterface|MockObject
*/
private $publishWorkflowChecker;

/**
* @var Cmf
*/
private $helper;
private MockObject&AuthorizationCheckerInterface $publishWorkflowChecker;
private Cmf $helper;

public function setUp(): void
{
Expand All @@ -39,14 +32,14 @@ public function setUp(): void
$this->publishWorkflowChecker = $this->createMock(AuthorizationCheckerInterface::class);
$this->publishWorkflowChecker
->method('isGranted')
->will($this->returnValue(true))
->willReturn(true)
;

$this->helper = new Cmf($this->publishWorkflowChecker);
$this->helper->setDoctrineRegistry($dbManager->getRegistry(), 'default');
}

public function testGetDescendants()
public function testGetDescendants(): void
{
$this->assertEquals([], $this->helper->getDescendants(null));

Expand All @@ -60,7 +53,7 @@ public function testGetDescendants()
/**
* @dataProvider getPrevData
*/
public function testGetPrev($expected, $path, $anchor = null, $depth = null, $class = 'Doctrine\ODM\PHPCR\Document\Generic')
public function testGetPrev(?string $expected, ?string $path, ?string $anchor = null, ?int $depth = null, string $class = Generic::class): void
{
$prev = $this->helper->getPrev($path, $anchor, $depth);
if (null === $expected) {
Expand All @@ -71,7 +64,7 @@ public function testGetPrev($expected, $path, $anchor = null, $depth = null, $cl
}
}

public static function getPrevData()
public static function getPrevData(): array
{
return [
[null, null],
Expand Down Expand Up @@ -99,7 +92,7 @@ public static function getPrevData()
/**
* @dataProvider getNextData
*/
public function testGetNext($expected, $path, $anchor = null, $depth = null, $class = Generic::class)
public function testGetNext(?string $expected, ?string $path, ?string $anchor = null, ?int $depth = null, string $class = Generic::class): void
{
$next = $this->helper->getNext($path, $anchor, $depth);
if (null === $expected) {
Expand All @@ -110,7 +103,7 @@ public function testGetNext($expected, $path, $anchor = null, $depth = null, $cl
}
}

public static function getNextData()
public static function getNextData(): array
{
return [
[null, null],
Expand Down Expand Up @@ -139,7 +132,7 @@ public static function getNextData()
/**
* @dataProvider getPrevLinkableData
*/
public function testGetPrevLinkable($expected, $path, $anchor = null, $depth = null)
public function testGetPrevLinkable(?string $expected, ?string $path, ?string $anchor = null, ?int $depth = null): void
{
$prev = $this->helper->getPrevLinkable($path, $anchor, $depth);
if (null === $expected) {
Expand All @@ -150,7 +143,7 @@ public function testGetPrevLinkable($expected, $path, $anchor = null, $depth = n
}
}

public static function getPrevLinkableData()
public static function getPrevLinkableData(): array
{
// TODO: expand test case
return [
Expand All @@ -164,7 +157,7 @@ public static function getPrevLinkableData()
/**
* @dataProvider getNextLinkableData
*/
public function testGetNextLinkable($expected, $path, $anchor = null, $depth = null)
public function testGetNextLinkable(?string $expected, ?string $path, ?string $anchor = null, ?int $depth = null): void
{
$next = $this->helper->getNextLinkable($path, $anchor, $depth);
if (null === $expected) {
Expand All @@ -175,7 +168,7 @@ public function testGetNextLinkable($expected, $path, $anchor = null, $depth = n
}
}

public static function getNextLinkableData()
public static function getNextLinkableData(): array
{
// TODO: expand test case
return [
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Twig/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class ServiceTest extends BaseTestCase
{
public function testContainer()
public function testContainer(): void
{
/** @var \Twig\Environment $twig */
$twig = $this->getContainer()->get('test.service_container')->get('twig');
Expand Down
7 changes: 1 addition & 6 deletions tests/Unit/Twig/Extension/CmfExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,17 @@
use PHPUnit\Framework\TestCase;
use Symfony\Cmf\Bundle\CoreBundle\Templating\Helper\Cmf;
use Symfony\Cmf\Bundle\CoreBundle\Twig\Extension\CmfExtension;
use Twig\Environment;
use Twig\Loader\ArrayLoader;

class CmfExtensionTest extends TestCase
{
private Cmf&MockObject $cmfHelper;
private Environment $env;
private CmfExtension $cmfExtension;

public function setUp(): void
{
$this->cmfHelper = $this->createMock(Cmf::class);

$this->cmfExtension = new CmfExtension($this->cmfHelper);
$this->env = new Environment(new ArrayLoader([]));
$this->env->addExtension($this->cmfExtension);
}

/**
Expand All @@ -54,7 +49,7 @@ public function testFunctions($methodName, array $methodArguments, $helperMethod
public function getFunctionsData(): array
{
return [
['isPublished', ['document1']],
['isPublished', [$this]],
['isLinkable', ['document1']],
['getChild', ['parent', 'name']],
['getChildren', ['parent', true], 'getChildren', ['parent', true, false, null, false, null]],
Expand Down

0 comments on commit 3b7fb6c

Please sign in to comment.