Skip to content

Commit

Permalink
Fix id in AbstractElement::class. (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 3, 2023
1 parent ff12ebe commit e36cc6e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[*.xml]
indent_size = 2
7 changes: 5 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
Expand Down
5 changes: 4 additions & 1 deletion src/Base/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ abstract class AbstractElement extends Element
protected function run(): string
{
$attributes = $this->attributes;
$attributes['id'] = $this->id;

if (array_key_exists('id', $attributes) === false) {
$attributes['id'] = $this->id;
}

/** @var string|null $type */
$type = $this->attributes['type'] ?? null;
Expand Down
20 changes: 18 additions & 2 deletions tests/Input/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function testAriaLabel(): void
public function testAttributes(): void
{
$this->assertSame(
'<input class="test-class">',
Input::widget()->attributes(['class' => 'test-class'])->render(),
'<input class="test-class" id="test-id">',
Input::widget()->attributes(['class' => 'test-class', 'id' => 'test-id'])->render(),
);
}

Expand Down Expand Up @@ -181,4 +181,20 @@ public function testType(): void
Input::widget()->type('radio')->render(),
);
}

public function testValue(): void
{
$this->assertSame(
'<input value="test-value">',
Input::widget()->value('test-value')->render(),
);
}

public function testValueEmpty(): void
{
$this->assertSame(
'<input>',
Input::widget()->value('')->render(),
);
}
}

0 comments on commit e36cc6e

Please sign in to comment.