Skip to content

Commit cddfe2e

Browse files
author
Ante Prkacin
committed
NGSTACK-1000 modify tests to be compatible with PHP8 and PHPUnit12
1 parent e92e7d8 commit cddfe2e

File tree

5 files changed

+19
-35
lines changed

5 files changed

+19
-35
lines changed

tests/DependencyInjection/NetgenOpenGraphExtensionTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
88
use Netgen\Bundle\OpenGraphBundle\DependencyInjection\NetgenOpenGraphExtension;
9+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
910

1011
final class NetgenOpenGraphExtensionTest extends AbstractExtensionTestCase
1112
{
12-
/**
13-
* @doesNotPerformAssertions
14-
*/
13+
#[DoesNotPerformAssertions]
1514
public function testItSetsValidContainerParameters(): void
1615
{
1716
$this->container->setParameter('ibexa.site_access.list', []);

tests/Handler/Literal/UrlTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Netgen\Bundle\OpenGraphBundle\Handler\HandlerInterface;
99
use Netgen\Bundle\OpenGraphBundle\Handler\Literal\Url;
1010
use Netgen\Bundle\OpenGraphBundle\MetaTag\Item;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\TestCase;
1213
use Symfony\Component\HttpFoundation\Request;
1314
use Symfony\Component\HttpFoundation\RequestStack;
@@ -37,9 +38,7 @@ public function testGettingTagsWithEmptyParams(): void
3738
$this->url->getMetaTags('some_tag');
3839
}
3940

40-
/**
41-
* @dataProvider validResultProvider
42-
*/
41+
#[DataProvider('validResultProvider')]
4342
public function testGettingTagsWithValidResult(string $input, string $output): void
4443
{
4544
$request = Request::create('https://domain.com');
@@ -54,7 +53,7 @@ public function testGettingTagsWithValidResult(string $input, string $output): v
5453
self::assertSame($output, $result[0]->getTagValue());
5554
}
5655

57-
public function validResultProvider(): iterable
56+
public static function validResultProvider(): iterable
5857
{
5958
return [
6059
['https://other.domain.com/some/path', 'https://other.domain.com/some/path'],
@@ -66,9 +65,7 @@ public function validResultProvider(): iterable
6665
];
6766
}
6867

69-
/**
70-
* @dataProvider validResultProviderWithoutRequest
71-
*/
68+
#[DataProvider('validResultProviderWithoutRequest')]
7269
public function testGettingTagsWithValidResultAndWithoutRequest(string $input, string $output): void
7370
{
7471
$result = $this->url->getMetaTags('some_tag', [$input]);
@@ -79,7 +76,7 @@ public function testGettingTagsWithValidResultAndWithoutRequest(string $input, s
7976
self::assertSame($output, $result[0]->getTagValue());
8077
}
8178

82-
public function validResultProviderWithoutRequest(): iterable
79+
public static function validResultProviderWithoutRequest(): iterable
8380
{
8481
return [
8582
['https://other.domain.com/some/path', 'https://other.domain.com/some/path'],

tests/Handler/RegistryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ protected function setUp(): void
2020

2121
public function testAddingHandlers(): void
2222
{
23-
$handler = $this->getMockForAbstractClass(HandlerInterface::class);
23+
$handler = $this->createStub(HandlerInterface::class);
2424
$this->registry->addHandler('some_handler', $handler);
2525

2626
self::assertSame($this->registry->getHandler('some_handler'), $handler);
2727
}
2828

2929
public function testGettingHandlers(): void
3030
{
31-
$handler = $this->getMockForAbstractClass(HandlerInterface::class);
31+
$handler = $this->createStub(HandlerInterface::class);
3232
$this->registry->addHandler('some_handler', $handler);
3333

3434
$returnedHandler = $this->registry->getHandler('some_handler');

tests/MetaTag/CollectorTest.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,9 @@ protected function setUp(): void
4848

4949
public function testCollect(): void
5050
{
51-
$this->config->expects(self::at(0))
51+
$this->config
5252
->method('hasParameter')
53-
->willReturn(true);
54-
55-
$this->config->expects(self::at(1))
56-
->method('getParameter')
57-
->willReturn([]);
58-
59-
$this->config->expects(self::at(2))
60-
->method('hasParameter')
61-
->willReturn(true);
53+
->willReturnOnConsecutiveCalls(true, true);
6254

6355
$handlers = [
6456
'article' => [
@@ -72,9 +64,9 @@ public function testCollect(): void
7264
],
7365
];
7466

75-
$this->config->expects(self::at(3))
67+
$this->config
7668
->method('getParameter')
77-
->willReturn($handlers);
69+
->willReturnOnConsecutiveCalls([], $handlers);
7870

7971
$versionInfo = new VersionInfo(
8072
[
@@ -100,7 +92,7 @@ public function testCollect(): void
10092
'fieldDefinitions' => [
10193
new FieldDefinition(
10294
[
103-
'id' => 'id',
95+
'id' => 42,
10496
'identifier' => 'name',
10597
'fieldTypeIdentifier' => 'eztext',
10698
],
@@ -136,18 +128,14 @@ public function testCollectWithLogicException(): void
136128

137129
$handlers = ['all_content_types' => $handlerArray];
138130

139-
$this->config->expects(self::at(0))
131+
$this->config
140132
->method('hasParameter')
141-
->willReturn(true);
133+
->willReturnOnConsecutiveCalls(true, false);
142134

143-
$this->config->expects(self::at(1))
135+
$this->config
144136
->method('getParameter')
145137
->willReturn($handlers);
146138

147-
$this->config->expects(self::at(2))
148-
->method('hasParameter')
149-
->willReturn(false);
150-
151139
$versionInfo = new VersionInfo(
152140
[
153141
'contentInfo' => new ContentInfo(
@@ -172,7 +160,7 @@ public function testCollectWithLogicException(): void
172160
'fieldDefinitions' => [
173161
new FieldDefinition(
174162
[
175-
'id' => 'id',
163+
'id' => 42,
176164
'identifier' => 'name',
177165
'fieldTypeIdentifier' => 'eztext',
178166
],

tests/NetgenOpenGraphBundleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testItAddsCompilerPass(): void
1818
->onlyMethods(['addCompilerPass'])
1919
->getMock();
2020

21-
$container->expects(self::at(0))
21+
$container->expects(self::once())
2222
->method('addCompilerPass')
2323
->with(new MetaTagHandlersCompilerPass());
2424

0 commit comments

Comments
 (0)