Skip to content

Commit

Permalink
Kill mutants.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Mar 22, 2024
1 parent 1f2759d commit 582b870
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 38 deletions.
43 changes: 5 additions & 38 deletions src/Base/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Html\Concern\HasPrefixCollection,
Html\Concern\HasSuffixCollection,
Html\Concern\HasTemplate,
Html\Field\Concern\CanBeEnclosedByLabel,
Html\Field\Concern\HasClass,
Html\Field\Concern\HasError,
Html\Field\Concern\HasHint,
Html\Field\Concern\HasInputContainer,
Expand Down Expand Up @@ -55,7 +57,9 @@
*/
abstract class AbstractField extends Element
{
use CanBeEnclosedByLabel;
use HasAttributes;
use HasClass;
use HasContainerCollection;
use HasError;
use HasHint;
Expand All @@ -71,9 +75,6 @@ abstract class AbstractField extends Element
use HasValue;

protected array $attributes = [];
protected string $class = '';
protected bool $classOverride = false;
protected bool $enclosedByLabel = false;
private InputInterface $widget;

/**
Expand All @@ -94,40 +95,6 @@ public function __construct(
parent::__construct($definitions);
}

/**
* Set the `CSS` `HTML` field class attribute.
*
* @param string $value The `CSS` attribute of the widget.
* @param bool $override If `true` the value will be overridden.
*
* @return static A new instance of the current class with the specified class value.
*
* @link https://html.spec.whatwg.org/#classes
*/
public function class(string $value, bool $override = false): static
{
$new = clone $this;
$new->class = $value;
$new->classOverride = $override;

return $new;
}

/**
* Set the current instance as being enclosed by a label.
*
* @param bool $value The value to set.
*
* @return self A new instance of of the current class with the specified enclosed by label property.
*/
public function enclosedByLabel(bool $value): self
{
$new = clone $this;
$new->enclosedByLabel = $value;

return $new;
}

public function input(InputInterface $widget): self
{
/** @psalm-var array<string, mixed> $definitionProperty */
Expand Down Expand Up @@ -306,7 +273,7 @@ private function renderField(InputInterface $widget): string
);
}

public function renderHintTag(): string
private function renderHintTag(): string
{
return $this->renderTag($this->hintAttributes, $this->hintContent, $this->hintTag, $this->hintId);
}
Expand Down
26 changes: 26 additions & 0 deletions src/Concern/CanBeEnclosedByLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace UIAwesome\Html\Field\Concern;

/**
* Provides methods for configuring enclosing field by label.
*/
trait CanBeEnclosedByLabel
{
protected bool $enclosedByLabel = false;

/**
* Set the current instance as being enclosed by a label.
*
* @return self A new instance of of the current class with the specified enclosed by label property.
*/
public function enclosedByLabel(): self
{
$new = clone $this;
$new->enclosedByLabel = true;

return $new;
}
}
33 changes: 33 additions & 0 deletions src/Concern/HasClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace UIAwesome\Html\Field\Concern;

/**
* Provides methods for configuring field input class.
*/
trait HasClass
{
protected string $class = '';
protected bool $classOverride = false;

/**
* Set the `CSS` `HTML` field class attribute.
*
* @param string $value The `CSS` attribute of the widget.
* @param bool $override If `true` the value will be overridden.
*
* @return static A new instance of the current class with the specified class value.
*
* @link https://html.spec.whatwg.org/#classes
*/
public function class(string $value, bool $override = false): static
{
$new = clone $this;
$new->class = $value;
$new->classOverride = $override;

return $new;
}
}
19 changes: 19 additions & 0 deletions tests/Concern/CanBeEnclosedByLabelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace UIAwesome\Html\Field\Tests\Concern;

use UIAwesome\Html\Field\Concern\CanBeEnclosedByLabel;

final class CanBeEnclosedByLabelTest extends \PHPUnit\Framework\TestCase
{
public function testImmutability(): void
{
$instance = new class () {
use CanBeEnclosedByLabel;
};

$this->assertNotSame($instance, $instance->enclosedByLabel());
}
}
19 changes: 19 additions & 0 deletions tests/Concern/HasClassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace UIAwesome\Html\Field\Tests\Concern;

use UIAwesome\Html\Field\Concern\HasClass;

final class HasClassTest extends \PHPUnit\Framework\TestCase
{
public function testImmutability(): void
{
$instance = new class () {
use HasClass;
};

$this->assertNotSame($instance, $instance->class(''));
}
}
13 changes: 13 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ public function testRender(): void
Field::widget(new ConfigForm(), 'name')->render()
);
}

public function testRenderWithDefinitions(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div>
<label for="custom-id">Name</label>
<input class="custom-class form-control" id="custom-id" name="ConfigForm[name]" type="text">
</div>
HTML,
Field::widget(new ConfigForm(), 'name', ['id()' => ['custom-id']])->render()
);
}
}

0 comments on commit 582b870

Please sign in to comment.