Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions tests/PintoSlotsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

namespace Pinto\tests;

use PHPUnit\Framework\TestCase;
use Pinto\Exception\Slots\UnknownValue;
use Pinto\Slots;
Expand Down Expand Up @@ -29,9 +31,9 @@ final class PintoSlotsTest extends TestCase
{
public function testSlotsAttribute(): void
{
static::expectException(LogicException::class);
static::expectException(\LogicException::class);
static::expectExceptionMessage('Using this attribute without named parameters is not supported.');
new Pinto\Attribute\ObjectType\Slots('');
new \Pinto\Attribute\ObjectType\Slots('');
}

public function testSlotsBuild(): void
Expand Down Expand Up @@ -62,7 +64,7 @@ public function testSlotsExplicit(): void

public function testSlotsExplicitEnums(): void
{
$object = new Pinto\tests\fixtures\Objects\Slots\PintoObjectSlotsExplicitEnums();
$object = new fixtures\Objects\Slots\PintoObjectSlotsExplicitEnums();
$build = $object();
static::assertInstanceOf(Slots\Build::class, $build);
static::assertEquals('Slot One', $build->pintoGet(SlotEnum::Slot1));
Expand All @@ -79,7 +81,7 @@ public function testSlotsExplicitEnumClass(): void
{
// Call \Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject
// directly since pintoMapping won't execute enum->cases expansion..
[1 => $slotsDefinition] = Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject(PintoObjectSlotsExplicitEnumClass::class, PintoListSlots::PintoObjectSlotsExplicitEnumClass, definitionDiscovery: new Pinto\DefinitionDiscovery());
[1 => $slotsDefinition] = \Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject(PintoObjectSlotsExplicitEnumClass::class, PintoListSlots::PintoObjectSlotsExplicitEnumClass, definitionDiscovery: new \Pinto\DefinitionDiscovery());

static::assertInstanceOf(Slots\Definition::class, $slotsDefinition);
static::assertEquals(new SlotList([
Expand All @@ -94,7 +96,7 @@ public function testSlotsExplicitEnumClass(): void
*/
public function testPintoObjectSlotsBindPromotedPublic(): void
{
[1 => $slotsDefinition] = Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject(PintoObjectSlotsBindPromotedPublic::class, PintoListSlots::PintoObjectSlotsBindPromotedPublic, definitionDiscovery: new Pinto\DefinitionDiscovery());
[1 => $slotsDefinition] = \Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject(PintoObjectSlotsBindPromotedPublic::class, PintoListSlots::PintoObjectSlotsBindPromotedPublic, definitionDiscovery: new \Pinto\DefinitionDiscovery());

static::assertInstanceOf(Slots\Definition::class, $slotsDefinition);
static::assertEquals(new SlotList([
Expand All @@ -118,7 +120,7 @@ public function testPintoObjectSlotsBindPromotedPublic(): void
*/
public function PintoObjectSlotsBindPromotedPublicNonConstructor(): void
{
[1 => $slotsDefinition] = Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject(PintoObjectSlotsBindPromotedPublicNonConstructor::class, PintoListSlots::PintoObjectSlotsBindPromotedPublicNonConstructor, definitionDiscovery: new Pinto\DefinitionDiscovery());
[1 => $slotsDefinition] = \Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject(PintoObjectSlotsBindPromotedPublicNonConstructor::class, PintoListSlots::PintoObjectSlotsBindPromotedPublicNonConstructor, definitionDiscovery: new \Pinto\DefinitionDiscovery());

static::assertInstanceOf(Slots\Definition::class, $slotsDefinition);
static::assertEquals(new SlotList([
Expand All @@ -135,14 +137,14 @@ public function PintoObjectSlotsBindPromotedPublicNonConstructor(): void

public function testPintoObjectSlotsBindPromotedPublicWithDefinedSlots(): void
{
static::expectException(Pinto\Exception\PintoThemeDefinition::class);
static::expectException(\Pinto\Exception\PintoThemeDefinition::class);
static::expectExceptionMessage('Slots must use reflection (no explicitly defined `$slots`) when promoted properties bind is on.');
Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject(Pinto\tests\fixtures\Objects\Faulty\PintoObjectSlotsBindPromotedPublicWithDefinedSlots::class, Lists\PintoFaultyList::PintoObjectSlotsBindPromotedPublicWithDefinedSlots, definitionDiscovery: new Pinto\DefinitionDiscovery());
\Pinto\ObjectType\ObjectTypeDiscovery::definitionForThemeObject(fixtures\Objects\Faulty\PintoObjectSlotsBindPromotedPublicWithDefinedSlots::class, Lists\PintoFaultyList::PintoObjectSlotsBindPromotedPublicWithDefinedSlots, definitionDiscovery: new \Pinto\DefinitionDiscovery());
}

public function testSlotsExplicitIgnoresReflection(): void
{
$object = new Pinto\tests\fixtures\Objects\Slots\PintoObjectSlotsExplicitIgnoresReflection('Should be ignored', 999);
$object = new fixtures\Objects\Slots\PintoObjectSlotsExplicitIgnoresReflection('Should be ignored', 999);
$build = $object();
static::assertInstanceOf(Slots\Build::class, $build);
static::assertEquals('Some text', $build->pintoGet('text'));
Expand All @@ -152,7 +154,7 @@ public function testSlotsExplicitIgnoresReflection(): void
public function testSlotsBuildMissingValue(): void
{
$object = new PintoObjectSlotsMissingSlotValue('Foo!', 12345);
static::expectException(Pinto\Exception\Slots\BuildValidation::class);
static::expectException(\Pinto\Exception\Slots\BuildValidation::class);
static::expectExceptionMessage(sprintf('Build for %s missing values for slot: `number', PintoObjectSlotsMissingSlotValue::class));
$object();
}
Expand All @@ -162,18 +164,18 @@ public function testSlotsBuildMissingValue(): void
*
* Issue would normally expose itself during discovery.
*
* @see Pinto\Attribute\ObjectType\Slots::getDefinition
* @see \Pinto\Attribute\ObjectType\Slots::getDefinition
*/
public function testSlotsNoConstructor(): void
{
$definitions = PintoListSlots::definitions(new Pinto\DefinitionDiscovery());
$definitions = PintoListSlots::definitions(new \Pinto\DefinitionDiscovery());
// Assert anything (no exception thrown):
static::assertGreaterThan(0, count($definitions));
}

public function testSlotsBuildMissingValueWithDefault(): void
{
$object = new Pinto\tests\fixtures\Objects\Slots\PintoObjectSlotsMissingSlotValueWithDefault('Foo!');
$object = new fixtures\Objects\Slots\PintoObjectSlotsMissingSlotValueWithDefault('Foo!');
$build = $object();
static::assertInstanceOf(Slots\Build::class, $build);
static::assertEquals('Foo!', $build->pintoGet('text'));
Expand All @@ -183,7 +185,7 @@ public function testSlotsBuildMissingValueWithDefault(): void

public function testDefinitionsSlotsAttrOnObject(): void
{
$themeDefinitions = PintoListSlots::definitions(new Pinto\DefinitionDiscovery());
$themeDefinitions = PintoListSlots::definitions(new \Pinto\DefinitionDiscovery());
static::assertCount(8, $themeDefinitions);

$slotsDefinition = $themeDefinitions[PintoListSlots::Slots];
Expand All @@ -203,7 +205,7 @@ public function testDefinitionsSlotsAttrOnObject(): void

public function testDefinitionsSlotsAttrOnList(): void
{
$themeDefinitions = Lists\PintoListSlotsOnEnum::definitions(new Pinto\DefinitionDiscovery());
$themeDefinitions = Lists\PintoListSlotsOnEnum::definitions(new \Pinto\DefinitionDiscovery());
static::assertCount(1, $themeDefinitions);

$slotsDefinition = $themeDefinitions[Lists\PintoListSlotsOnEnum::SlotsOnEnum];
Expand All @@ -216,7 +218,7 @@ public function testDefinitionsSlotsAttrOnList(): void

public function testDefinitionsSlotsAttrOnListCase(): void
{
$themeDefinitions = Lists\PintoListSlotsOnEnumCase::definitions(new Pinto\DefinitionDiscovery());
$themeDefinitions = Lists\PintoListSlotsOnEnumCase::definitions(new \Pinto\DefinitionDiscovery());
static::assertCount(1, $themeDefinitions);

$slotsDefinition = $themeDefinitions[Lists\PintoListSlotsOnEnumCase::SlotsOnEnumCase];
Expand All @@ -228,7 +230,7 @@ public function testDefinitionsSlotsAttrOnListCase(): void

public function testDefinitionsSlotsAttrByInheritance(): void
{
$definitionDiscovery = new Pinto\DefinitionDiscovery();
$definitionDiscovery = new \Pinto\DefinitionDiscovery();
$definitionDiscovery[PintoObjectSlotsByInheritanceChild::class] = Lists\PintoListSlotsByInheritance::SlotsByInheritanceChild;
$definitionDiscovery[PintoObjectSlotsByInheritanceGrandParent::class] = Lists\PintoListSlotsByInheritance::SlotsByInheritanceGrandParent;
$themeDefinitions = Lists\PintoListSlotsByInheritance::definitions($definitionDiscovery);
Expand All @@ -246,7 +248,7 @@ public function testDefinitionsSlotsAttrByInheritance(): void
*/
public function testModifySlotsAttributeNamedParameters(): void
{
static::expectException(LogicException::class);
static::expectException(\LogicException::class);
static::expectExceptionMessage('Using this attribute without named parameters is not supported.');
new Slots\Attribute\ModifySlots('');
}
Expand All @@ -256,14 +258,14 @@ public function testModifySlotsAttributeNamedParameters(): void
*/
public function testModifySlotsAttributeAddMissingSlots(): void
{
static::expectException(LogicException::class);
static::expectException(\LogicException::class);
static::expectExceptionMessage('Slots must be added.');
new Slots\Attribute\ModifySlots(add: []);
}

public function testDefinitionsSlotsAttrByInheritanceModifiedSlots(): void
{
$definitionDiscovery = new Pinto\DefinitionDiscovery();
$definitionDiscovery = new \Pinto\DefinitionDiscovery();
$definitionDiscovery[PintoObjectSlotsByInheritanceChild::class] = Lists\PintoListSlotsByInheritance::SlotsByInheritanceChild;
$definitionDiscovery[PintoObjectSlotsByInheritanceChildModifySlots::class] = Lists\PintoListSlotsByInheritance::PintoObjectSlotsByInheritanceChildModifySlots;
$definitionDiscovery[PintoObjectSlotsByInheritanceGrandParent::class] = Lists\PintoListSlotsByInheritance::SlotsByInheritanceGrandParent;
Expand All @@ -281,17 +283,17 @@ public function testDefinitionsSlotsAttrByInheritanceModifiedSlots(): void
public function testDefinitionsSlotsAttrByInheritanceGrandParentUnregistered(): void
{
// It the parent isn't registered to an enum, no object type is determined.
$definitionDiscovery = new Pinto\DefinitionDiscovery();
$definitionDiscovery = new \Pinto\DefinitionDiscovery();
// Normally parent is set here.
$definitionDiscovery[PintoObjectSlotsByInheritanceChild::class] = Lists\PintoListSlotsByInheritance::SlotsByInheritanceChild;

static::expectException(Pinto\Exception\PintoIndeterminableObjectType::class);
static::expectException(\Pinto\Exception\PintoIndeterminableObjectType::class);
Lists\PintoListSlotsByInheritance::definitions($definitionDiscovery);
}

public function testDefinitionsSlotsAttrOnListMethodSpecified(): void
{
$themeDefinitions = Lists\PintoListSlotsOnEnumMethodSpecified::definitions(new Pinto\DefinitionDiscovery());
$themeDefinitions = Lists\PintoListSlotsOnEnumMethodSpecified::definitions(new \Pinto\DefinitionDiscovery());
static::assertCount(1, $themeDefinitions);

$slotsDefinition = $themeDefinitions[Lists\PintoListSlotsOnEnumMethodSpecified::SlotsOnEnumMethodSpecified];
Expand All @@ -303,7 +305,7 @@ public function testDefinitionsSlotsAttrOnListMethodSpecified(): void

public function testSlotAttribute(): void
{
$attr = new Pinto\Attribute\ObjectType\Slots(slots: [
$attr = new \Pinto\Attribute\ObjectType\Slots(slots: [
new Slots\Slot(name: 'foo'),
'bar',
]);
Expand All @@ -316,16 +318,16 @@ public function testSlotAttribute(): void

public function testSlotNamedParameters(): void
{
static::expectException(LogicException::class);
static::expectException(\LogicException::class);
static::expectExceptionMessage('Using this attribute without named parameters is not supported.');
new Slots\Slot('slotname', '', 'defaultvalue');
}

public function testSlotAttributeNamedParameters(): void
{
static::expectException(LogicException::class);
static::expectException(\LogicException::class);
static::expectExceptionMessage('Using this attribute without named parameters is not supported.');
new Pinto\Attribute\ObjectType\Slots('');
new \Pinto\Attribute\ObjectType\Slots('');
}

/**
Expand All @@ -334,7 +336,7 @@ public function testSlotAttributeNamedParameters(): void
*/
public function testRenameSlots(): void
{
$definitionDiscovery = new Pinto\DefinitionDiscovery();
$definitionDiscovery = new \Pinto\DefinitionDiscovery();
$definitionDiscovery[PintoObjectSlotsRenameParent::class] = Lists\PintoListSlotsRename::SlotsRenameParent;
$definitionDiscovery[PintoObjectSlotsRenameChild::class] = Lists\PintoListSlotsRename::SlotsRenameChild;
$themeDefinitions = Lists\PintoListSlotsRename::definitions($definitionDiscovery);
Expand Down
Loading