Skip to content

Commit c77b048

Browse files
committed
sigh.
1 parent 1db4e73 commit c77b048

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/ACL/ACLAuthMethodListEntryQueryResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function getValue(): array
3838

3939
public function unmarshalValue(mixed $decoded): void
4040
{
41+
$this->ACLAuthMethodListEntries = [];
4142
if (!is_array($decoded)) {
4243
return;
4344
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace DCarbone\PHPConsulAPITests\Unit\ACL;
4+
5+
use DCarbone\PHPConsulAPI\ACL\ACLAuthMethodListEntry;
6+
use DCarbone\PHPConsulAPI\ACL\ACLAuthMethodListEntryQueryResponse;
7+
use PHPUnit\Framework\TestCase;
8+
9+
/**
10+
* @internal
11+
*/
12+
final class ACLAuthMethodListEntryQueryResponseTest extends TestCase
13+
{
14+
public function testUnmarshalValueResetsStateOnInvalidDecodedValue(): void
15+
{
16+
$entry = new \stdClass();
17+
$entry->Name = 'method-1';
18+
$entry->Type = 'jwt';
19+
$entry->DisplayName = 'Method One';
20+
$entry->Description = '';
21+
$entry->MaxTokenTTL = '0s';
22+
$entry->TokenLocality = 'local';
23+
$entry->CreateIndex = 1;
24+
$entry->ModifyIndex = 1;
25+
$entry->Namespace = '';
26+
$entry->Partition = '';
27+
28+
$resp = new ACLAuthMethodListEntryQueryResponse();
29+
$resp->unmarshalValue([$entry]);
30+
self::assertCount(1, $resp->getValue());
31+
self::assertInstanceOf(ACLAuthMethodListEntry::class, $resp->getValue()[0]);
32+
33+
$resp->unmarshalValue(null);
34+
self::assertSame([], $resp->getValue());
35+
}
36+
}
37+

0 commit comments

Comments
 (0)