Skip to content

Commit

Permalink
Prepare first release. (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Feb 23, 2024
1 parent e571bd6 commit 1cbbbcc
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 18 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
Change Log
==========

## 0.1.0 February 23, 2024

- Initial release.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"html",
"php"
],
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1",
"ext-dom": "*",
Expand All @@ -26,7 +24,7 @@
"phpunit/phpunit": "^10.5",
"roave/infection-static-analysis-plugin": "^1.34",
"symplify/easy-coding-standard": "^12.1",
"vimeo/psalm": "^5.20"
"vimeo/psalm": "^5.22"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 6 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"PHPForge\\Html\\Attribute\\Input\\HasSrc::src",
"PHPForge\\Html\\Attribute\\Input\\HasValue::value"
]
},
"TrueValue": {
"ignore": [
"PHPForge\\Html\\Attribute\\Custom\\HasPrefixCollection::renderPrefixTag",
"PHPForge\\Html\\Attribute\\Custom\\HasSuffixCollection::renderSuffixTag"
]
}
}
}
2 changes: 1 addition & 1 deletion src/Attribute/Custom/HasPrefixCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function renderPrefixTag(): string
->content($this->prefix)
->tagName($this->prefixContainerTag)
->render(),
default => $this->prefix,
false => $this->prefix,
};
}
}
10 changes: 8 additions & 2 deletions src/Helper/CssClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ final class CssClass
* effect.
*
* @param array $attributes The attributes to be modified.
* @param string|string[] $class The CSS class(es) to be added.
* @param array|string $class The CSS class(es) to be added.
* @param bool $override Whether to override existing CSS class(es) with new one.
*
* @psalm-param string|string[] $class
*/
public static function add(array &$attributes, array|string $class, bool $override = false): void
{
Expand All @@ -46,7 +48,11 @@ public static function add(array &$attributes, array|string $class, bool $overri
/** @psalm-var string[] $existingClasses */
$existingClasses = is_array($attributes['class'])
? $attributes['class']
: preg_split('/\s+/', (string) $attributes['class'], flags: PREG_SPLIT_NO_EMPTY);
: preg_split(
'/\s+/',
is_string($attributes['class']) ? $attributes['class'] : '',
flags: PREG_SPLIT_NO_EMPTY
);

$newClasses = is_array($class)
? $class
Expand Down
28 changes: 22 additions & 6 deletions tests/Attribute/Custom/HasPrefixCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,40 @@ public function testRender(): void
$instance = new class () {
use HasPrefixCollection;

public function getPrefix(): string
public function run(): string
{
return $this->prefix;
return $this->renderPrefixTag();
}
};

$instance = $instance->prefix('prefix')->prefixContainer(false);

Assert::equalsWithoutLE(
<<<HTML
prefix
HTML,
$instance->run()
);
}

public function testRenderWithContainerTrue(): void
{
$instance = new class () {
use HasPrefixCollection;

public function run(): string
{
return $this->renderPrefixTag();
}
};

$instance = $instance->prefix(Span::widget(), 'prefix');

$this->assertSame('<span></span>prefix', $instance->getPrefix());
$instance = $instance->prefix('prefix')->prefixContainer(true);

Assert::equalsWithoutLE(
<<<HTML
<span></span>prefix
<div>
prefix
</div>
HTML,
$instance->run()
);
Expand Down
30 changes: 24 additions & 6 deletions tests/Attribute/Custom/HasSuffixCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,42 @@ public function testRender(): void
$instance = new class () {
use HasSuffixCollection;

public function getSuffix(): string
public function run(): string
{
return $this->suffix;
return $this->renderSuffixTag();
}
};

$instance = $instance->suffix('suffix')->suffixContainer(false);

$this->assertStringNotContainsString('<div>', $instance->run());
Assert::equalsWithoutLE(
<<<HTML
suffix
HTML,
$instance->run()
);
}

public function testRenderWithContainerTrue(): void
{
$instance = new class () {
use HasSuffixCollection;

public function run(): string
{
return $this->renderSuffixTag();
}
};

$instance = $instance->suffix('suffix', Span::widget());

$this->assertSame('suffix<span></span>', $instance->getSuffix());
$instance = $instance->suffix('suffix')->suffixContainer(true);

$this->assertStringContainsString('<div>', $instance->run());
Assert::equalsWithoutLE(
<<<HTML
suffix<span></span>
<div>
suffix
</div>
HTML,
$instance->run()
);
Expand Down

0 comments on commit 1cbbbcc

Please sign in to comment.