Skip to content

Commit

Permalink
Fix HasHref::class (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Aug 28, 2023
1 parent 0aa43e3 commit 4ee042f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
34 changes: 0 additions & 34 deletions src/Attribute/Tag/HasHref.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

namespace PHPForge\Html\Attribute\Tag;

use PHPForge\Html\Helper\CssClass;

/**
* Is used by widgets that implement the href method.
*/
trait HasHref
{
protected array $hrefAttributes = [];

/**
* Set the URL that the hyperlink points to.
*
Expand All @@ -31,34 +27,4 @@ public function href(string $value): static

return $new;
}

/**
* Set the `HTML` attributes.
*
* @param array $values Attribute values indexed by attribute names.
*
* @return static A new instance of the current class with the specified href attributes.
*/
public function hrefAttributes(array $values): static
{
$new = clone $this;
$new->hrefAttributes = array_merge($this->hrefAttributes, $values);

return $new;
}

/**
* Set the `CSS` class.
*
* @param string $value The `CSS` class.
*
* @return static A new instance of the current class with the specified href class.
*/
public function hrefClass(string $value): static
{
$new = clone $this;
CssClass::add($new->hrefAttributes, $value);

return $new;
}
}
33 changes: 0 additions & 33 deletions tests/Attribute/Tag/HasHrefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,6 @@

final class HasHrefTest extends TestCase
{
public function testAttributes(): void
{
$instance = new class() {
use HasHref;

public function getHrefAttributes(): array
{
return $this->hrefAttributes;
}
};

$instance = $instance->hrefAttributes(['class' => 'foo']);
$instance = $instance->hrefAttributes(['disabled' => true]);

$this->assertSame(['class' => 'foo', 'disabled' => true], $instance->getHrefAttributes());
}

public function testClass(): void
{
$instance = new class() {
use HasHref;

public function getHrefAttributes(): array
{
return $this->hrefAttributes;
}
};

$this->assertSame(['class' => 'test-class'], $instance->hrefClass('test-class')->getHrefAttributes());
}

public function testImmutablity(): void
{
$instance = new class() {
Expand All @@ -49,7 +18,5 @@ public function testImmutablity(): void
};

$this->assertNotSame($instance, $instance->href(''));
$this->assertNotSame($instance, $instance->hrefAttributes([]));
$this->assertNotSame($instance, $instance->hrefClass(''));
}
}

0 comments on commit 4ee042f

Please sign in to comment.