Skip to content

Commit 9aa176e

Browse files
committed
OXDEV-9270 Update to phpunit 12.5
1 parent ce869aa commit 9aa176e

13 files changed

Lines changed: 62 additions & 89 deletions

.github/oxid-esales/twig-component.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ install:
2323
"mikey179/vfsstream": "~1.6.8",
2424
"oxid-esales/developer-tools": "{{ .Data.install.composer.dev_ref }}",
2525
"phpspec/prophecy-phpunit": "^v2.0.1",
26-
"phpunit/phpunit": "^11.4"
26+
"phpunit/phpunit": "^12.5"
2727
},
2828
"autoload-dev":{
2929
"psr-4":{

tests/Integration/Extensions/IncludeContentExtensionTest.php

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
1717
use OxidEsales\Twig\Extensions\IncludeContentExtension;
1818
use PHPUnit\Framework\Attributes\DataProvider;
19-
use PHPUnit\Framework\MockObject\MockBuilder;
20-
use PHPUnit\Framework\MockObject\MockObject;
2119
use Twig\Environment;
2220
use Twig\Error\LoaderError;
2321
use Twig\Extension\StringLoaderExtension;
@@ -28,25 +26,15 @@ final class IncludeContentExtensionTest extends AbstractExtensionTestCase
2826
{
2927
use ContainerTrait;
3028

31-
private MockBuilder $contentMockBuilder;
32-
private MockObject&ContentFactory $contentFactoryMock;
29+
private ContentFactory $contentFactoryStub;
3330
private string $spamContent = 'not spam<script>alert("spam")</script>';
3431

3532
public function setUp(): void
3633
{
3734
parent::setUp();
3835

39-
$this->contentMockBuilder = $this
40-
->getMockBuilder(Content::class)
41-
->disableOriginalConstructor()
42-
->onlyMethods(['getLanguage']);
43-
44-
$this->contentFactoryMock = $this
45-
->getMockBuilder(ContentFactory::class)
46-
->onlyMethods(['getContent'])
47-
->getMock();
48-
49-
$this->contentFactoryMock
36+
$this->contentFactoryStub = $this->createStub(ContentFactory::class);
37+
$this->contentFactoryStub
5038
->method('getContent')
5139
->willReturnMap($this->getContentMap());
5240
}
@@ -112,49 +100,49 @@ private function initializeExtension(bool $sanitizerEnabled): void
112100
$this->setParameter('oxid_esales.html_sanitizer_enabled', $sanitizerEnabled);
113101

114102
$this->extension = new IncludeContentExtension(
115-
$this->contentFactoryMock,
103+
$this->contentFactoryStub,
116104
ContainerFacade::get(HtmlSanitizerInterface::class)
117105
);
118106
}
119107

120-
private function prepareContentMock(int $language, array $fields): MockObject
108+
private function prepareContent(int $language, array $fields): Content
121109
{
122-
$mock = $this->contentMockBuilder->getMock();
123-
$mock->method('getLanguage')->willReturn($language);
110+
$content = new Content();
111+
$content->setLanguage($language);
124112

125113
foreach ($fields as $field => $value) {
126114
$property = 'oxcontents__' . $field;
127-
$mock->$property = (object)['value' => $value];
115+
$content->$property = (object)['value' => $value];
128116
}
129117

130-
return $mock;
118+
return $content;
131119
}
132120

133121
/** Build the content return map for the mock factory */
134122
private function getContentMap(): array
135123
{
136124
return [
137-
['ident', 'german', $this->prepareContentMock(0, [
125+
['ident', 'german', $this->prepareContent(0, [
138126
'oxactive' => true,
139127
'oxcontent' => 'Template code (DE)',
140128
])],
141-
['ident', 'english', $this->prepareContentMock(1, [
129+
['ident', 'english', $this->prepareContent(1, [
142130
'oxactive' => true,
143131
'oxcontent' => 'Template code (EN)',
144132
])],
145-
['ident', 'twig_code', $this->prepareContentMock(0, [
133+
['ident', 'twig_code', $this->prepareContent(0, [
146134
'oxactive' => true,
147135
'oxcontent' => 'In my_var I have {{ my_var }} value',
148136
])],
149-
['ident', 'dynamic_content', $this->prepareContentMock(0, [
137+
['ident', 'dynamic_content', $this->prepareContent(0, [
150138
'oxactive' => true,
151139
'oxcontent' => 'Dynamic content',
152140
])],
153-
['ident', 'not_active', $this->prepareContentMock(0, [
141+
['ident', 'not_active', $this->prepareContent(0, [
154142
'oxactive' => false,
155143
'oxcontent' => 'Not active content',
156144
])],
157-
['ident', 'spam', $this->prepareContentMock(0, [
145+
['ident', 'spam', $this->prepareContent(0, [
158146
'oxactive' => true,
159147
'oxcontent' => $this->spamContent,
160148
])],

tests/Integration/TwigEngineTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use org\bovigo\vfs\vfsStream;
1313
use OxidEsales\Twig\Resolver\TemplateChain\TemplateChainResolverInterface;
1414
use OxidEsales\Twig\TwigEngine;
15-
use OxidEsales\Twig\TwigEngineConfigurationInterface;
1615
use PHPUnit\Framework\TestCase;
1716
use Prophecy\PhpUnit\ProphecyTrait;
1817
use Prophecy\Prophecy\ObjectProphecy;
@@ -80,15 +79,6 @@ public function testRenderFragment(): void
8079

8180
private function getEngine(): TwigEngine
8281
{
83-
/** @var TwigEngineConfigurationInterface $configuration */
84-
$configuration = $this->getMockBuilder(TwigEngineConfigurationInterface::class)->getMock();
85-
$configuration->method('getParameters')
86-
->willReturn([
87-
'template_dir' => [$this->templateDirPath],
88-
'is_debug' => 'false',
89-
'cache_dir' => 'foo',
90-
]);
91-
9282
$loader = new FilesystemLoader($this->templateDirPath);
9383

9484
$engine = new Environment($loader);

tests/Unit/Extensions/IncludeWidgetExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp(): void
2828

2929
public function testIncludeWidget(): void
3030
{
31-
$widgetControl = $this->createMock(WidgetControl::class);
31+
$widgetControl = $this->createStub(WidgetControl::class);
3232
$widgetControl->method('start')->willReturn('html');
3333
Registry::set(WidgetControl::class, $widgetControl);
3434

tests/Unit/Extensions/StyleExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function dataProvider(): array
3737

3838
private function getTwigEnvironment($isDynamic): Environment
3939
{
40-
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
40+
$loader = $this->createStub(LoaderInterface::class);
4141
$env = new Environment($loader, []);
4242
$env->addGlobal('__oxid_include_dynamic', $isDynamic);
4343
return $env;

tests/Unit/Loader/CmsLoaderTest.php

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,28 @@
1313
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\TemplateLogic\ContentFactory;
1414
use OxidEsales\Twig\Loader\CmsLoader;
1515
use OxidEsales\Twig\Loader\CmsTemplateNameParser;
16-
use PHPUnit\Framework\MockObject\MockBuilder;
17-
use PHPUnit\Framework\MockObject\MockObject;
1816
use PHPUnit\Framework\TestCase;
1917
use Twig\Error\LoaderError;
2018

2119
final class CmsLoaderTest extends TestCase
2220
{
2321
private CmsLoader $contentTemplateLoader;
24-
private MockBuilder $contentMockBuilder;
2522

2623
public function setUp(): void
2724
{
2825
parent::setUp();
29-
$this->contentMockBuilder = $this->getMockBuilder(Content::class)->onlyMethods(['getLanguage']);
3026

31-
$validContentMock = $this->prepareContentMock(
27+
$validContent = $this->prepareContentStub(
3228
0,
3329
['oxactive' => true, 'oxcontent' => "Template code (DE)", 'oxtimestamp' => '2018-10-09 09:32:06']
3430
);
3531

36-
$englishContentMock = $this->prepareContentMock(
32+
$englishContent = $this->prepareContentStub(
3733
1,
3834
['oxactive' => true, 'oxcontent' => "Template code (EN)", 'oxtimestamp' => '2018-10-09 09:32:06']
3935
);
4036

41-
$fieldContentMock = $this->prepareContentMock(
37+
$fieldContent = $this->prepareContentStub(
4238
0,
4339
[
4440
'oxactive' => true,
@@ -47,32 +43,29 @@ public function setUp(): void
4743
]
4844
);
4945

50-
$notFreshContentMock = $this->prepareContentMock(
46+
$notFreshContent = $this->prepareContentStub(
5147
0,
5248
['oxactive' => true, 'oxtimestamp' => '2018-10-09 09:40:25']
5349
);
5450

55-
$notValidContentMock = $this->prepareContentMock(0, ['oxactive' => false]);
51+
$notValidContent = $this->prepareContentStub(0, ['oxactive' => false]);
5652

57-
$contentFactoryMock = $this
58-
->getMockBuilder(ContentFactory::class)
59-
->onlyMethods(['getContent'])
60-
->getMock();
53+
$contentFactoryStub = $this->createStub(ContentFactory::class);
6154

62-
$contentFactoryMock
55+
$contentFactoryStub
6356
->method('getContent')
6457
->willReturnMap(
6558
[
66-
['ident', 'valid', $validContentMock],
67-
['oxid', 'english', $englishContentMock],
68-
['ident', 'field', $fieldContentMock],
69-
['oxid', 'notFresh', $notFreshContentMock],
70-
['ident', 'notValid', $notValidContentMock]
59+
['ident', 'valid', $validContent],
60+
['oxid', 'english', $englishContent],
61+
['ident', 'field', $fieldContent],
62+
['oxid', 'notFresh', $notFreshContent],
63+
['ident', 'notValid', $notValidContent]
7164
]
7265
);
7366

74-
/** @var ContentFactory $contentFactoryMock */
75-
$this->contentTemplateLoader = new CmsLoader(new CmsTemplateNameParser(), $contentFactoryMock);
67+
/** @var ContentFactory $contentFactoryStub */
68+
$this->contentTemplateLoader = new CmsLoader(new CmsTemplateNameParser(), $contentFactoryStub);
7669
}
7770

7871
/**
@@ -143,16 +136,22 @@ public function testGetCacheKey(): void
143136
);
144137
}
145138

146-
private function prepareContentMock(int $language, array $fields): MockObject
139+
private function prepareContentStub(int $language, array $fields): Content
147140
{
148-
$mock = $this->contentMockBuilder->getMock();
149-
$mock->method('getLanguage')->willReturn($language);
141+
$contentStub = $this->createStub(Content::class);
142+
$contentStub->method('getLanguage')->willReturn($language);
150143

144+
$fieldValues = [];
151145
foreach ($fields as $field => $value) {
152146
$fieldName = 'oxcontents__' . $field;
153-
$mock->$fieldName = (object) ['value' => $value];
147+
$fieldValues[$fieldName] = (object) ['value' => $value];
154148
}
155149

156-
return $mock;
150+
$contentStub->method('__get')
151+
->willReturnCallback(
152+
static fn(string $fieldName): ?object => $fieldValues[$fieldName] ?? null
153+
);
154+
155+
return $contentStub;
157156
}
158157
}

tests/Unit/Resolver/TemplateChain/DataObject/TemplateChainTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,13 @@ private function createMockTemplate(
407407
string $fullyQualifiedName,
408408
string $parentNamespace = ''
409409
): TemplateTypeInterface {
410-
$mock = $this->createMock(TemplateTypeInterface::class);
411-
412-
$mock->method('getNamespace')
413-
->willReturn($namespace);
414-
415-
$mock->method('getFullyQualifiedName')
416-
->willReturn($fullyQualifiedName);
417-
418-
$mock->method('getParentNamespace')
419-
->willReturn($parentNamespace);
420-
421-
return $mock;
410+
return $this->createConfiguredStub(
411+
TemplateTypeInterface::class,
412+
[
413+
'getNamespace' => $namespace,
414+
'getFullyQualifiedName' => $fullyQualifiedName,
415+
'getParentNamespace' => $parentNamespace,
416+
]
417+
);
422418
}
423419
}

tests/Unit/Resolver/TemplateChain/TemplateChainResolverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function testGetLastChildWithMultipleCallsWillUseCachedResult(): void
2222
{
2323
$templateName = 'widget/header.html.twig';
2424

25-
$templateTypeMock = $this->createMock(TemplateTypeInterface::class);
26-
$lastChildMock = $this->createConfiguredMock(TemplateTypeInterface::class, [
25+
$templateTypeMock = $this->createStub(TemplateTypeInterface::class);
26+
$lastChildMock = $this->createConfiguredStub(TemplateTypeInterface::class, [
2727
'getFullyQualifiedName' => '@my_module/widget/header.html.twig'
2828
]);
29-
$templateChainMock = $this->createConfiguredMock(TemplateChain::class, [
29+
$templateChainMock = $this->createConfiguredStub(TemplateChain::class, [
3030
'getLastChild' => $lastChildMock
3131
]);
3232

tests/Unit/TokenParser/CaptureTokenParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function setUp(): void
2929
{
3030
parent::setUp();
3131

32-
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
32+
$loader = $this->createStub(LoaderInterface::class);
3333
$this->environment = new Environment($loader, ['cache' => false]);
3434

3535
$this->captureTokenParser = new CaptureTokenParser();

tests/Unit/TokenParser/HasRightsTokenParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testDecideMyTagForkCorrect(): void
5454

5555
public function testParse(): void
5656
{
57-
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
57+
$loader = $this->createStub(LoaderInterface::class);
5858
$env = new Environment($loader, array('cache' => false, 'autoescape' => false));
5959
$env->addExtension(new HasRightsExtension(new HasRightsTokenParser(HasRightsNode::class)));
6060

@@ -75,7 +75,7 @@ public function testParse(): void
7575

7676
public function testParseException(): void
7777
{
78-
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
78+
$loader = $this->createStub(LoaderInterface::class);
7979
$env = new Environment($loader, ['cache' => false, 'autoescape' => false]);
8080
$env->addExtension(new HasRightsExtension(new HasRightsTokenParser(HasRightsNode::class)));
8181

0 commit comments

Comments
 (0)