Skip to content

Commit

Permalink
Add getContainerId method. (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 22, 2023
1 parent 1dd1c0e commit 2b8183a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Attribute/Custom/HasContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,15 @@ public function containerTag(string $value): static

return $new;
}

public function getContainerId(): string|null
{
$id = null;

if (array_key_exists('id', $this->containerAttributes)) {
$id = (string) $this->containerAttributes['id'];

Check warning on line 89 in src/Attribute/Custom/HasContainer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $id = null; if (array_key_exists('id', $this->containerAttributes)) { - $id = (string) $this->containerAttributes['id']; + $id = $this->containerAttributes['id']; } return $id; } }
}

return $id;
}
}
16 changes: 16 additions & 0 deletions tests/Attribute/Custom/HasContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ public function testException(): void
$instance->containerTag('');
}

public function testContainerGetId(): void
{
$instance = new class () {
use HasContainer;

protected bool $container = true;
protected string $containerTag = 'div';
};

$this->assertNull($instance->getContainerId());

$instance = $instance->containerAttributes(['id' => 'test-id']);

$this->assertSame('test-id', $instance->getContainerId());
}

public function testImmutability(): void
{
$instance = new class () {
Expand Down

0 comments on commit 2b8183a

Please sign in to comment.