Skip to content

Commit f2f0db0

Browse files
authored
IBX-10669: Fixed accessing isContainer property for CT drafts (#653)
For more details see https://issues.ibexa.co/browse/IBX-10669 and #653 Key changes: * Fixed accessing `isContainer` property for content type drafts
1 parent c4b3f76 commit f2f0db0

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

rector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
declare(strict_types=1);
88

99
use Ibexa\Contracts\Rector\Sets\IbexaSetList;
10+
use Ibexa\Rector\Rule\PropertyToGetterRector;
1011
use Rector\Config\RectorConfig;
1112
use Rector\Doctrine\Set\DoctrineSetList;
1213
use Rector\Symfony\Set\SymfonySetList;
@@ -33,4 +34,7 @@
3334
CommandConfigureToAttributeRector::class => [
3435
__DIR__ . '/tests/bundle/Core/EventListener/BackwardCompatibleCommandListenerTest.php',
3536
],
37+
PropertyToGetterRector::class => [
38+
__DIR__ . '/tests/lib/Repository/Values/ContentType/ContentTypeTest.php',
39+
]
3640
]);

src/lib/Repository/Values/ContentType/ContentTypeDraft.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,9 @@ public function hasFieldDefinition(string $fieldDefinitionIdentifier): bool
149149
{
150150
return $this->innerContentType->hasFieldDefinition($fieldDefinitionIdentifier);
151151
}
152+
153+
public function isContainer(): bool
154+
{
155+
return $this->innerContentType->isContainer();
156+
}
152157
}

tests/integration/RepositoryInstaller/.gitkeep

Whitespace-only changes.

tests/lib/Repository/Values/ContentType/ContentTypeTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
1212
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCollection as APIFieldDefinitionCollection;
1313
use Ibexa\Core\Repository\Values\ContentType\ContentType;
14+
use Ibexa\Core\Repository\Values\ContentType\ContentTypeDraft;
1415
use PHPUnit\Framework\TestCase;
1516

1617
/**
1718
* @covers \Ibexa\Core\Repository\Values\ContentType\ContentType
1819
*/
1920
final class ContentTypeTest extends TestCase
2021
{
21-
private const EXAMPLE_FIELD_DEFINITION_IDENTIFIER = 'example';
22-
private const EXAMPLE_FIELD_TYPE_IDENTIFIER = 'ezcustom';
22+
private const string EXAMPLE_FIELD_DEFINITION_IDENTIFIER = 'example';
23+
private const string EXAMPLE_FIELD_TYPE_IDENTIFIER = 'ezcustom';
2324

2425
public function testStrictGetters(): void
2526
{
@@ -139,4 +140,31 @@ public function testGetFirstFieldDefinitionOfType(): void
139140
$contentType->getFirstFieldDefinitionOfType(self::EXAMPLE_FIELD_TYPE_IDENTIFIER)
140141
);
141142
}
143+
144+
/**
145+
* @dataProvider provideForDeprecatedPropertyAccessMatchesMethodCallResult
146+
*/
147+
public function testDeprecatedPropertyAccessMatchesMethodCallResult(bool $isContainer): void
148+
{
149+
$contentTypeDraft = new ContentTypeDraft([
150+
'innerContentType' => new ContentType([
151+
'isContainer' => $isContainer,
152+
]),
153+
]);
154+
155+
/** @phpstan-ignore-next-line property.protected
156+
* intentionally violating deprecated property access.
157+
*/
158+
self::assertSame($isContainer, $contentTypeDraft->isContainer);
159+
self::assertSame($isContainer, $contentTypeDraft->isContainer());
160+
}
161+
162+
/**
163+
* @return iterable<string, array{0: bool}>
164+
*/
165+
public function provideForDeprecatedPropertyAccessMatchesMethodCallResult(): iterable
166+
{
167+
yield 'content type draft is a container' => [true];
168+
yield 'content type draft is not a container' => [false];
169+
}
142170
}

0 commit comments

Comments
 (0)