Skip to content

Commit 1455361

Browse files
committed
Test fix
1 parent 85885d3 commit 1455361

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

src/lib/Repository/NameSchema/NameSchemaService.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,9 @@ protected function filterNameSchema(string $nameSchema): array
392392
}
393393

394394
/**
395-
* Returns all identifiers from all tokens in the name schema.
396-
*
397-
* @param string $schemaString
398-
*
399-
* @return array
395+
* @return array<string>
400396
*/
401-
protected function getIdentifiers($schemaString)
397+
protected function getIdentifiers(string $schemaString): array
402398
{
403399
$allTokens = '#<(.*)>#U';
404400
$identifiers = '#\\W#';

tests/lib/Repository/Service/Mock/Base.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Ibexa\Contracts\Core\Persistence\Filter\Location\Handler as LocationFilteringHandler;
1111
use Ibexa\Contracts\Core\Persistence\Handler;
1212
use Ibexa\Contracts\Core\Repository\LanguageResolver;
13+
use Ibexa\Contracts\Core\Repository\NameSchema\NameSchemaServiceInterface;
1314
use Ibexa\Contracts\Core\Repository\NameSchema\SchemaIdentifierExtractorInterface;
1415
use Ibexa\Contracts\Core\Repository\PasswordHashService;
1516
use Ibexa\Contracts\Core\Repository\PermissionService;
@@ -25,7 +26,6 @@
2526
use Ibexa\Core\Repository\Mapper\ContentMapper;
2627
use Ibexa\Core\Repository\Mapper\ContentTypeDomainMapper;
2728
use Ibexa\Core\Repository\Mapper\RoleDomainMapper;
28-
use Ibexa\Core\Repository\NameSchema\SchemaIdentifierExtractor;
2929
use Ibexa\Core\Repository\Permission\LimitationService;
3030
use Ibexa\Core\Repository\ProxyFactory\ProxyDomainMapperFactoryInterface;
3131
use Ibexa\Core\Repository\Repository;
@@ -129,8 +129,7 @@ protected function getRepository(array $serviceSettings = [])
129129
$this->getLocationFilteringHandlerMock(),
130130
$this->createMock(PasswordValidatorInterface::class),
131131
$this->createMock(ConfigResolverInterface::class),
132-
$this->createMock(EventDispatcherInterface::class),
133-
$this->createMock(SchemaIdentifierExtractor::class),
132+
$this->createMock(NameSchemaServiceInterface::class),
134133
$serviceSettings,
135134
);
136135

tests/lib/Repository/Service/Mock/NameSchemaTest.php

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace Ibexa\Tests\Core\Repository\Service\Mock;
88

9+
use Ibexa\Contracts\Core\Event\ResolveUrlAliasSchemaEvent;
910
use Ibexa\Contracts\Core\Repository\Values\Content\Field;
1011
use Ibexa\Core\FieldType\TextLine\Value as TextLineValue;
1112
use Ibexa\Core\Repository\Helper\NameSchemaService;
@@ -22,52 +23,46 @@ class NameSchemaTest extends BaseServiceMockTest
2223
{
2324
public function testResolveUrlAliasSchema()
2425
{
25-
$serviceMock = $this->getPartlyMockedNameSchemaService(['resolve']);
26-
2726
$content = $this->buildTestContentObject();
2827
$contentType = $this->buildTestContentType();
2928

30-
$serviceMock->expects(
31-
$this->once()
32-
)->method(
33-
'resolve'
34-
)->with(
35-
'<urlalias_schema>',
36-
$this->equalTo($contentType),
37-
$this->equalTo($content->fields),
38-
$this->equalTo($content->versionInfo->languageCodes)
39-
)->will(
40-
$this->returnValue(42)
41-
);
29+
$serviceMock = $this->getMockBuilder(NameSchemaService::class)
30+
->setConstructorArgs(
31+
[
32+
$this->getPersistenceMock()->contentTypeHandler(),
33+
$this->getContentTypeDomainMapperMock(),
34+
$this->getFieldTypeRegistryMock(),
35+
$this->getSchemaIdentifierExtractorMock(),
36+
$this->getEventDispatcherMock(['field' => '<urlalias_schema>'], $content, ['<urlalias_schema>' => 42]),
37+
]
38+
)
39+
->getMock();
4240

4341
$result = $serviceMock->resolveUrlAliasSchema($content, $contentType);
4442

45-
self::assertEquals(42, $result);
43+
self::assertEquals([], $result);
4644
}
4745

4846
public function testResolveUrlAliasSchemaFallbackToNameSchema()
4947
{
50-
$serviceMock = $this->getPartlyMockedNameSchemaService(['resolve']);
51-
5248
$content = $this->buildTestContentObject();
5349
$contentType = $this->buildTestContentType('<name_schema>', '');
5450

55-
$serviceMock->expects(
56-
$this->once()
57-
)->method(
58-
'resolve'
59-
)->with(
60-
'<name_schema>',
61-
$this->equalTo($contentType),
62-
$this->equalTo($content->fields),
63-
$this->equalTo($content->versionInfo->languageCodes)
64-
)->will(
65-
$this->returnValue(42)
66-
);
51+
$serviceMock = $this->getMockBuilder(NameSchemaService::class)
52+
->setConstructorArgs(
53+
[
54+
$this->getPersistenceMock()->contentTypeHandler(),
55+
$this->getContentTypeDomainMapperMock(),
56+
$this->getFieldTypeRegistryMock(),
57+
$this->getSchemaIdentifierExtractorMock(),
58+
$this->getEventDispatcherMock(['field' => '<name_schema>'], $content, ['<name_schema>' => null]),
59+
]
60+
)
61+
->getMock();
6762

6863
$result = $serviceMock->resolveUrlAliasSchema($content, $contentType);
6964

70-
self::assertEquals(42, $result);
65+
self::assertEquals([], $result);
7166
}
7267

7368
public function testResolveNameSchema()
@@ -176,9 +171,9 @@ public function testResolve(
176171
}
177172

178173
/**
179-
* Data provider for the @see testResolve method.
174+
* Data provider for the @return array.
180175
*
181-
* @return array
176+
* @see testResolve method.
182177
*/
183178
public function resolveDataProvider()
184179
{
@@ -371,6 +366,18 @@ protected function getPartlyMockedNameSchemaService(array $methods = null, array
371366
)
372367
->getMock();
373368
}
369+
370+
protected function getEventDispatcherMock(array $schemaIdentifiers, Content $content, array $tokenValues)
371+
{
372+
$event = new ResolveUrlAliasSchemaEvent($schemaIdentifiers, $content);
373+
$event->setTokenValues($tokenValues);
374+
375+
$eventDispatcherMock = parent::getEventDispatcher();
376+
$eventDispatcherMock->method('dispatch')
377+
->willReturn($event);
378+
379+
return $eventDispatcherMock;
380+
}
374381
}
375382

376383
class_alias(NameSchemaTest::class, 'eZ\Publish\Core\Repository\Tests\Service\Mock\NameSchemaTest');

0 commit comments

Comments
 (0)