Skip to content

Commit 030a660

Browse files
committed
wip
1 parent 25a1225 commit 030a660

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/Contract/HasIdentifiersInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface HasIdentifiersInterface extends HasPropertiesInterface
99
public function addIdentifier(string $identifier): self;
1010

1111
/**
12-
* @param string[] $identifiers
12+
* @param iterable<string> $identifiers
1313
*/
1414
public function addIdentifiers(iterable $identifiers): self;
1515

tests/Trait/IdentifiersTraitTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,44 @@ public function testAddIdentifierWithoutProperty(): void
9191
$this->expectException(InvalidArgumentException::class);
9292
$trait->addIdentifier('someProperty');
9393
}
94+
95+
public function testProperties(): void
96+
{
97+
$trait = $this->getTrait();
98+
$trait->addProperty('someProperty', 'some value');
99+
$this->assertCount(1, $trait->getProperties());
100+
$this->assertTrue($trait->hasProperty('someProperty'));
101+
$this->assertFalse($trait->hasProperty('notExistingProperty'));
102+
$this->assertSame('some value', $trait->getProperty('someProperty'));
103+
104+
$trait->addProperties([
105+
'otherProperty' => 'other value',
106+
'anotherProperty' => 'another value',
107+
]);
108+
$this->assertCount(3, $trait->getProperties());
109+
$trait->removeProperty('otherProperty');
110+
$this->assertCount(2, $trait->getProperties());
111+
$trait->removeProperties();
112+
$this->assertCount(0, $trait->getProperties());
113+
}
114+
115+
public function testRemovePropertyWhichIsAlsoIdentifier(): void
116+
{
117+
$trait = $this->getTrait()
118+
->addProperty('id', 123)
119+
->addIdentifier('id');
120+
$this->expectExceptionMessage("Unable to remove identifying property with name 'id' - remove identifier first");
121+
$this->expectException(InvalidArgumentException::class);
122+
$trait->removeProperty('id');
123+
}
124+
125+
public function testRemovePropertiesWithExistingIdentifier(): void
126+
{
127+
$trait = $this->getTrait()
128+
->addProperty('id', 123)
129+
->addIdentifier('id');
130+
$this->expectExceptionMessage("Unable to remove all properties because identifiers are still defined");
131+
$this->expectException(InvalidArgumentException::class);
132+
$trait->removeProperties();
133+
}
94134
}

0 commit comments

Comments
 (0)