diff --git a/CHANGELOG.md b/CHANGELOG.md index 02acf384..7e291fb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - New #260: Add `$attributes` parameter to `Html::li()` method (@gauravkumar2525) - Enh #261: Enhance `RadioList::addRadioWrapClass()` method for cleaner class addition (@vjik) - Enh #263: Explicitly import classes and constants in "use" section (@mspirkov) +- Chg #243: Deprecate static constructors such as `TagName::tag()` in favor of `new TagName()` (@razvbir) ## 3.12.0 December 13, 2025 diff --git a/README.md b/README.md index 1ff9daaf..bcf73c33 100644 --- a/README.md +++ b/README.md @@ -85,9 +85,9 @@ Tag classes allow working with a tag as an object and then get an HTML code by u to string. For example, the following code: ```php -echo \Yiisoft\Html\Tag\Div::tag() +echo new \Yiisoft\Html\Tag\Div() ->content( - \Yiisoft\Html\Tag\A::tag() + new \Yiisoft\Html\Tag\A() ->mailto('info@example.com') ->content('contact us') ->render() @@ -108,7 +108,7 @@ echo \Yiisoft\Html\Tag\Div::tag() To generate custom tags, use the `CustomTag` class. For example, the following code: ```php -echo \Yiisoft\Html\Tag\CustomTag::name('b') +echo new \Yiisoft\Html\Tag\CustomTag('b') ->content('text') ->attribute('title', 'Important'); ``` @@ -166,7 +166,7 @@ complex HTML in simple PHP. Represents a group of buttons. ```php -echo \Yiisoft\Html\Widget\ButtonGroup::create() +echo new \Yiisoft\Html\Widget\ButtonGroup() ->buttons( \Yiisoft\Html\Html::resetButton('Reset Data'), \Yiisoft\Html\Html::resetButton('Send'), @@ -189,7 +189,7 @@ Result will be: Represents a list of checkboxes. ```php -echo \Yiisoft\Html\Widget\CheckboxList\CheckboxList::create('count') +echo new \Yiisoft\Html\Widget\CheckboxList\CheckboxList('count') ->items([1 => 'One', 2 => 'Two', 5 => 'Five']) ->uncheckValue(0) ->value(2, 5) @@ -212,7 +212,7 @@ Result will be: Represents a list of radio buttons. ```php -echo \Yiisoft\Html\Widget\RadioList\RadioList::create('count') +echo new \Yiisoft\Html\Widget\RadioList\RadioList('count') ->items([1 => 'One', 2 => 'Two', 5 => 'Five']) ->uncheckValue(0) ->value(2) diff --git a/src/Html.php b/src/Html.php index c14daf29..a1393ae7 100644 --- a/src/Html.php +++ b/src/Html.php @@ -307,7 +307,7 @@ public static function escapeJavaScriptStringValue(mixed $value): string */ public static function tag(string $name, string|Stringable $content = '', array $attributes = []): CustomTag { - $tag = CustomTag::name($name); + $tag = new CustomTag($name); if ($content !== '') { $tag = $tag->content($content); } @@ -330,7 +330,7 @@ public static function tag(string $name, string|Stringable $content = '', array */ public static function normalTag(string $name, string|Stringable $content = '', array $attributes = []): CustomTag { - $tag = CustomTag::name($name)->normal(); + $tag = (new CustomTag($name))->normal(); if ($content !== '') { $tag = $tag->content($content); } @@ -352,7 +352,7 @@ public static function normalTag(string $name, string|Stringable $content = '', */ public static function voidTag(string $name, array $attributes = []): CustomTag { - $tag = CustomTag::name($name)->void(); + $tag = (new CustomTag($name))->void(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -392,7 +392,7 @@ public static function closeTag(string $name): string */ public static function style(string $content = '', array $attributes = []): Style { - $tag = Style::tag(); + $tag = new Style(); if ($content !== '') { $tag = $tag->content($content); } @@ -410,7 +410,7 @@ public static function style(string $content = '', array $attributes = []): Styl */ public static function script(string $content = '', array $attributes = []): Script { - $tag = Script::tag(); + $tag = new Script(); if ($content !== '') { $tag = $tag->content($content); } @@ -427,7 +427,7 @@ public static function script(string $content = '', array $attributes = []): Scr */ public static function noscript(string|Stringable $content = ''): Noscript { - $tag = Noscript::tag(); + $tag = new Noscript(); return $content === '' ? $tag : $tag->content($content); } @@ -439,7 +439,7 @@ public static function noscript(string|Stringable $content = ''): Noscript */ public static function title(string|Stringable $content = '', array $attributes = []): Title { - $tag = Title::tag(); + $tag = new Title(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -453,7 +453,7 @@ public static function title(string|Stringable $content = '', array $attributes */ public static function meta(array $attributes = []): Meta { - $tag = Meta::tag(); + $tag = new Meta(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -468,7 +468,7 @@ public static function meta(array $attributes = []): Meta */ public static function link(?string $url = null, array $attributes = []): Link { - $tag = Link::tag(); + $tag = new Link(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -501,7 +501,7 @@ public static function cssFile(string $url, array $attributes = []): Link */ public static function javaScriptFile(string $url, array $attributes = []): Script { - $tag = Script::tag()->url($url); + $tag = (new Script())->url($url); if (!empty($attributes)) { $tag = $tag->addAttributes($attributes); } @@ -518,7 +518,7 @@ public static function javaScriptFile(string $url, array $attributes = []): Scri */ public static function a(string|Stringable $content = '', ?string $url = null, array $attributes = []): A { - $tag = A::tag(); + $tag = new A(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -540,7 +540,7 @@ public static function a(string|Stringable $content = '', ?string $url = null, a */ public static function mailto(string $content, ?string $mail = null, array $attributes = []): A { - $tag = A::tag() + $tag = (new A()) ->content($content) ->mailto($mail ?? $content); if (!empty($attributes)) { @@ -558,7 +558,7 @@ public static function mailto(string $content, ?string $mail = null, array $attr */ public static function img(?string $url = null, ?string $alt = '', array $attributes = []): Img { - $tag = Img::tag(); + $tag = new Img(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -578,7 +578,7 @@ public static function img(?string $url = null, ?string $alt = '', array $attrib */ public static function fieldset(array $attributes = []): Fieldset { - $tag = Fieldset::tag(); + $tag = new Fieldset(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -594,7 +594,7 @@ public static function fieldset(array $attributes = []): Fieldset */ public static function form(?string $action = null, ?string $method = null, array $attributes = []): Form { - $tag = Form::tag(); + $tag = new Form(); if ($action !== null) { $attributes['action'] = $action; } @@ -616,7 +616,7 @@ public static function form(?string $action = null, ?string $method = null, arra */ public static function label(string|Stringable $content = '', ?string $for = null): Label { - $tag = Label::tag(); + $tag = new Label(); if ($for !== null) { $tag = $tag->forId($for); } @@ -634,7 +634,7 @@ public static function label(string|Stringable $content = '', ?string $for = nul */ public static function legend(string|Stringable $content = '', array $attributes = []): Legend { - $tag = Legend::tag(); + $tag = new Legend(); if ($content !== '') { $tag = $tag->content($content); } @@ -710,7 +710,7 @@ public static function input( bool|float|int|string|Stringable|null $value = null, array $attributes = [], ): Input { - $tag = Input::tag()->type($type); + $tag = (new Input())->type($type); if ($name !== null) { $tag = $tag->name($name); } @@ -929,7 +929,7 @@ public static function checkbox( */ public static function textarea(?string $name = null, string|Stringable|array|null $value = null, array $attributes = []): Textarea { - $tag = Textarea::tag(); + $tag = new Textarea(); if ($name !== null) { $tag = $tag->name($name); } @@ -946,7 +946,7 @@ public static function textarea(?string $name = null, string|Stringable|array|nu */ public static function select(?string $name = null): Select { - $tag = Select::tag(); + $tag = new Select(); if ($name !== null) { $tag = $tag->name($name); } @@ -958,7 +958,7 @@ public static function select(?string $name = null): Select */ public static function optgroup(): Optgroup { - return Optgroup::tag(); + return new Optgroup(); } /** @@ -971,7 +971,7 @@ public static function option( string|Stringable $content = '', bool|float|int|string|Stringable|null $value = null, ): Option { - $tag = Option::tag(); + $tag = new Option(); if ($content !== '') { $tag = $tag->content($content); } @@ -988,7 +988,7 @@ public static function option( */ public static function checkboxList(string $name): CheckboxList { - return CheckboxList::create($name); + return new CheckboxList($name); } /** @@ -998,7 +998,7 @@ public static function checkboxList(string $name): CheckboxList */ public static function radioList(string $name): RadioList { - return RadioList::create($name); + return new RadioList($name); } /** @@ -1009,7 +1009,7 @@ public static function radioList(string $name): RadioList */ public static function div(string|Stringable $content = '', array $attributes = []): Div { - $tag = Div::tag(); + $tag = new Div(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1026,7 +1026,7 @@ public static function div(string|Stringable $content = '', array $attributes = */ public static function code(string|Stringable $content = '', array $attributes = []): Code { - $tag = Code::tag(); + $tag = new Code(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1043,7 +1043,7 @@ public static function code(string|Stringable $content = '', array $attributes = */ public static function pre(string|Stringable $content = '', array $attributes = []): Pre { - $tag = Pre::tag(); + $tag = new Pre(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1058,7 +1058,7 @@ public static function pre(string|Stringable $content = '', array $attributes = */ public static function span(string|Stringable $content = '', array $attributes = []): Span { - $tag = Span::tag(); + $tag = new Span(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1073,7 +1073,7 @@ public static function span(string|Stringable $content = '', array $attributes = */ public static function em(string|Stringable $content = '', array $attributes = []): Em { - $tag = Em::tag(); + $tag = new Em(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1088,7 +1088,7 @@ public static function em(string|Stringable $content = '', array $attributes = [ */ public static function strong(string|Stringable $content = '', array $attributes = []): Strong { - $tag = Strong::tag(); + $tag = new Strong(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1103,7 +1103,7 @@ public static function strong(string|Stringable $content = '', array $attributes */ public static function small(string|Stringable $content = '', array $attributes = []): Small { - $tag = Small::tag(); + $tag = new Small(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1118,7 +1118,7 @@ public static function small(string|Stringable $content = '', array $attributes */ public static function b(string|Stringable $content = '', array $attributes = []): B { - $tag = B::tag(); + $tag = new B(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1133,7 +1133,7 @@ public static function b(string|Stringable $content = '', array $attributes = [] */ public static function i(string|Stringable $content = '', array $attributes = []): I { - $tag = I::tag(); + $tag = new I(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1148,7 +1148,7 @@ public static function i(string|Stringable $content = '', array $attributes = [] */ public static function h1(string|Stringable $content = '', array $attributes = []): H1 { - $tag = H1::tag(); + $tag = new H1(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1163,7 +1163,7 @@ public static function h1(string|Stringable $content = '', array $attributes = [ */ public static function h2(string|Stringable $content = '', array $attributes = []): H2 { - $tag = H2::tag(); + $tag = new H2(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1178,7 +1178,7 @@ public static function h2(string|Stringable $content = '', array $attributes = [ */ public static function h3(string|Stringable $content = '', array $attributes = []): H3 { - $tag = H3::tag(); + $tag = new H3(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1193,7 +1193,7 @@ public static function h3(string|Stringable $content = '', array $attributes = [ */ public static function h4(string|Stringable $content = '', array $attributes = []): H4 { - $tag = H4::tag(); + $tag = new H4(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1208,7 +1208,7 @@ public static function h4(string|Stringable $content = '', array $attributes = [ */ public static function h5(string|Stringable $content = '', array $attributes = []): H5 { - $tag = H5::tag(); + $tag = new H5(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1223,7 +1223,7 @@ public static function h5(string|Stringable $content = '', array $attributes = [ */ public static function h6(string|Stringable $content = '', array $attributes = []): H6 { - $tag = H6::tag(); + $tag = new H6(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1238,7 +1238,7 @@ public static function h6(string|Stringable $content = '', array $attributes = [ */ public static function p(string|Stringable $content = '', array $attributes = []): P { - $tag = P::tag(); + $tag = new P(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1252,7 +1252,7 @@ public static function p(string|Stringable $content = '', array $attributes = [] */ public static function ul(array $attributes = []): Ul { - $tag = Ul::tag(); + $tag = new Ul(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1266,7 +1266,7 @@ public static function ul(array $attributes = []): Ul */ public static function ol(array $attributes = []): Ol { - $tag = Ol::tag(); + $tag = new Ol(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1281,7 +1281,7 @@ public static function ol(array $attributes = []): Ol */ public static function li(string|Stringable $content = '', array $attributes = []): Li { - $tag = Li::tag(); + $tag = new Li(); if ($attributes !== []) { $tag = $tag->attributes($attributes); @@ -1297,7 +1297,7 @@ public static function li(string|Stringable $content = '', array $attributes = [ */ public static function datalist(array $attributes = []): Datalist { - $tag = Datalist::tag(); + $tag = new Datalist(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1312,7 +1312,7 @@ public static function datalist(array $attributes = []): Datalist */ public static function caption(string|Stringable $content = '', array $attributes = []): Caption { - $tag = Caption::tag(); + $tag = new Caption(); if ($content !== '') { $tag = $tag->content($content); } @@ -1329,7 +1329,7 @@ public static function caption(string|Stringable $content = '', array $attribute */ public static function col(array $attributes = []): Col { - $tag = Col::tag(); + $tag = new Col(); return $attributes === [] ? $tag : $tag->attributes($attributes); } @@ -1340,7 +1340,7 @@ public static function col(array $attributes = []): Col */ public static function colgroup(array $attributes = []): Colgroup { - $tag = Colgroup::tag(); + $tag = new Colgroup(); return $attributes === [] ? $tag : $tag->attributes($attributes); } @@ -1351,7 +1351,7 @@ public static function colgroup(array $attributes = []): Colgroup */ public static function table(array $attributes = []): Table { - $tag = Table::tag(); + $tag = new Table(); return $attributes === [] ? $tag : $tag->attributes($attributes); } @@ -1362,7 +1362,7 @@ public static function table(array $attributes = []): Table */ public static function thead(array $attributes = []): Thead { - $tag = Thead::tag(); + $tag = new Thead(); return $attributes === [] ? $tag : $tag->attributes($attributes); } @@ -1373,7 +1373,7 @@ public static function thead(array $attributes = []): Thead */ public static function tbody(array $attributes = []): Tbody { - $tag = Tbody::tag(); + $tag = new Tbody(); return $attributes === [] ? $tag : $tag->attributes($attributes); } @@ -1384,7 +1384,7 @@ public static function tbody(array $attributes = []): Tbody */ public static function tfoot(array $attributes = []): Tfoot { - $tag = Tfoot::tag(); + $tag = new Tfoot(); return $attributes === [] ? $tag : $tag->attributes($attributes); } @@ -1395,7 +1395,7 @@ public static function tfoot(array $attributes = []): Tfoot */ public static function tr(array $attributes = []): Tr { - $tag = Tr::tag(); + $tag = new Tr(); return $attributes === [] ? $tag : $tag->attributes($attributes); } @@ -1407,7 +1407,7 @@ public static function tr(array $attributes = []): Tr */ public static function td(string|Stringable $content = '', array $attributes = []): Td { - $tag = Td::tag(); + $tag = new Td(); if ($content !== '') { $tag = $tag->content($content); } @@ -1425,7 +1425,7 @@ public static function td(string|Stringable $content = '', array $attributes = [ */ public static function th(string|Stringable $content = '', array $attributes = []): Th { - $tag = Th::tag(); + $tag = new Th(); if ($content !== '') { $tag = $tag->content($content); } @@ -1440,7 +1440,7 @@ public static function th(string|Stringable $content = '', array $attributes = [ */ public static function br(): Br { - return Br::tag(); + return new Br(); } /** @@ -1448,7 +1448,7 @@ public static function br(): Br */ public static function video(): Video { - return Video::tag(); + return new Video(); } /** @@ -1456,7 +1456,7 @@ public static function video(): Video */ public static function audio(): Audio { - return Audio::tag(); + return new Audio(); } /** @@ -1464,7 +1464,7 @@ public static function audio(): Audio */ public static function track(?string $src = null): Track { - $tag = Track::tag(); + $tag = new Track(); return $src === null ? $tag : $tag->src($src); } @@ -1473,7 +1473,7 @@ public static function track(?string $src = null): Track */ public static function picture(): Picture { - return Picture::tag(); + return new Picture(); } /** @@ -1481,7 +1481,7 @@ public static function picture(): Picture */ public static function source(): Source { - return Source::tag(); + return new Source(); } /** @@ -1493,7 +1493,7 @@ public static function source(): Source */ public static function html(string|Stringable $content = '', ?string $lang = null, array $attributes = []): Tag\Html { - $tag = Tag\Html::tag(); + $tag = new Tag\Html(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1514,7 +1514,7 @@ public static function html(string|Stringable $content = '', ?string $lang = nul */ public static function body(string|Stringable $content = '', array $attributes = []): Body { - $tag = Body::tag(); + $tag = new Body(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1529,7 +1529,7 @@ public static function body(string|Stringable $content = '', array $attributes = */ public static function article(string|Stringable $content = '', array $attributes = []): Article { - $tag = Article::tag(); + $tag = new Article(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1544,7 +1544,7 @@ public static function article(string|Stringable $content = '', array $attribute */ public static function section(string|Stringable $content = '', array $attributes = []): Section { - $tag = Section::tag(); + $tag = new Section(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1559,7 +1559,7 @@ public static function section(string|Stringable $content = '', array $attribute */ public static function nav(string|Stringable $content = '', array $attributes = []): Nav { - $tag = Nav::tag(); + $tag = new Nav(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1574,7 +1574,7 @@ public static function nav(string|Stringable $content = '', array $attributes = */ public static function aside(string|Stringable $content = '', array $attributes = []): Aside { - $tag = Aside::tag(); + $tag = new Aside(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1589,7 +1589,7 @@ public static function aside(string|Stringable $content = '', array $attributes */ public static function hgroup(string|Stringable $content = '', array $attributes = []): Hgroup { - $tag = Hgroup::tag(); + $tag = new Hgroup(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1604,7 +1604,7 @@ public static function hgroup(string|Stringable $content = '', array $attributes */ public static function header(string|Stringable $content = '', array $attributes = []): Header { - $tag = Header::tag(); + $tag = new Header(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1616,7 +1616,7 @@ public static function header(string|Stringable $content = '', array $attributes */ public static function hr(array $attributes = []): Hr { - $tag = Hr::tag(); + $tag = new Hr(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1631,7 +1631,7 @@ public static function hr(array $attributes = []): Hr */ public static function footer(string|Stringable $content = '', array $attributes = []): Footer { - $tag = Footer::tag(); + $tag = new Footer(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } @@ -1646,7 +1646,7 @@ public static function footer(string|Stringable $content = '', array $attributes */ public static function address(string|Stringable $content = '', array $attributes = []): Address { - $tag = Address::tag(); + $tag = new Address(); if (!empty($attributes)) { $tag = $tag->attributes($attributes); } diff --git a/src/Tag/Base/ListTag.php b/src/Tag/Base/ListTag.php index d6f34e82..f4cc2052 100644 --- a/src/Tag/Base/ListTag.php +++ b/src/Tag/Base/ListTag.php @@ -34,7 +34,7 @@ public function items(Li ...$items): static public function strings(array $strings, array $attributes = [], bool $encode = true): static { $items = array_map( - static fn(string $string) => Li::tag() + static fn(string $string) => (new Li()) ->content($string) ->attributes($attributes) ->encode($encode), diff --git a/src/Tag/Base/NormalTag.php b/src/Tag/Base/NormalTag.php index ab8ac07c..cf05ce0e 100644 --- a/src/Tag/Base/NormalTag.php +++ b/src/Tag/Base/NormalTag.php @@ -9,8 +9,11 @@ */ abstract class NormalTag extends Tag { - final private function __construct() {} + final public function __construct() {} + /** + * @deprecated Use the constructor instead. + */ final public static function tag(): static { return new static(); diff --git a/src/Tag/Base/VoidTag.php b/src/Tag/Base/VoidTag.php index 34012b14..77a87305 100644 --- a/src/Tag/Base/VoidTag.php +++ b/src/Tag/Base/VoidTag.php @@ -10,8 +10,11 @@ */ abstract class VoidTag extends Tag { - final private function __construct() {} + final public function __construct() {} + /** + * @deprecated Use the constructor instead. + */ final public static function tag(): static { return new static(); diff --git a/src/Tag/Button.php b/src/Tag/Button.php index ba59169a..c370eb5a 100644 --- a/src/Tag/Button.php +++ b/src/Tag/Button.php @@ -16,21 +16,21 @@ final class Button extends NormalTag public static function button(string $content = ''): self { - $button = self::tag()->content($content); + $button = (new self())->content($content); $button->attributes['type'] = 'button'; return $button; } public static function submit(string $content = ''): self { - $button = self::tag()->content($content); + $button = (new self())->content($content); $button->attributes['type'] = 'submit'; return $button; } public static function reset(string $content = ''): self { - $button = self::tag()->content($content); + $button = (new self())->content($content); $button->attributes['type'] = 'reset'; return $button; } diff --git a/src/Tag/CustomTag.php b/src/Tag/CustomTag.php index 933d0d31..a7d02036 100644 --- a/src/Tag/CustomTag.php +++ b/src/Tag/CustomTag.php @@ -44,7 +44,7 @@ final class CustomTag extends Tag private int $type = self::TYPE_AUTO; - private function __construct( + public function __construct( private string $name, ) {} @@ -54,6 +54,8 @@ private function __construct( * @param string $name Name of the tag. * * @psalm-param non-empty-string $name + * + * @deprecated Use the constructor instead. */ public static function name(string $name): self { diff --git a/src/Tag/Input.php b/src/Tag/Input.php index 9e50aeb5..412a9a19 100644 --- a/src/Tag/Input.php +++ b/src/Tag/Input.php @@ -29,7 +29,7 @@ final class Input extends InputTag */ public static function hidden(?string $name = null, bool|float|int|string|Stringable|null $value = null): self { - $input = self::tag(); + $input = new self(); $input->attributes['type'] = 'hidden'; $input->attributes['name'] = $name; $input->attributes['value'] = $value; @@ -46,7 +46,7 @@ public static function hidden(?string $name = null, bool|float|int|string|String */ public static function text(?string $name = null, bool|float|int|string|Stringable|null $value = null): self { - $input = self::tag(); + $input = new self(); $input->attributes['type'] = 'text'; $input->attributes['name'] = $name; $input->attributes['value'] = $value; @@ -63,7 +63,7 @@ public static function text(?string $name = null, bool|float|int|string|Stringab */ public static function password(?string $name = null, bool|float|int|string|Stringable|null $value = null): self { - $input = self::tag(); + $input = new self(); $input->attributes['type'] = 'password'; $input->attributes['name'] = $name; $input->attributes['value'] = $value; @@ -80,7 +80,7 @@ public static function password(?string $name = null, bool|float|int|string|Stri */ public static function file(?string $name = null, bool|float|int|string|Stringable|null $value = null): File { - $input = File::tag(); + $input = new File(); if ($name !== null) { $input = $input->name($name); } @@ -100,7 +100,7 @@ public static function file(?string $name = null, bool|float|int|string|Stringab */ public static function checkbox(?string $name = null, bool|float|int|string|Stringable|null $value = null): Checkbox { - $input = Checkbox::tag(); + $input = new Checkbox(); if ($name !== null) { $input = $input->name($name); } @@ -120,7 +120,7 @@ public static function checkbox(?string $name = null, bool|float|int|string|Stri */ public static function radio(?string $name = null, bool|float|int|string|Stringable|null $value = null): Radio { - $input = Radio::tag(); + $input = new Radio(); if ($name !== null) { $input = $input->name($name); } @@ -140,7 +140,7 @@ public static function radio(?string $name = null, bool|float|int|string|Stringa */ public static function range(?string $name = null, float|int|string|Stringable|null $value = null): Range { - $input = Range::tag(); + $input = new Range(); if ($name !== null) { $input = $input->name($name); } @@ -160,7 +160,7 @@ public static function range(?string $name = null, float|int|string|Stringable|n */ public static function color(?string $name = null, string|Stringable|null $value = null): Color { - $input = Color::tag(); + $input = new Color(); if ($name !== null) { $input = $input->name($name); } @@ -179,7 +179,7 @@ public static function color(?string $name = null, string|Stringable|null $value */ public static function button(?string $label = null): self { - $input = self::tag(); + $input = new self(); $input->attributes['type'] = 'button'; $input->attributes['value'] = $label; return $input; @@ -194,7 +194,7 @@ public static function button(?string $label = null): self */ public static function submitButton(?string $label = null): self { - $input = self::tag(); + $input = new self(); $input->attributes['type'] = 'submit'; $input->attributes['value'] = $label; return $input; @@ -209,7 +209,7 @@ public static function submitButton(?string $label = null): self */ public static function resetButton(?string $label = null): self { - $input = self::tag(); + $input = new self(); $input->attributes['type'] = 'reset'; $input->attributes['value'] = $label; return $input; diff --git a/src/Tag/Input/Range.php b/src/Tag/Input/Range.php index 48df6046..e3d63d20 100644 --- a/src/Tag/Input/Range.php +++ b/src/Tag/Input/Range.php @@ -126,7 +126,7 @@ protected function after(): string return ''; } - return "\n" . CustomTag::name($this->outputTag) + return "\n" . (new CustomTag($this->outputTag)) ->attributes($this->outputAttributes) ->content((string) ($this->attributes['value'] ?? '-')) ->id($this->outputId) diff --git a/src/Tag/Link.php b/src/Tag/Link.php index 93d056ec..710af8f1 100644 --- a/src/Tag/Link.php +++ b/src/Tag/Link.php @@ -13,7 +13,7 @@ final class Link extends VoidTag { public static function toCssFile(string $url): self { - $link = self::tag(); + $link = new self(); $link->attributes['rel'] = 'stylesheet'; $link->attributes['href'] = $url; return $link; diff --git a/src/Tag/Meta.php b/src/Tag/Meta.php index c04f40a4..ef4303bf 100644 --- a/src/Tag/Meta.php +++ b/src/Tag/Meta.php @@ -16,7 +16,7 @@ final class Meta extends VoidTag */ public static function data(string $name, string $content): self { - $tag = self::tag(); + $tag = new self(); $tag->attributes['name'] = $name; $tag->attributes['content'] = $content; return $tag; @@ -27,7 +27,7 @@ public static function data(string $name, string $content): self */ public static function pragmaDirective(string $name, string $content): self { - $tag = self::tag(); + $tag = new self(); $tag->attributes['http-equiv'] = $name; $tag->attributes['content'] = $content; return $tag; @@ -38,7 +38,7 @@ public static function pragmaDirective(string $name, string $content): self */ public static function documentEncoding(string $encoding): self { - $tag = self::tag(); + $tag = new self(); $tag->attributes['charset'] = $encoding; return $tag; } @@ -48,7 +48,7 @@ public static function documentEncoding(string $encoding): self */ public static function description(string $content): self { - $tag = self::tag(); + $tag = new self(); $tag->attributes['name'] = 'description'; $tag->attributes['content'] = $content; return $tag; diff --git a/src/Tag/Optgroup.php b/src/Tag/Optgroup.php index 5fae1709..83f9cbe5 100644 --- a/src/Tag/Optgroup.php +++ b/src/Tag/Optgroup.php @@ -35,7 +35,7 @@ public function optionsData(array $data, bool $encode = true, array $optionsAttr { $options = []; foreach ($data as $value => $content) { - $options[] = Option::tag() + $options[] = (new Option()) ->attributes($optionsAttributes[$value] ?? []) ->value($value) ->content($content) diff --git a/src/Tag/Script.php b/src/Tag/Script.php index 220b6783..4716c01c 100644 --- a/src/Tag/Script.php +++ b/src/Tag/Script.php @@ -130,7 +130,7 @@ public function defer(bool $defer = true): self public function noscript(string|Stringable|null $content): self { $new = clone $this; - $new->noscript = $content === null ? null : Noscript::tag()->content($content); + $new->noscript = $content === null ? null : (new Noscript())->content($content); return $new; } diff --git a/src/Tag/Select.php b/src/Tag/Select.php index d5e45bcb..1d81dc0d 100644 --- a/src/Tag/Select.php +++ b/src/Tag/Select.php @@ -152,12 +152,12 @@ public function optionsData( $items = []; foreach ($data as $value => $content) { if (is_array($content)) { - $items[] = Optgroup::tag() + $items[] = (new Optgroup()) ->label((string) $value) ->addAttributes($groupsAttributes[$value] ?? []) ->optionsData($content, $encode, $optionsAttributes); } else { - $items[] = Option::tag() + $items[] = (new Option()) ->attributes($optionsAttributes[$value] ?? []) ->value($value) ->content($content) @@ -174,7 +174,7 @@ public function optionsData( public function prompt(?string $text): self { $new = clone $this; - $new->prompt = $text === null ? null : Option::tag() + $new->prompt = $text === null ? null : (new Option()) ->value('') ->content($text); return $new; diff --git a/src/Tag/Table.php b/src/Tag/Table.php index 94c07009..28a11d2e 100644 --- a/src/Tag/Table.php +++ b/src/Tag/Table.php @@ -46,7 +46,7 @@ public function caption(?Caption $caption): self public function captionString(string $content, bool $encode = true): self { - $caption = Caption::tag()->content($content); + $caption = (new Caption())->content($content); if (!$encode) { $caption = $caption->encode(false); } diff --git a/src/Tag/Tr.php b/src/Tag/Tr.php index ce8ed00f..7179dcd6 100644 --- a/src/Tag/Tr.php +++ b/src/Tag/Tr.php @@ -97,7 +97,7 @@ protected function getName(): string private function makeDataCells(array $strings, array $attributes, bool $encode): array { return array_map( - static fn(string $string) => Td::tag() + static fn(string $string) => (new Td()) ->content($string) ->attributes($attributes) ->encode($encode), @@ -113,7 +113,7 @@ private function makeDataCells(array $strings, array $attributes, bool $encode): private function makeHeaderCells(array $strings, array $attributes, bool $encode): array { return array_map( - static fn(string $string) => Th::tag() + static fn(string $string) => (new Th()) ->content($string) ->attributes($attributes) ->encode($encode), diff --git a/src/Widget/ButtonGroup.php b/src/Widget/ButtonGroup.php index 2b1ae41c..76eb0b63 100644 --- a/src/Widget/ButtonGroup.php +++ b/src/Widget/ButtonGroup.php @@ -27,13 +27,16 @@ final class ButtonGroup implements NoEncodeStringableInterface private array $buttonAttributes = []; private string $separator = "\n"; - private function __construct() {} + public function __construct() {} public function __toString(): string { return $this->render(); } + /** + * @deprecated Use the constructor instead. + */ public static function create(): self { return new self(); diff --git a/src/Widget/CheckboxList/CheckboxList.php b/src/Widget/CheckboxList/CheckboxList.php index 79648351..87a198f8 100644 --- a/src/Widget/CheckboxList/CheckboxList.php +++ b/src/Widget/CheckboxList/CheckboxList.php @@ -53,7 +53,7 @@ final class CheckboxList implements NoEncodeStringableInterface */ private ?Closure $itemFormatter = null; - private function __construct( + public function __construct( private string $name, ) {} @@ -62,6 +62,9 @@ public function __toString(): string return $this->render(); } + /** + * @deprecated Use the constructor instead. + */ public static function create(string $name): self { return new self($name); diff --git a/src/Widget/RadioList/RadioList.php b/src/Widget/RadioList/RadioList.php index e9b22269..6d5c6103 100644 --- a/src/Widget/RadioList/RadioList.php +++ b/src/Widget/RadioList/RadioList.php @@ -47,7 +47,7 @@ final class RadioList implements NoEncodeStringableInterface */ private ?Closure $itemFormatter = null; - private function __construct( + public function __construct( private string $name, ) {} @@ -56,6 +56,9 @@ public function __toString(): string return $this->render(); } + /** + * @deprecated Use the constructor instead. + */ public static function create(string $name): self { return new self($name); diff --git a/tests/HtmlTest.php b/tests/HtmlTest.php index 6a604742..b1256397 100644 --- a/tests/HtmlTest.php +++ b/tests/HtmlTest.php @@ -122,7 +122,7 @@ public function testNoscript(): void { $this->assertSame('', Html::noscript()->render()); $this->assertSame('', Html::noscript('hello')->render()); - $this->assertSame('', Html::noscript(Div::tag())->render()); + $this->assertSame('', Html::noscript(new Div())->render()); } public function testTitle(): void diff --git a/tests/Tag/ATest.php b/tests/Tag/ATest.php index ea7eb326..63c10e18 100644 --- a/tests/Tag/ATest.php +++ b/tests/Tag/ATest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( 'Link', - (string) A::tag() + (string) (new A()) ->url('https://example.com') ->content('Link'), ); @@ -31,7 +31,7 @@ public static function dataHref(): array #[DataProvider('dataHref')] public function testHref(string $expected, ?string $href): void { - $this->assertSame($expected, (string) A::tag()->href($href)); + $this->assertSame($expected, (string) (new A())->href($href)); } public static function dataUrl(): array @@ -45,7 +45,7 @@ public static function dataUrl(): array #[DataProvider('dataUrl')] public function testUrl(string $expected, ?string $url): void { - $this->assertSame($expected, (string) A::tag()->url($url)); + $this->assertSame($expected, (string) (new A())->url($url)); } public static function dataMailto(): array @@ -59,7 +59,7 @@ public static function dataMailto(): array #[DataProvider('dataMailto')] public function testMailto(string $expected, ?string $url): void { - $this->assertSame($expected, (string) A::tag()->mailto($url)); + $this->assertSame($expected, (string) (new A())->mailto($url)); } public static function dataRel(): array @@ -76,12 +76,12 @@ public static function dataRel(): array #[DataProvider('dataRel')] public function testRel(string $expected, ?string $rel): void { - $this->assertSame($expected, (string) A::tag()->rel($rel)); + $this->assertSame($expected, (string) (new A())->rel($rel)); } public function testNofollow(): void { - $this->assertSame('', (string) A::tag()->nofollow()); + $this->assertSame('', (string) (new A())->nofollow()); } public static function dataTarget(): array @@ -95,12 +95,12 @@ public static function dataTarget(): array #[DataProvider('dataTarget')] public function testTarget(string $expected, ?string $contextName): void { - $this->assertSame($expected, (string) A::tag()->target($contextName)); + $this->assertSame($expected, (string) (new A())->target($contextName)); } public function testImmutability(): void { - $tag = A::tag(); + $tag = new A(); $this->assertNotSame($tag, $tag->content('')); $this->assertNotSame($tag, $tag->href(null)); $this->assertNotSame($tag, $tag->url(null)); diff --git a/tests/Tag/AddressTest.php b/tests/Tag/AddressTest.php index 0ed2adef..a1ccf7de 100644 --- a/tests/Tag/AddressTest.php +++ b/tests/Tag/AddressTest.php @@ -14,10 +14,10 @@ public function testBase(): void { $this->assertSame( '
Street 111, Mount View Town. Contact: xx-xx-xxxx
', - (string) Address::tag() + (string) (new Address()) ->content( 'Street 111, Mount View Town. Contact: ' - . A::tag() + . (new A()) ->href('tel:xx-xx-xxxx') ->content('xx-xx-xxxx'), ) diff --git a/tests/Tag/ArticleTest.php b/tests/Tag/ArticleTest.php index 6c07f2ca..dc4e3fd3 100644 --- a/tests/Tag/ArticleTest.php +++ b/tests/Tag/ArticleTest.php @@ -17,11 +17,11 @@ public function testBase(): void { $this->assertSame( '

Heading 1

Article content

', - (string) Article::tag() + (string) (new Article()) ->content( - Header::tag()->content(H1::tag()->content('Heading 1')) - . P::tag()->content('Article content') - . Footer::tag()->content('Footer'), + (new Header())->content((new H1())->content('Heading 1')) + . (new P())->content('Article content') + . (new Footer())->content('Footer'), ) ->encode(false), ); diff --git a/tests/Tag/AsideTest.php b/tests/Tag/AsideTest.php index 4f3157d6..698dc809 100644 --- a/tests/Tag/AsideTest.php +++ b/tests/Tag/AsideTest.php @@ -15,10 +15,10 @@ public function testBase(): void { $this->assertSame( '', - (string) Aside::tag() + (string) (new Aside()) ->content( - H2::tag()->content('Hello') - . P::tag()->content('Aside Tag Content'), + (new H2())->content('Hello') + . (new P())->content('Aside Tag Content'), ) ->encode(false), ); diff --git a/tests/Tag/AudioTest.php b/tests/Tag/AudioTest.php index ee49d906..8ebd0d91 100644 --- a/tests/Tag/AudioTest.php +++ b/tests/Tag/AudioTest.php @@ -20,10 +20,10 @@ public function testBase(): void . '' . "\n" . 'Your browser does not support audio.' . "\n" . '', - (string) Audio::tag() + (string) (new Audio()) ->controls() - ->sources(Source::tag()->src('a.mp3'), Source::tag()->src('b.ogg')) - ->tracks(Track::tag()->src('c.mp3')) + ->sources((new Source())->src('a.mp3'), (new Source())->src('b.ogg')) + ->tracks((new Track())->src('c.mp3')) ->fallback('Your browser does not support audio.'), ); } diff --git a/tests/Tag/BTest.php b/tests/Tag/BTest.php index 68e34b5c..200bb383 100644 --- a/tests/Tag/BTest.php +++ b/tests/Tag/BTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Hello', - (string) B::tag() + (string) (new B()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/Base/BooleanInputTagTest.php b/tests/Tag/Base/BooleanInputTagTest.php index aaa1780c..a1d8f27f 100644 --- a/tests/Tag/Base/BooleanInputTagTest.php +++ b/tests/Tag/Base/BooleanInputTagTest.php @@ -12,9 +12,9 @@ final class BooleanInputTagTest extends TestCase { public function testChecked(): void { - $this->assertSame('', (string) TestBooleanInputTag::tag()->checked()); - $this->assertSame('', (string) TestBooleanInputTag::tag()->checked(false)); - $this->assertSame('', (string) TestBooleanInputTag::tag() + $this->assertSame('', (string) (new TestBooleanInputTag())->checked()); + $this->assertSame('', (string) (new TestBooleanInputTag())->checked(false)); + $this->assertSame('', (string) (new TestBooleanInputTag()) ->checked(true) ->checked(false)); } @@ -55,7 +55,7 @@ public function testLabel(string $expected, ?string $label, array $attributes): { $this->assertSame( $expected, - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->label($label, $attributes) ->render(), ); @@ -65,7 +65,7 @@ public function testLabelNoWrap(): void { $this->assertSame( ' ', - (string) TestBooleanInputTag::tag() + (string) (new TestBooleanInputTag()) ->id('ID') ->label('Voronezh', wrap: false), ); @@ -75,7 +75,7 @@ public function testLabelWithId(): void { $this->assertSame( '', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->id('Test') ->label('One') ->render(), @@ -86,7 +86,7 @@ public function testSideLabel(): void { $this->assertMatchesRegularExpression( '~ ~', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->sideLabel('One') ->render(), ); @@ -96,7 +96,7 @@ public function testSideLabelEmpty(): void { $this->assertMatchesRegularExpression( '~ ~', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->sideLabel('') ->render(), ); @@ -106,7 +106,7 @@ public function testSideLabelNull(): void { $this->assertSame( '', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->sideLabel(null) ->render(), ); @@ -116,7 +116,7 @@ public function testSideLabelWithId(): void { $this->assertSame( ' ', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->id('Test') ->sideLabel('One') ->render(), @@ -127,7 +127,7 @@ public function testSideLabelWithAttributes(): void { $this->assertMatchesRegularExpression( '~ ~', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->sideLabel('One', ['class' => 'red']) ->render(), ); @@ -137,7 +137,7 @@ public function testSideLabelId(): void { $this->assertSame( ' ', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->sideLabel('One') ->id('count') ->render(), @@ -148,7 +148,7 @@ public function testWithoutLabelEncode(): void { $this->assertSame( '', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->label('One') ->labelEncode(false) ->render(), @@ -180,7 +180,7 @@ public function testUncheckValue(string $expected, ?string $name, $value): void { $this->assertSame( $expected, - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->name($name) ->uncheckValue($value) ->render(), @@ -192,7 +192,7 @@ public function testUncheckValueDisabled(): void $this->assertSame( '' . '', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->name('color') ->uncheckValue(7) ->disabled() @@ -205,7 +205,7 @@ public function testUncheckValueForm(): void $this->assertSame( '' . '', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->name('color') ->uncheckValue(7) ->form('post') @@ -218,7 +218,7 @@ public function testUncheckValueWithLabel(): void $this->assertSame( '' . '', - TestBooleanInputTag::tag() + (new TestBooleanInputTag()) ->name('color') ->uncheckValue(7) ->label('Seven') @@ -228,7 +228,7 @@ public function testUncheckValueWithLabel(): void public function testImmutability(): void { - $input = TestBooleanInputTag::tag(); + $input = new TestBooleanInputTag(); $this->assertNotSame($input, $input->checked()); $this->assertNotSame($input, $input->label('')); $this->assertNotSame($input, $input->sideLabel('')); diff --git a/tests/Tag/Base/InputTagTest.php b/tests/Tag/Base/InputTagTest.php index e4d9a958..6ebfb142 100644 --- a/tests/Tag/Base/InputTagTest.php +++ b/tests/Tag/Base/InputTagTest.php @@ -22,7 +22,7 @@ public static function dataProviderName(): array #[DataProvider('dataProviderName')] public function testName(string $expected, ?string $name): void { - $this->assertSame($expected, (string) TestInputTag::tag()->name($name)); + $this->assertSame($expected, (string) (new TestInputTag())->name($name)); } public static function dataValue(): array @@ -42,7 +42,7 @@ public static function dataValue(): array #[DataProvider('dataValue')] public function testValue(string $expected, $value): void { - $this->assertSame($expected, (string) TestInputTag::tag()->value($value)); + $this->assertSame($expected, (string) (new TestInputTag())->value($value)); } public static function dataForm(): array @@ -57,41 +57,41 @@ public static function dataForm(): array #[DataProvider('dataForm')] public function testForm(string $expected, ?string $formId): void { - $this->assertSame($expected, TestInputTag::tag() + $this->assertSame($expected, (new TestInputTag()) ->form($formId) ->render()); } public function testReadonly(): void { - $this->assertSame('', (string) TestInputTag::tag()->readonly()); - $this->assertSame('', (string) TestInputTag::tag()->readonly(false)); - $this->assertSame('', (string) TestInputTag::tag() + $this->assertSame('', (string) (new TestInputTag())->readonly()); + $this->assertSame('', (string) (new TestInputTag())->readonly(false)); + $this->assertSame('', (string) (new TestInputTag()) ->readonly(true) ->readonly(false)); } public function testRequired(): void { - $this->assertSame('', (string) TestInputTag::tag()->required()); - $this->assertSame('', (string) TestInputTag::tag()->required(false)); - $this->assertSame('', (string) TestInputTag::tag() + $this->assertSame('', (string) (new TestInputTag())->required()); + $this->assertSame('', (string) (new TestInputTag())->required(false)); + $this->assertSame('', (string) (new TestInputTag()) ->required(true) ->required(false)); } public function testDisabled(): void { - $this->assertSame('', (string) TestInputTag::tag()->disabled()); - $this->assertSame('', (string) TestInputTag::tag()->disabled(false)); - $this->assertSame('', (string) TestInputTag::tag() + $this->assertSame('', (string) (new TestInputTag())->disabled()); + $this->assertSame('', (string) (new TestInputTag())->disabled(false)); + $this->assertSame('', (string) (new TestInputTag()) ->disabled(true) ->disabled(false)); } public function testImmutability(): void { - $input = TestInputTag::tag(); + $input = new TestInputTag(); $this->assertNotSame($input, $input->name(null)); $this->assertNotSame($input, $input->value(null)); $this->assertNotSame($input, $input->form(null)); diff --git a/tests/Tag/Base/ListTagTest.php b/tests/Tag/Base/ListTagTest.php index aca97f05..22ab0cff 100644 --- a/tests/Tag/Base/ListTagTest.php +++ b/tests/Tag/Base/ListTagTest.php @@ -12,9 +12,9 @@ final class ListTagTest extends TestCase { public function testItems(): void { - $tag = TestListTag::tag()->items( - Li::tag()->content('A'), - Li::tag()->content('B'), + $tag = (new TestListTag())->items( + (new Li())->content('A'), + (new Li())->content('B'), ); $this->assertSame("\n
  • A
  • \n
  • B
  • \n
    ", (string) $tag); @@ -22,14 +22,14 @@ public function testItems(): void public function testStrings(): void { - $tag = TestListTag::tag()->strings(['A', 'B']); + $tag = (new TestListTag())->strings(['A', 'B']); $this->assertSame("\n
  • A
  • \n
  • B
  • \n
    ", (string) $tag); } public function testStringsAttributes(): void { - $tag = TestListTag::tag()->strings(['A', 'B'], ['class' => 'red']); + $tag = (new TestListTag())->strings(['A', 'B'], ['class' => 'red']); $this->assertSame( "\n
  • A
  • \n
  • B
  • \n
    ", @@ -39,7 +39,7 @@ public function testStringsAttributes(): void public function testStringsEncode(): void { - $tag = TestListTag::tag()->strings(['A', 'B']); + $tag = (new TestListTag())->strings(['A', 'B']); $this->assertSame( "\n
  • <b>A</b>
  • \n
  • <b>B</b>
  • \n
    ", @@ -49,14 +49,14 @@ public function testStringsEncode(): void public function testStringsWithoutEncode(): void { - $tag = TestListTag::tag()->strings(['A', 'B'], [], false); + $tag = (new TestListTag())->strings(['A', 'B'], [], false); $this->assertSame("\n
  • A
  • \n
  • B
  • \n
    ", (string) $tag); } public function testImmutability(): void { - $tag = TestListTag::tag(); + $tag = new TestListTag(); $this->assertNotSame($tag, $tag->items()); $this->assertNotSame($tag, $tag->strings([])); } diff --git a/tests/Tag/Base/MediaTagTest.php b/tests/Tag/Base/MediaTagTest.php index 22e7f669..bd8ff6c6 100644 --- a/tests/Tag/Base/MediaTagTest.php +++ b/tests/Tag/Base/MediaTagTest.php @@ -22,10 +22,10 @@ public function testBase(): void . '' . "\n" . 'Your browser does not support media.' . "\n" . '', - (string) TestMediaTag::tag() + (string) (new TestMediaTag()) ->controls() - ->sources(Source::tag()->src('a.mp3'), Source::tag()->src('b.ogg')) - ->tracks(Track::tag()->src('c.mp3')) + ->sources((new Source())->src('a.mp3'), (new Source())->src('b.ogg')) + ->tracks((new Track())->src('c.mp3')) ->fallback('Your browser does not support media.'), ); } @@ -43,15 +43,15 @@ public static function dataFallback(): array #[DataProvider('dataFallback')] public function testFallback($fallback): void { - $tag = TestMediaTag::tag()->fallback($fallback); + $tag = (new TestMediaTag())->fallback($fallback); $this->assertSame('' . "\n" . $fallback . "\n" . '', (string) $tag); } public function testTracks(): void { - $tag = TestMediaTag::tag()->tracks( - Track::tag()->src('a.mp4'), - Track::tag()->src('b.mp4'), + $tag = (new TestMediaTag())->tracks( + (new Track())->src('a.mp4'), + (new Track())->src('b.mp4'), ); $this->assertSame("\n\n\n", (string) $tag); @@ -59,10 +59,10 @@ public function testTracks(): void public function testAddTrack(): void { - $tag = TestMediaTag::tag() - ->tracks(Track::tag()->src('a.mp4')) - ->addTrack(Track::tag()->src('b.mp4')) - ->addTrack(Track::tag()->src('c.mp4')); + $tag = (new TestMediaTag()) + ->tracks((new Track())->src('a.mp4')) + ->addTrack((new Track())->src('b.mp4')) + ->addTrack((new Track())->src('c.mp4')); $this->assertSame( "\n\n\n\n", @@ -81,7 +81,7 @@ public static function dataSrc(): array #[DataProvider('dataSrc')] public function testSrc(string $expected, ?string $url): void { - $this->assertSame($expected, (string) TestMediaTag::tag()->src($url)); + $this->assertSame($expected, (string) (new TestMediaTag())->src($url)); } public static function dataCrossOrigin(): array @@ -95,7 +95,7 @@ public static function dataCrossOrigin(): array #[DataProvider('dataCrossOrigin')] public function testCrossOrigin(string $expected, ?string $crossOrigin): void { - $this->assertSame($expected, (string) TestMediaTag::tag()->crossOrigin($crossOrigin)); + $this->assertSame($expected, (string) (new TestMediaTag())->crossOrigin($crossOrigin)); } public static function dataPreload(): array @@ -109,58 +109,58 @@ public static function dataPreload(): array #[DataProvider('dataPreload')] public function testPreload(string $expected, ?string $preload): void { - $this->assertSame($expected, (string) TestMediaTag::tag()->preload($preload)); + $this->assertSame($expected, (string) (new TestMediaTag())->preload($preload)); } public function testMuted(): void { - $this->assertSame('', (string) TestMediaTag::tag()->muted()); - $this->assertSame('', (string) TestMediaTag::tag()->muted(false)); - $this->assertSame('', (string) TestMediaTag::tag() + $this->assertSame('', (string) (new TestMediaTag())->muted()); + $this->assertSame('', (string) (new TestMediaTag())->muted(false)); + $this->assertSame('', (string) (new TestMediaTag()) ->muted(true) ->muted(false)); } public function testLoop(): void { - $this->assertSame('', (string) TestMediaTag::tag()->loop()); - $this->assertSame('', (string) TestMediaTag::tag()->loop(false)); - $this->assertSame('', (string) TestMediaTag::tag() + $this->assertSame('', (string) (new TestMediaTag())->loop()); + $this->assertSame('', (string) (new TestMediaTag())->loop(false)); + $this->assertSame('', (string) (new TestMediaTag()) ->loop(true) ->loop(false)); } public function testAutoplay(): void { - $this->assertSame('', (string) TestMediaTag::tag()->autoplay()); - $this->assertSame('', (string) TestMediaTag::tag()->autoplay(false)); - $this->assertSame('', (string) TestMediaTag::tag() + $this->assertSame('', (string) (new TestMediaTag())->autoplay()); + $this->assertSame('', (string) (new TestMediaTag())->autoplay(false)); + $this->assertSame('', (string) (new TestMediaTag()) ->autoplay(true) ->autoplay(false)); } public function testControls(): void { - $this->assertSame('', (string) TestMediaTag::tag()->controls()); - $this->assertSame('', (string) TestMediaTag::tag()->controls(false)); - $this->assertSame('', (string) TestMediaTag::tag() + $this->assertSame('', (string) (new TestMediaTag())->controls()); + $this->assertSame('', (string) (new TestMediaTag())->controls(false)); + $this->assertSame('', (string) (new TestMediaTag()) ->controls(true) ->controls(false)); } public function testWrongTrackDefault(): void { - $tag = TestMediaTag::tag()->tracks( - Track::tag() + $tag = (new TestMediaTag())->tracks( + (new Track()) ->kind('captions') ->src('sampleCaptions.vtt') ->srclang('en') ->default(), - Track::tag() + (new Track()) ->kind('descriptions') ->src('sampleDescriptions.vtt') ->srclang('de'), - Track::tag() + (new Track()) ->kind('chapters') ->src('sampleChapters.vtt') ->srclang('ja') @@ -179,10 +179,10 @@ public function testWrongTrackDefault(): void public function testImmutability(): void { - $tag = TestMediaTag::tag(); + $tag = new TestMediaTag(); $this->assertNotSame($tag, $tag->fallback(null)); $this->assertNotSame($tag, $tag->tracks()); - $this->assertNotSame($tag, $tag->addTrack(Track::tag())); + $this->assertNotSame($tag, $tag->addTrack(new Track())); $this->assertNotSame($tag, $tag->src(null)); $this->assertNotSame($tag, $tag->crossOrigin(null)); $this->assertNotSame($tag, $tag->preload(null)); diff --git a/tests/Tag/Base/NormalTagTest.php b/tests/Tag/Base/NormalTagTest.php index 1e75a9ca..be966862 100644 --- a/tests/Tag/Base/NormalTagTest.php +++ b/tests/Tag/Base/NormalTagTest.php @@ -10,6 +10,16 @@ final class NormalTagTest extends TestCase { public function testBase(): void + { + $this->assertSame( + 'content', + (new TestNormalTag()) + ->id('main') + ->render(), + ); + } + + public function testTag(): void { $this->assertSame( 'content', @@ -23,7 +33,7 @@ public function testOpen(): void { $this->assertSame( '', - TestNormalTag::tag() + (new TestNormalTag()) ->id('main') ->open(), ); @@ -33,7 +43,7 @@ public function testClose(): void { $this->assertSame( '', - TestNormalTag::tag() + (new TestNormalTag()) ->id('main') ->close(), ); diff --git a/tests/Tag/Base/TableCellTagTest.php b/tests/Tag/Base/TableCellTagTest.php index 21754086..b50cd77e 100644 --- a/tests/Tag/Base/TableCellTagTest.php +++ b/tests/Tag/Base/TableCellTagTest.php @@ -21,7 +21,7 @@ public static function dataColSpan(): array #[DataProvider('dataColSpan')] public function testColSpan(string $expected, ?int $number): void { - $this->assertSame($expected, (string) TestTableCellTag::tag()->colSpan($number)); + $this->assertSame($expected, (string) (new TestTableCellTag())->colSpan($number)); } public static function dataRowSpan(): array @@ -35,12 +35,12 @@ public static function dataRowSpan(): array #[DataProvider('dataRowSpan')] public function testRowSpan(string $expected, ?int $number): void { - $this->assertSame($expected, (string) TestTableCellTag::tag()->rowSpan($number)); + $this->assertSame($expected, (string) (new TestTableCellTag())->rowSpan($number)); } public function testImmutability(): void { - $tag = TestTableCellTag::tag(); + $tag = new TestTableCellTag(); $this->assertNotSame($tag, $tag->colSpan(null)); $this->assertNotSame($tag, $tag->rowSpan(null)); } diff --git a/tests/Tag/Base/TableRowsContainerTagTest.php b/tests/Tag/Base/TableRowsContainerTagTest.php index ada7da6d..ebd93304 100644 --- a/tests/Tag/Base/TableRowsContainerTagTest.php +++ b/tests/Tag/Base/TableRowsContainerTagTest.php @@ -12,9 +12,9 @@ final class TableRowsContainerTagTest extends TestCase { public function testRows(): void { - $tag = TestTableRowsContainerTag::tag()->rows( - Tr::tag()->dataStrings(['A', 'B']), - Tr::tag()->dataStrings(['C', 'D']), + $tag = (new TestTableRowsContainerTag())->rows( + (new Tr())->dataStrings(['A', 'B']), + (new Tr())->dataStrings(['C', 'D']), ); $this->assertSame( @@ -34,13 +34,13 @@ public function testRows(): void public function testAddRows(): void { - $tag = TestTableRowsContainerTag::tag() + $tag = (new TestTableRowsContainerTag()) ->rows( - Tr::tag()->dataStrings(['A', 'B']), + (new Tr())->dataStrings(['A', 'B']), ) ->addRows( - Tr::tag()->dataStrings(['C', 'D']), - Tr::tag()->dataStrings(['E', 'F']), + (new Tr())->dataStrings(['C', 'D']), + (new Tr())->dataStrings(['E', 'F']), ); $this->assertSame( @@ -64,7 +64,7 @@ public function testAddRows(): void public function testImmutability(): void { - $tag = TestTableRowsContainerTag::tag(); + $tag = new TestTableRowsContainerTag(); $this->assertNotSame($tag, $tag->rows()); $this->assertNotSame($tag, $tag->addRows()); } diff --git a/tests/Tag/Base/TagContentTraitTest.php b/tests/Tag/Base/TagContentTraitTest.php index e5f306a1..db201736 100644 --- a/tests/Tag/Base/TagContentTraitTest.php +++ b/tests/Tag/Base/TagContentTraitTest.php @@ -20,7 +20,7 @@ public function testBase(): void { $this->assertSame( '<b>hello &gt; world!</b>', - TestTagContentTrait::tag() + (new TestTagContentTrait()) ->id('main') ->content('hello > world!') ->render(), @@ -31,7 +31,7 @@ public function testWithoutEncode(): void { $this->assertSame( 'hello', - (string) TestTagContentTrait::tag() + (string) (new TestTagContentTrait()) ->content('hello') ->encode(false), ); @@ -41,7 +41,7 @@ public function testWithoutDoubleEncode(): void { $this->assertSame( '<b>A > B</b>', - (string) TestTagContentTrait::tag() + (string) (new TestTagContentTrait()) ->content('A > B') ->doubleEncode(false), ); @@ -52,10 +52,10 @@ public static function dataContent(): array return [ 'string' => ['hello', 'hello'], 'string-tag' => ['<p>Hi!</p>', '

    Hi!

    '], - 'object-tag' => ['

    Hi!

    ', P::tag()->content('Hi!')], + 'object-tag' => ['

    Hi!

    ', (new P())->content('Hi!')], 'array' => [ 'Hello > World!', - ['Hello', ' > ', Span::tag()->content('World'), '!'], + ['Hello', ' > ', (new Span())->content('World'), '!'], ], ]; } @@ -63,7 +63,7 @@ public static function dataContent(): array #[DataProvider('dataContent')] public function testContent(string $expected, string|array|Stringable $content): void { - $tag = TestTagContentTrait::tag(); + $tag = new TestTagContentTrait(); $tag = is_array($content) ? $tag->content(...$content) : $tag->content($content); $this->assertSame($expected, $tag->render()); @@ -73,9 +73,9 @@ public function testEncodeContent(): void { $this->assertSame( '<p>Hi!</p>', - TestTagContentTrait::tag() + (new TestTagContentTrait()) ->encode(true) - ->content(P::tag()->content('Hi!')) + ->content((new P())->content('Hi!')) ->render(), ); } @@ -84,7 +84,7 @@ public function testAddContent(): void { $this->assertSame( 'Hello World', - TestTagContentTrait::tag() + (new TestTagContentTrait()) ->content('Hello') ->addContent(' ') ->addContent(new StringableObject('World')) @@ -96,7 +96,7 @@ public function testAddContentVariadic(): void { $this->assertSame( '123', - TestTagContentTrait::tag() + (new TestTagContentTrait()) ->content('1') ->addContent(...['2', '3']) ->render(), @@ -107,7 +107,7 @@ public function testNamedParametersContent(): void { $this->assertSame( '123', - TestTagContentTrait::tag() + (new TestTagContentTrait()) ->content(content: '1') ->addContent(content: '2') ->addContent(content: '3') @@ -117,14 +117,14 @@ public function testNamedParametersContent(): void public function testContentArray(): void { - $tag = TestTagContentTrait::tag()->content(a: '1', b: '2'); + $tag = (new TestTagContentTrait())->content(a: '1', b: '2'); $this->assertSame(['1', '2'], $tag->getContentArray()); } public function testImmutability(): void { - $tag = TestTagContentTrait::tag(); + $tag = new TestTagContentTrait(); $this->assertNotSame($tag, $tag->encode(true)); $this->assertNotSame($tag, $tag->doubleEncode(true)); $this->assertNotSame($tag, $tag->content('')); diff --git a/tests/Tag/Base/TagSourcesTraitTest.php b/tests/Tag/Base/TagSourcesTraitTest.php index 9c65ee1c..a138b318 100644 --- a/tests/Tag/Base/TagSourcesTraitTest.php +++ b/tests/Tag/Base/TagSourcesTraitTest.php @@ -14,18 +14,18 @@ public function testBase(): void { $this->assertSame( "\n\n\n\n", - TestTagSourcesTrait::tag() - ->sources(Source::tag()->src('video1.mp4')) - ->addSource(Source::tag()->src('video2.mp4')) - ->addSource(Source::tag()->src('video3.mp4')) + (new TestTagSourcesTrait()) + ->sources((new Source())->src('video1.mp4')) + ->addSource((new Source())->src('video2.mp4')) + ->addSource((new Source())->src('video3.mp4')) ->render(), ); } public function testImmutability(): void { - $tag = TestTagSourcesTrait::tag(); + $tag = new TestTagSourcesTrait(); $this->assertNotSame($tag, $tag->sources()); - $this->assertNotSame($tag, $tag->addSource(Source::tag())); + $this->assertNotSame($tag, $tag->addSource(new Source())); } } diff --git a/tests/Tag/Base/TagTest.php b/tests/Tag/Base/TagTest.php index cd7e33e2..e0a3416f 100644 --- a/tests/Tag/Base/TagTest.php +++ b/tests/Tag/Base/TagTest.php @@ -62,15 +62,15 @@ public static function dataAttributes(): array #[DataProvider('dataAttributes')] public function testAttributes(string $expected, array $attributes): void { - $this->assertSame($expected, (string) TestTag::tag()->addAttributes($attributes)); - $this->assertSame($expected, (string) TestTag::tag()->attributes($attributes)); + $this->assertSame($expected, (string) (new TestTag())->addAttributes($attributes)); + $this->assertSame($expected, (string) (new TestTag())->attributes($attributes)); } public function testAttributesMerge(): void { $this->assertSame( '', - TestTag::tag() + (new TestTag()) ->id('color') ->class('red') ->addAttributes(['class' => 'green']) @@ -82,7 +82,7 @@ public function testReplaceAttributes(): void { $this->assertSame( '', - TestTag::tag() + (new TestTag()) ->id('color') ->class('red') ->attributes(['class' => 'green']) @@ -94,7 +94,7 @@ public function testUnionAttributes(): void { $this->assertSame( '', - TestTag::tag() + (new TestTag()) ->class('red') ->unionAttributes(['class' => 'green', 'id' => 'color']) ->render(), @@ -113,7 +113,7 @@ public static function dataAttribute(): array #[DataProvider('dataAttribute')] public function testAttribute(string $expected, $value): void { - $this->assertSame($expected, TestTag::tag() + $this->assertSame($expected, (new TestTag()) ->attribute('key', $value) ->render()); } @@ -129,7 +129,7 @@ public static function dataId(): array #[DataProvider('dataId')] public function testId(string $expected, ?string $id): void { - $this->assertSame($expected, (string) TestTag::tag()->id($id)); + $this->assertSame($expected, (string) (new TestTag())->id($id)); } public static function dataAddClass(): array @@ -151,7 +151,7 @@ public static function dataAddClass(): array #[DataProvider('dataAddClass')] public function testAddClass(string $expected, array $class): void { - $this->assertSame($expected, (string) TestTag::tag() + $this->assertSame($expected, (string) (new TestTag()) ->addClass('main') ->addClass(...$class)); } @@ -168,7 +168,7 @@ public static function dataNewClass(): array #[DataProvider('dataNewClass')] public function testNewClass(string $expected, ?string $class): void { - $this->assertSame($expected, (string) TestTag::tag()->addClass($class)); + $this->assertSame($expected, (string) (new TestTag())->addClass($class)); } public static function dataClass(): array @@ -191,7 +191,7 @@ public static function dataClass(): array #[DataProvider('dataClass')] public function testClass(string $expected, array $class): void { - $this->assertSame($expected, (string) TestTag::tag() + $this->assertSame($expected, (string) (new TestTag()) ->class('red') ->class(...$class)); } @@ -206,13 +206,13 @@ public static function dataAddStyle(): iterable #[DataProvider('dataAddStyle')] public function testAddStyle(string $expected, array|string $style): void { - $result = (string) TestTag::tag()->addStyle($style); + $result = (string) (new TestTag())->addStyle($style); $this->assertSame($expected, $result); } public function testAddStyleMerging(): void { - $tag = TestTag::tag()->addStyle('width: 100px;'); + $tag = (new TestTag())->addStyle('width: 100px;'); $result = (string) $tag->addStyle(['width' => '200px', 'height' => '300px']); @@ -224,7 +224,7 @@ public function testAddStyleMerging(): void public function testAddStyleMergingWithoutOverwrite(): void { - $tag = TestTag::tag()->addStyle('width: 100px;'); + $tag = (new TestTag())->addStyle('width: 100px;'); $result = (string) $tag->addStyle(['width' => '200px', 'height' => '300px'], false); @@ -236,7 +236,7 @@ public function testAddStyleMergingWithoutOverwrite(): void public function testAddStyleWithExistingAttribute(): void { - $tag = TestTag::tag()->attribute('style', 'color: red;'); + $tag = (new TestTag())->attribute('style', 'color: red;'); $result = (string) $tag->addStyle('width: 100px;'); @@ -250,22 +250,22 @@ public static function dataRemoveStyle(): iterable { yield [ '', - TestTag::tag(), + new TestTag(), 'width', ]; yield [ '', - TestTag::tag()->addStyle('width: 100px;'), + (new TestTag())->addStyle('width: 100px;'), 'width', ]; yield [ '', - TestTag::tag()->addStyle('height: 100px; width: 100px;'), + (new TestTag())->addStyle('height: 100px; width: 100px;'), 'width', ]; yield [ '', - TestTag::tag()->addStyle('height: 100px; width: 100px; color: red;'), + (new TestTag())->addStyle('height: 100px; width: 100px; color: red;'), ['width', 'height'], ]; } @@ -280,7 +280,7 @@ public function testRemoveStyle(string $expected, TestTag $tag, string|array $pr public function testImmutability(): void { - $tag = TestTag::tag(); + $tag = new TestTag(); $this->assertNotSame($tag, $tag->addAttributes([])); $this->assertNotSame($tag, $tag->attributes([])); $this->assertNotSame($tag, $tag->unionAttributes([])); diff --git a/tests/Tag/Base/VoidTagTest.php b/tests/Tag/Base/VoidTagTest.php index 2ebc57dd..114a6c1d 100644 --- a/tests/Tag/Base/VoidTagTest.php +++ b/tests/Tag/Base/VoidTagTest.php @@ -10,6 +10,16 @@ final class VoidTagTest extends TestCase { public function testBase(): void + { + $this->assertSame( + '', + (new TestVoidTag()) + ->id('main') + ->render(), + ); + } + + public function testTag(): void { $this->assertSame( '', diff --git a/tests/Tag/BodyTest.php b/tests/Tag/BodyTest.php index 397d9080..1a89b982 100644 --- a/tests/Tag/BodyTest.php +++ b/tests/Tag/BodyTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Welcome!', - (string) Body::tag()->content('Welcome!'), + (string) (new Body())->content('Welcome!'), ); } @@ -21,7 +21,7 @@ public function testAttributes(): void { $this->assertSame( 'Welcome Back!', - (string) Body::tag() + (string) (new Body()) ->attributes([ 'onafterprint' => 'alert(123);', 'style' => 'font-size:20px;', diff --git a/tests/Tag/BrTest.php b/tests/Tag/BrTest.php index 466e01cb..e78e89e8 100644 --- a/tests/Tag/BrTest.php +++ b/tests/Tag/BrTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '
    ', - (string) Br::tag(), + (string) new Br(), ); } } diff --git a/tests/Tag/ButtonTest.php b/tests/Tag/ButtonTest.php index 0f4c5c52..fd09ac46 100644 --- a/tests/Tag/ButtonTest.php +++ b/tests/Tag/ButtonTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - (string) Button::tag() + (string) (new Button()) ->type('submit') ->content('Send'), ); @@ -79,21 +79,21 @@ public static function dataType(): array #[DataProvider('dataType')] public function testType(string $expected, ?string $type): void { - $this->assertSame($expected, (string) Button::tag()->type($type)); + $this->assertSame($expected, (string) (new Button())->type($type)); } public function testDisabled(): void { - $this->assertSame('', (string) Button::tag()->disabled()); - $this->assertSame('', (string) Button::tag()->disabled(false)); - $this->assertSame('', (string) Button::tag() + $this->assertSame('', (string) (new Button())->disabled()); + $this->assertSame('', (string) (new Button())->disabled(false)); + $this->assertSame('', (string) (new Button()) ->disabled(true) ->disabled(false)); } public function testImmutability(): void { - $button = Button::tag(); + $button = new Button(); $this->assertNotSame($button, $button->type(null)); $this->assertNotSame($button, $button->disabled()); } diff --git a/tests/Tag/CaptionTest.php b/tests/Tag/CaptionTest.php index 2f19be71..37ed1a11 100644 --- a/tests/Tag/CaptionTest.php +++ b/tests/Tag/CaptionTest.php @@ -14,10 +14,10 @@ public function testBase(): void { $this->assertSame( 'Table Caption', - Caption::tag() + (new Caption()) ->content( 'Table ', - CustomTag::name('b')->content('Caption'), + (new CustomTag('b'))->content('Caption'), ) ->render(), ); diff --git a/tests/Tag/CodeTest.php b/tests/Tag/CodeTest.php index da218840..96323015 100644 --- a/tests/Tag/CodeTest.php +++ b/tests/Tag/CodeTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Hello', - (string) Code::tag() + (string) (new Code()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/ColTest.php b/tests/Tag/ColTest.php index 8af28cec..8bd8a5b1 100644 --- a/tests/Tag/ColTest.php +++ b/tests/Tag/ColTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - Col::tag() + (new Col()) ->span(2) ->attribute('style', 'background-color:#f00;') ->render(), @@ -34,13 +34,13 @@ public function testSpan(string $expected, ?int $span): void { $this->assertSame( $expected, - Col::tag()->span($span)->render(), + (new Col())->span($span)->render(), ); } public function testImmutability(): void { - $tag = Col::tag(); + $tag = new Col(); $this->assertNotSame($tag, $tag->span(null)); } } diff --git a/tests/Tag/ColgroupTest.php b/tests/Tag/ColgroupTest.php index 00242d9a..c87b15f8 100644 --- a/tests/Tag/ColgroupTest.php +++ b/tests/Tag/ColgroupTest.php @@ -19,13 +19,13 @@ public function testBase(): void . '' . "\n" . '' . "\n" . '', - Colgroup::tag() + (new Colgroup()) ->columns( - Col::tag(), - Col::tag() + new Col(), + (new Col()) ->span(2) ->class('red'), - Col::tag() + (new Col()) ->span(2) ->class('blue'), ) @@ -35,9 +35,9 @@ public function testBase(): void public function testColumns(): void { - $tag = Colgroup::tag()->columns( - Col::tag(), - Col::tag()->span(2), + $tag = (new Colgroup())->columns( + new Col(), + (new Col())->span(2), ); $this->assertSame( @@ -51,14 +51,14 @@ public function testColumns(): void public function testAddColumns(): void { - $tag = Colgroup::tag() + $tag = (new Colgroup()) ->columns( - Col::tag(), - Col::tag()->span(2), + new Col(), + (new Col())->span(2), ) ->addColumns( - Col::tag()->span(3), - Col::tag()->span(4), + (new Col())->span(3), + (new Col())->span(4), ); $this->assertSame( @@ -83,14 +83,14 @@ public static function dataSpan(): array #[DataProvider('dataSpan')] public function testSpan(string $expected, ?int $span): void { - $this->assertSame($expected, Colgroup::tag() + $this->assertSame($expected, (new Colgroup()) ->span($span) ->render()); } public function testImmutability(): void { - $tag = Colgroup::tag(); + $tag = new Colgroup(); $this->assertNotSame($tag, $tag->columns()); $this->assertNotSame($tag, $tag->addColumns()); $this->assertNotSame($tag, $tag->span(null)); diff --git a/tests/Tag/CustomTagTest.php b/tests/Tag/CustomTagTest.php index 003b5b05..38e4ab26 100644 --- a/tests/Tag/CustomTagTest.php +++ b/tests/Tag/CustomTagTest.php @@ -17,6 +17,18 @@ final class CustomTagTest extends TestCase { public function testBase(): void + { + $this->assertSame( + 'body', + (new CustomTag('test')) + ->id('custom') + ->attribute('count', 15) + ->content('body') + ->render(), + ); + } + + public function testName(): void { $this->assertSame( 'body', @@ -43,7 +55,7 @@ public function testVoidTags(string $name): void { $this->assertSame( "<$name>", - CustomTag::name($name)->render(), + (new CustomTag($name))->render(), ); } @@ -58,7 +70,7 @@ public static function dataNormal(): array #[DataProvider('dataNormal')] public function testNormal(string $expected, string $name): void { - $this->assertSame($expected, CustomTag::name($name) + $this->assertSame($expected, (new CustomTag($name)) ->normal() ->render()); } @@ -74,7 +86,7 @@ public static function dataVoid(): array #[DataProvider('dataVoid')] public function testVoid(string $expected, string $name): void { - $this->assertSame($expected, CustomTag::name($name) + $this->assertSame($expected, (new CustomTag($name)) ->void() ->render()); } @@ -83,7 +95,7 @@ public function testWithoutEncode(): void { $this->assertSame( 'hello', - (string) CustomTag::name('test') + (string) (new CustomTag('test')) ->content('hello') ->encode(false), ); @@ -93,7 +105,7 @@ public function testWithoutDoubleEncode(): void { $this->assertSame( '<b>A > B</b>', - (string) CustomTag::name('test') + (string) (new CustomTag('test')) ->content('A > B') ->doubleEncode(false), ); @@ -104,10 +116,10 @@ public static function dataContent(): array return [ 'string' => ['hello', 'hello'], 'string-tag' => ['<p>Hi!</p>', '

    Hi!

    '], - 'object-tag' => ['

    Hi!

    ', P::tag()->content('Hi!')], + 'object-tag' => ['

    Hi!

    ', (new P())->content('Hi!')], 'array' => [ 'Hello > World!', - ['Hello', ' > ', Span::tag()->content('World'), '!'], + ['Hello', ' > ', (new Span())->content('World'), '!'], ], ]; } @@ -115,7 +127,7 @@ public static function dataContent(): array #[DataProvider('dataContent')] public function testContent(string $expected, string|array|Stringable $content): void { - $tag = CustomTag::name('test'); + $tag = new CustomTag('test'); $tag = is_array($content) ? $tag->content(...$content) : $tag->content($content); $this->assertSame($expected, $tag->render()); @@ -125,9 +137,9 @@ public function testEncodeContent(): void { $this->assertSame( '<p>Hi!</p>', - CustomTag::name('test') + (new CustomTag('test')) ->encode(true) - ->content(P::tag()->content('Hi!')) + ->content((new P())->content('Hi!')) ->render(), ); } @@ -136,7 +148,7 @@ public function testAddContent(): void { $this->assertSame( 'Hello World', - CustomTag::name('test') + (new CustomTag('test')) ->content('Hello') ->addContent(' ') ->addContent(new StringableObject('World')) @@ -148,7 +160,7 @@ public function testAddContentVariadic(): void { $this->assertSame( '123', - CustomTag::name('test') + (new CustomTag('test')) ->content('1') ->addContent(...['2', '3']) ->render(), @@ -159,7 +171,7 @@ public function testOpen(): void { $this->assertSame( '', - CustomTag::name('test') + (new CustomTag('test')) ->id('main') ->open(), ); @@ -169,7 +181,7 @@ public function testClose(): void { $this->assertSame( '', - CustomTag::name('test') + (new CustomTag('test')) ->id('main') ->close(), ); @@ -177,7 +189,7 @@ public function testClose(): void public function testImmutability(): void { - $tag = CustomTag::name('test'); + $tag = new CustomTag('test'); $this->assertNotSame($tag, $tag->normal()); $this->assertNotSame($tag, $tag->void()); $this->assertNotSame($tag, $tag->encode(true)); diff --git a/tests/Tag/DatalistTest.php b/tests/Tag/DatalistTest.php index 65f1ce2e..9e10f8c4 100644 --- a/tests/Tag/DatalistTest.php +++ b/tests/Tag/DatalistTest.php @@ -12,11 +12,11 @@ final class DatalistTest extends TestCase { public function testBase(): void { - $tag = Datalist::tag() + $tag = (new Datalist()) ->id('numbers') ->content( - Option::tag()->value('One'), - Option::tag()->value('Two'), + (new Option())->value('One'), + (new Option())->value('Two'), ); $this->assertSame( diff --git a/tests/Tag/DivTest.php b/tests/Tag/DivTest.php index ea8c653b..3dac791e 100644 --- a/tests/Tag/DivTest.php +++ b/tests/Tag/DivTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '
    Hello
    ', - (string) Div::tag() + (string) (new Div()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/EmTest.php b/tests/Tag/EmTest.php index a65de112..3f711d50 100644 --- a/tests/Tag/EmTest.php +++ b/tests/Tag/EmTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Hello', - (string) Em::tag() + (string) (new Em()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/FieldsetTest.php b/tests/Tag/FieldsetTest.php index 619e90f0..31aeedb3 100644 --- a/tests/Tag/FieldsetTest.php +++ b/tests/Tag/FieldsetTest.php @@ -14,7 +14,7 @@ final class FieldsetTest extends TestCase { public function testBase(): void { - $tag = Fieldset::tag() + $tag = (new Fieldset()) ->legend('Personal data') ->content( Html::textInput('first_name'), @@ -65,7 +65,7 @@ public static function dataLegend(): array #[DataProvider('dataLegend')] public function testLegend(string $expected, $content, array $attributes = []): void { - $tag = Fieldset::tag()->legend($content, $attributes); + $tag = (new Fieldset())->legend($content, $attributes); $this->assertSame($expected, $tag->render()); } @@ -83,7 +83,7 @@ public static function dataLegendTag(): array Hello HTML, - Legend::tag() + (new Legend()) ->content('Hello') ->attributes(['id' => 'MyLegend']), ], @@ -93,7 +93,7 @@ public static function dataLegendTag(): array #[DataProvider('dataLegendTag')] public function testLegendTag(string $expected, ?Legend $legend): void { - $tag = Fieldset::tag()->legendTag($legend); + $tag = (new Fieldset())->legendTag($legend); $this->assertSame($expected, $tag->render()); } @@ -119,14 +119,14 @@ public static function dataDisabled(): array #[DataProvider('dataDisabled')] public function testDisabled(string $expected, ?bool $disabled): void { - $tag = Fieldset::tag()->disabled($disabled); + $tag = (new Fieldset())->disabled($disabled); $this->assertSame($expected, $tag->render()); } public function testDisabledDefault(): void { - $tag = Fieldset::tag()->disabled(); + $tag = (new Fieldset())->disabled(); $this->assertSame('
    ', $tag->render()); } @@ -142,7 +142,7 @@ public static function dataForm(): array #[DataProvider('dataForm')] public function testForm(string $expected, ?string $formId): void { - $tag = Fieldset::tag()->form($formId); + $tag = (new Fieldset())->form($formId); $this->assertSame($expected, $tag->render()); } @@ -158,14 +158,14 @@ public static function dataProviderName(): array #[DataProvider('dataProviderName')] public function testName(string $expected, ?string $formId): void { - $tag = Fieldset::tag()->name($formId); + $tag = (new Fieldset())->name($formId); $this->assertSame($expected, $tag->render()); } public function testImmutability(): void { - $tag = Fieldset::tag(); + $tag = new Fieldset(); $this->assertNotSame($tag, $tag->legend(null)); $this->assertNotSame($tag, $tag->legendTag(null)); diff --git a/tests/Tag/FooterTest.php b/tests/Tag/FooterTest.php index 4e76b38b..94402c27 100644 --- a/tests/Tag/FooterTest.php +++ b/tests/Tag/FooterTest.php @@ -15,10 +15,10 @@ public function testBase(): void { $this->assertSame( '

    Heading 1

    Hello Text

    ', - (string) Footer::tag() + (string) (new Footer()) ->content( - H3::tag()->content('Heading 1') - . P::tag()->content('Hello Text'), + (new H3())->content('Heading 1') + . (new P())->content('Hello Text'), ) ->encode(false), ); diff --git a/tests/Tag/FormTest.php b/tests/Tag/FormTest.php index 2db79d06..f06cabd5 100644 --- a/tests/Tag/FormTest.php +++ b/tests/Tag/FormTest.php @@ -15,7 +15,7 @@ final class FormTest extends TestCase { public function testBase(): void { - $tag = Form::tag(); + $tag = new Form(); $this->assertSame( '
    ' @@ -37,7 +37,7 @@ public function testGet(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->get('https://example.com/send') ->render(), ); @@ -47,7 +47,7 @@ public function testGetWithoutUrl(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->get() ->render(), ); @@ -57,7 +57,7 @@ public function testPost(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->post('https://example.com/send') ->render(), ); @@ -67,7 +67,7 @@ public function testPostWithoutUrl(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->post() ->render(), ); @@ -75,7 +75,7 @@ public function testPostWithoutUrl(): void public function testCsrf(): void { - $tag = Form::tag()->csrf('abc', 'csrf-token'); + $tag = (new Form())->csrf('abc', 'csrf-token'); $this->assertSame( '
    ' . "\n" @@ -95,7 +95,7 @@ public function testCsrfDefaultName(): void $this->assertSame( '' . "\n" . '
    ', - Form::tag() + (new Form()) ->csrf('abc') ->render(), ); @@ -106,7 +106,7 @@ public function testStringableCsrfToken(): void $this->assertSame( '
    ' . "\n" . '
    ', - Form::tag() + (new Form()) ->csrf(new StringableObject('abc')) ->render(), ); @@ -125,7 +125,7 @@ public function testAcceptCharset(string $expected, ?string $charset): void { $this->assertSame( $expected, - Form::tag() + (new Form()) ->acceptCharset($charset) ->render(), ); @@ -144,7 +144,7 @@ public function testAction(string $expected, ?string $action): void { $this->assertSame( $expected, - Form::tag() + (new Form()) ->action($action) ->render(), ); @@ -163,7 +163,7 @@ public function testAutocomplete(string $expected, bool $value): void { $this->assertSame( $expected, - Form::tag() + (new Form()) ->autocomplete($value) ->render(), ); @@ -173,7 +173,7 @@ public function testDefaultAutocomplete(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->autocomplete() ->render(), ); @@ -192,7 +192,7 @@ public function testEnctype(string $expected, ?string $enctype): void { $this->assertSame( $expected, - Form::tag() + (new Form()) ->enctype($enctype) ->render(), ); @@ -202,7 +202,7 @@ public function testEnctypeApplicationXWwwFormUrlencoded(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->enctypeApplicationXWwwFormUrlencoded() ->render(), ); @@ -212,7 +212,7 @@ public function testEnctypeMultipartFormData(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->enctypeMultipartFormData() ->render(), ); @@ -222,7 +222,7 @@ public function testEnctypeTextPlain(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->enctypeTextPlain() ->render(), ); @@ -241,7 +241,7 @@ public function testMethod(string $expected, ?string $method): void { $this->assertSame( $expected, - Form::tag() + (new Form()) ->method($method) ->render(), ); @@ -260,7 +260,7 @@ public function testNoValidate(string $expected, bool $noValidate): void { $this->assertSame( $expected, - Form::tag() + (new Form()) ->noValidate($noValidate) ->render(), ); @@ -270,7 +270,7 @@ public function testDefaultNoValidate(): void { $this->assertSame( '
    ', - Form::tag() + (new Form()) ->noValidate() ->render(), ); @@ -289,7 +289,7 @@ public function testTarget(string $expected, ?string $target): void { $this->assertSame( $expected, - Form::tag() + (new Form()) ->target($target) ->render(), ); @@ -297,7 +297,7 @@ public function testTarget(string $expected, ?string $target): void public function testImmutability(): void { - $tag = Form::tag(); + $tag = new Form(); $this->assertNotSame($tag, $tag->get()); $this->assertNotSame($tag, $tag->post()); diff --git a/tests/Tag/H1Test.php b/tests/Tag/H1Test.php index 29043644..24d21d39 100644 --- a/tests/Tag/H1Test.php +++ b/tests/Tag/H1Test.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '

    Hello

    ', - (string) H1::tag() + (string) (new H1()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/H2Test.php b/tests/Tag/H2Test.php index 6e723bb3..e63cc6b4 100644 --- a/tests/Tag/H2Test.php +++ b/tests/Tag/H2Test.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '

    Hello

    ', - (string) H2::tag() + (string) (new H2()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/H3Test.php b/tests/Tag/H3Test.php index 000c3eb2..47e5dd10 100644 --- a/tests/Tag/H3Test.php +++ b/tests/Tag/H3Test.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '

    Hello

    ', - (string) H3::tag() + (string) (new H3()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/H4Test.php b/tests/Tag/H4Test.php index 8e9232e0..f250545a 100644 --- a/tests/Tag/H4Test.php +++ b/tests/Tag/H4Test.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '

    Hello

    ', - (string) H4::tag() + (string) (new H4()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/H5Test.php b/tests/Tag/H5Test.php index 9ed7580b..db325230 100644 --- a/tests/Tag/H5Test.php +++ b/tests/Tag/H5Test.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '
    Hello
    ', - (string) H5::tag() + (string) (new H5()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/H6Test.php b/tests/Tag/H6Test.php index b9f15082..cd427f79 100644 --- a/tests/Tag/H6Test.php +++ b/tests/Tag/H6Test.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '
    Hello
    ', - (string) H6::tag() + (string) (new H6()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/HeaderTest.php b/tests/Tag/HeaderTest.php index 6bb18587..1fce9ddf 100644 --- a/tests/Tag/HeaderTest.php +++ b/tests/Tag/HeaderTest.php @@ -15,10 +15,10 @@ public function testBase(): void { $this->assertSame( '

    Heading 1

    Hello Text
    ', - (string) Header::tag() + (string) (new Header()) ->content( - H1::tag()->content('Heading 1') - . I::tag()->content('Hello Text'), + (new H1())->content('Heading 1') + . (new I())->content('Hello Text'), ) ->encode(false), ); diff --git a/tests/Tag/HgroupTest.php b/tests/Tag/HgroupTest.php index 86f89a58..579900bd 100644 --- a/tests/Tag/HgroupTest.php +++ b/tests/Tag/HgroupTest.php @@ -16,11 +16,11 @@ public function testBase(): void { $this->assertSame( '

    Heading 1

    Heading 2

    Heading 3

    ', - (string) Hgroup::tag() + (string) (new Hgroup()) ->content( - H1::tag()->content('Heading 1') - . H2::tag()->content('Heading 2') - . H3::tag()->content('Heading 3'), + (new H1())->content('Heading 1') + . (new H2())->content('Heading 2') + . (new H3())->content('Heading 3'), ) ->encode(false), ); diff --git a/tests/Tag/HrTest.php b/tests/Tag/HrTest.php index dc5c56e2..e60c65c5 100644 --- a/tests/Tag/HrTest.php +++ b/tests/Tag/HrTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '
    ', - (string) Hr::tag(), + (string) (new Hr()), ); } } diff --git a/tests/Tag/HtmlTest.php b/tests/Tag/HtmlTest.php index db47dc66..1f6b1e48 100644 --- a/tests/Tag/HtmlTest.php +++ b/tests/Tag/HtmlTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( 'Welcome!', - (string) Html::tag()->content('Welcome!'), + (string) (new Html())->content('Welcome!'), ); } @@ -22,7 +22,7 @@ public function testAttributes(): void { $this->assertSame( 'Welcome Back!', - (string) Html::tag() + (string) (new Html()) ->attributes([ 'onafterprint' => 'alert(123);', 'style' => 'font-size:20px;', @@ -42,12 +42,12 @@ public static function dataLang(): array #[DataProvider('dataLang')] public function testLang(string $expected, ?string $href): void { - $this->assertSame($expected, (string) Html::tag()->lang($href)); + $this->assertSame($expected, (string) (new Html())->lang($href)); } public function testImmutability(): void { - $tag = Html::tag(); + $tag = new Html(); $this->assertNotSame($tag, $tag->lang(null)); } diff --git a/tests/Tag/ITest.php b/tests/Tag/ITest.php index 2c69b965..befadd5b 100644 --- a/tests/Tag/ITest.php +++ b/tests/Tag/ITest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Hello', - (string) I::tag() + (string) (new I()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/ImgTest.php b/tests/Tag/ImgTest.php index b072f3d8..94f925fe 100644 --- a/tests/Tag/ImgTest.php +++ b/tests/Tag/ImgTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( 'Great Company', - (string) Img::tag() + (string) (new Img()) ->url('logo.png') ->alt('Great Company'), ); @@ -31,8 +31,8 @@ public static function dataUrl(): array #[DataProvider('dataUrl')] public function testUrl(string $expected, ?string $url): void { - $this->assertSame($expected, (string) Img::tag()->url($url)); - $this->assertSame($expected, (string) Img::tag()->src($url)); + $this->assertSame($expected, (string) (new Img())->url($url)); + $this->assertSame($expected, (string) (new Img())->src($url)); } public static function dataSrcset(): array @@ -48,7 +48,7 @@ public static function dataSrcset(): array #[DataProvider('dataSrcset')] public function testSrcset(string $expected, array $items): void { - $this->assertSame($expected, (string) Img::tag()->srcset(...$items)); + $this->assertSame($expected, (string) (new Img())->srcset(...$items)); } public static function dataSrcsetData(): array @@ -70,7 +70,7 @@ public static function dataSrcsetData(): array #[DataProvider('dataSrcsetData')] public function testSrcsetData(string $expected, array $items): void { - $this->assertSame($expected, (string) Img::tag()->srcsetData($items)); + $this->assertSame($expected, (string) (new Img())->srcsetData($items)); } public static function dataAlt(): array @@ -84,7 +84,7 @@ public static function dataAlt(): array #[DataProvider('dataAlt')] public function testAlt(string $expected, ?string $text): void { - $this->assertSame($expected, (string) Img::tag()->alt($text)); + $this->assertSame($expected, (string) (new Img())->alt($text)); } public static function dataWidth(): array @@ -99,7 +99,7 @@ public static function dataWidth(): array #[DataProvider('dataWidth')] public function testWidth(string $expected, $width): void { - $this->assertSame($expected, (string) Img::tag()->width($width)); + $this->assertSame($expected, (string) (new Img())->width($width)); } public static function dataHeight(): array @@ -114,7 +114,7 @@ public static function dataHeight(): array #[DataProvider('dataHeight')] public function testHeight(string $expected, $height): void { - $this->assertSame($expected, (string) Img::tag()->height($height)); + $this->assertSame($expected, (string) (new Img())->height($height)); } public static function dataSize(): array @@ -129,7 +129,7 @@ public static function dataSize(): array #[DataProvider('dataSize')] public function testSize(string $expected, $width, $height): void { - $this->assertSame($expected, (string) Img::tag()->size($width, $height)); + $this->assertSame($expected, (string) (new Img())->size($width, $height)); } public static function dataLoading(): array @@ -144,12 +144,12 @@ public static function dataLoading(): array #[DataProvider('dataLoading')] public function testLoading(string $expected, ?string $loading): void { - $this->assertSame($expected, (string) Img::tag()->loading($loading)); + $this->assertSame($expected, (string) (new Img())->loading($loading)); } public function testImmutability(): void { - $img = Img::tag(); + $img = new Img(); $this->assertNotSame($img, $img->url(null)); $this->assertNotSame($img, $img->src(null)); $this->assertNotSame($img, $img->srcset()); diff --git a/tests/Tag/Input/CheckboxTest.php b/tests/Tag/Input/CheckboxTest.php index abedeebb..1608e0b6 100644 --- a/tests/Tag/Input/CheckboxTest.php +++ b/tests/Tag/Input/CheckboxTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '', - Checkbox::tag() + (new Checkbox()) ->name('number') ->value(42) ->render(), diff --git a/tests/Tag/Input/ColorTest.php b/tests/Tag/Input/ColorTest.php index 576299ff..d543d5ba 100644 --- a/tests/Tag/Input/ColorTest.php +++ b/tests/Tag/Input/ColorTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '', - Color::tag() + (new Color()) ->name('color') ->value('#ff0000') ->render(), diff --git a/tests/Tag/Input/FileTest.php b/tests/Tag/Input/FileTest.php index 8a861031..820f82ce 100644 --- a/tests/Tag/Input/FileTest.php +++ b/tests/Tag/Input/FileTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - File::tag() + (new File()) ->name('avatar') ->render(), ); @@ -45,7 +45,7 @@ public function testUncheckValue(string $expected, ?string $name, $value): void { $this->assertSame( $expected, - File::tag() + (new File()) ->name($name) ->uncheckValue($value) ->render(), @@ -57,7 +57,7 @@ public function testUncheckValueDisabled(): void $this->assertSame( '' . '', - File::tag() + (new File()) ->name('avatar') ->uncheckValue(7) ->disabled() @@ -70,7 +70,7 @@ public function testUncheckValueForm(): void $this->assertSame( '' . '', - File::tag() + (new File()) ->name('avatar') ->uncheckValue(7) ->form('post') @@ -80,7 +80,7 @@ public function testUncheckValueForm(): void public function testUncheckInputAttributes(): void { - $result = File::tag() + $result = (new File()) ->name('avatar') ->uncheckValue(7) ->addUncheckInputAttributes(['id' => 'FileHidden']) @@ -97,7 +97,7 @@ public function testUncheckInputAttributes(): void public function testReplaceUncheckInputAttributes(): void { - $result = File::tag() + $result = (new File()) ->name('avatar') ->uncheckValue(7) ->addUncheckInputAttributes(['id' => 'FileHidden']) @@ -131,7 +131,7 @@ public function testAccept(string $expected, ?string $accept): void { $this->assertSame( $expected, - File::tag() + (new File()) ->name('avatar') ->accept($accept) ->render(), @@ -157,7 +157,7 @@ public function testMultiple(string $expected, ?bool $multiple): void { $this->assertSame( $expected, - File::tag() + (new File()) ->name('avatar') ->multiple($multiple) ->render(), @@ -168,7 +168,7 @@ public function testMultipleDefault(): void { $this->assertSame( '', - File::tag() + (new File()) ->name('avatar') ->multiple() ->render(), @@ -177,7 +177,7 @@ public function testMultipleDefault(): void public function testImmutability(): void { - $tag = File::tag(); + $tag = new File(); $this->assertNotSame($tag, $tag->uncheckValue(null)); $this->assertNotSame($tag, $tag->addUncheckInputAttributes([])); diff --git a/tests/Tag/Input/RadioTest.php b/tests/Tag/Input/RadioTest.php index 134660c8..2ce8214a 100644 --- a/tests/Tag/Input/RadioTest.php +++ b/tests/Tag/Input/RadioTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '', - Radio::tag() + (new Radio()) ->name('number') ->value(42) ->render(), diff --git a/tests/Tag/Input/RangeTest.php b/tests/Tag/Input/RangeTest.php index 1a05ec01..689f0e08 100644 --- a/tests/Tag/Input/RangeTest.php +++ b/tests/Tag/Input/RangeTest.php @@ -14,7 +14,7 @@ final class RangeTest extends TestCase { public function testBase(): void { - $tag = Range::tag() + $tag = (new Range()) ->name('opacity') ->min(0) ->max(100) @@ -41,7 +41,7 @@ public static function dataMin(): array #[DataProvider('dataMin')] public function testMin(string $expected, $value): void { - $tag = Range::tag()->min($value); + $tag = (new Range())->min($value); $this->assertSame($expected, $tag->render()); } @@ -61,7 +61,7 @@ public static function dataMax(): array #[DataProvider('dataMax')] public function testMax(string $expected, $value): void { - $tag = Range::tag()->max($value); + $tag = (new Range())->max($value); $this->assertSame($expected, $tag->render()); } @@ -81,7 +81,7 @@ public static function dataStep(): array #[DataProvider('dataStep')] public function testStep(string $expected, $value): void { - $tag = Range::tag()->step($value); + $tag = (new Range())->step($value); $this->assertSame($expected, $tag->render()); } @@ -97,14 +97,14 @@ public static function dataList(): array #[DataProvider('dataList')] public function testList(string $expected, $value): void { - $tag = Range::tag()->list($value); + $tag = (new Range())->list($value); $this->assertSame($expected, $tag->render()); } public function testShowOutput(): void { - $tag = Range::tag()->showOutput(); + $tag = (new Range())->showOutput(); $this->assertMatchesRegularExpression( '~showOutput() ->addOutputAttributes(['class' => 'red']) ->addOutputAttributes(['id' => 'UID']); @@ -131,7 +131,7 @@ public function testAddOutputAttributes(): void public function testReplaceOutputAttributes(): void { - $tag = Range::tag() + $tag = (new Range()) ->showOutput() ->addOutputAttributes(['class' => 'red']) ->outputAttributes(['id' => 'UID']); @@ -146,7 +146,7 @@ public function testReplaceOutputAttributes(): void public function testOutputWithCustomId(): void { - $tag = Range::tag() + $tag = (new Range()) ->showOutput() ->outputAttributes(['id' => 'UID']); @@ -160,7 +160,7 @@ public function testOutputWithCustomId(): void public function testOutputWithCustomTag(): void { - $tag = Range::tag() + $tag = (new Range()) ->showOutput() ->outputTag('b'); @@ -174,7 +174,7 @@ public function testOutputWithCustomTag(): void public function testOutputWithCustomAttributes(): void { - $tag = Range::tag() + $tag = (new Range()) ->showOutput() ->outputAttributes(['class' => 'red']); @@ -188,7 +188,7 @@ public function testOutputWithCustomAttributes(): void public function testOutputWithValue(): void { - $tag = Range::tag() + $tag = (new Range()) ->showOutput() ->value(10); @@ -202,7 +202,7 @@ public function testOutputWithValue(): void public function testEmptyOutputTag(): void { - $tag = Range::tag(); + $tag = new Range(); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The output tag name it cannot be empty value.'); @@ -211,7 +211,7 @@ public function testEmptyOutputTag(): void public function testImmutability(): void { - $tag = Range::tag(); + $tag = new Range(); $this->assertNotSame($tag, $tag->min(null)); $this->assertNotSame($tag, $tag->max(null)); diff --git a/tests/Tag/InputTest.php b/tests/Tag/InputTest.php index a7056eaf..e00f6043 100644 --- a/tests/Tag/InputTest.php +++ b/tests/Tag/InputTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - (string) Input::tag() + (string) (new Input()) ->type('hidden') ->name('id') ->value('42'), @@ -120,12 +120,12 @@ public static function dataType(): array #[DataProvider('dataType')] public function testType(string $expected, ?string $type): void { - $this->assertSame($expected, (string) Input::tag()->type($type)); + $this->assertSame($expected, (string) (new Input())->type($type)); } public function testImmutability(): void { - $input = Input::tag(); + $input = new Input(); $this->assertNotSame($input, $input->type(null)); } } diff --git a/tests/Tag/LabelTest.php b/tests/Tag/LabelTest.php index 23021510..7457c787 100644 --- a/tests/Tag/LabelTest.php +++ b/tests/Tag/LabelTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - (string) Label::tag() + (string) (new Label()) ->forId('name') ->content('Your name'), ); @@ -31,12 +31,12 @@ public static function dataForId(): array #[DataProvider('dataForId')] public function testForId(string $expected, ?string $id): void { - $this->assertSame($expected, (string) Label::tag()->forId($id)); + $this->assertSame($expected, (string) (new Label())->forId($id)); } public function testImmutability(): void { - $label = Label::tag(); + $label = new Label(); $this->assertNotSame($label, $label->forId(null)); } } diff --git a/tests/Tag/LegendTest.php b/tests/Tag/LegendTest.php index f02d2c41..13b8ffef 100644 --- a/tests/Tag/LegendTest.php +++ b/tests/Tag/LegendTest.php @@ -11,7 +11,7 @@ final class LegendTest extends TestCase { public function testBase(): void { - $tag = Legend::tag()->content('Personal data'); + $tag = (new Legend())->content('Personal data'); $this->assertSame('Personal data', $tag->render()); } } diff --git a/tests/Tag/LiTest.php b/tests/Tag/LiTest.php index 63b0c800..2d9f6d40 100644 --- a/tests/Tag/LiTest.php +++ b/tests/Tag/LiTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '
  • Hello
  • ', - (string) Li::tag() + (string) (new Li()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/LinkTest.php b/tests/Tag/LinkTest.php index 627eae64..1b93c46a 100644 --- a/tests/Tag/LinkTest.php +++ b/tests/Tag/LinkTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - (string) Link::tag() + (string) (new Link()) ->url('/rss') ->type('application/rss+xml') ->rel('alternate') @@ -41,8 +41,8 @@ public static function dataUrl(): array #[DataProvider('dataUrl')] public function testUrl(string $expected, ?string $url): void { - $this->assertSame($expected, (string) Link::tag()->url($url)); - $this->assertSame($expected, (string) Link::tag()->href($url)); + $this->assertSame($expected, (string) (new Link())->url($url)); + $this->assertSame($expected, (string) (new Link())->href($url)); } public static function dataRel(): array @@ -56,7 +56,7 @@ public static function dataRel(): array #[DataProvider('dataRel')] public function testRel(string $expected, ?string $rel): void { - $this->assertSame($expected, (string) Link::tag()->rel($rel)); + $this->assertSame($expected, (string) (new Link())->rel($rel)); } public static function dataType(): array @@ -70,7 +70,7 @@ public static function dataType(): array #[DataProvider('dataType')] public function testType(string $expected, ?string $type): void { - $this->assertSame($expected, (string) Link::tag()->type($type)); + $this->assertSame($expected, (string) (new Link())->type($type)); } public static function dataTitle(): array @@ -84,7 +84,7 @@ public static function dataTitle(): array #[DataProvider('dataTitle')] public function testTitle(string $expected, ?string $title): void { - $this->assertSame($expected, (string) Link::tag()->title($title)); + $this->assertSame($expected, (string) (new Link())->title($title)); } public static function dataCrossOrigin(): array @@ -98,7 +98,7 @@ public static function dataCrossOrigin(): array #[DataProvider('dataCrossOrigin')] public function testCrossOrigin(string $expected, ?string $crossOrigin): void { - $this->assertSame($expected, (string) Link::tag()->crossOrigin($crossOrigin)); + $this->assertSame($expected, (string) (new Link())->crossOrigin($crossOrigin)); } public static function dataTestAs(): array @@ -113,7 +113,7 @@ public static function dataTestAs(): array #[DataProvider('dataTestAs')] public function testAs(string $expected, ?string $as): void { - $this->assertSame($expected, (string) Link::tag()->as($as)); + $this->assertSame($expected, (string) (new Link())->as($as)); } public static function dataPreload(): array @@ -128,15 +128,15 @@ public static function dataPreload(): array public function testPreload(string $expected, string $url, ?string $as = null): void { $tag = $as === null - ? Link::tag()->preload($url) - : Link::tag()->preload($url, $as); + ? (new Link())->preload($url) + : (new Link())->preload($url, $as); $this->assertSame($expected, $tag->render()); } public function testImmutability(): void { - $link = Link::tag(); + $link = new Link(); $this->assertNotSame($link, $link->url(null)); $this->assertNotSame($link, $link->href(null)); $this->assertNotSame($link, $link->rel(null)); diff --git a/tests/Tag/MetaTest.php b/tests/Tag/MetaTest.php index d426d229..a0faafe8 100644 --- a/tests/Tag/MetaTest.php +++ b/tests/Tag/MetaTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - Meta::tag() + (new Meta()) ->name('description') ->content('Yii Framework') ->render(), @@ -65,7 +65,7 @@ public static function dataProviderName(): array #[DataProvider('dataProviderName')] public function testName(string $expected, ?string $name): void { - $this->assertSame($expected, (string) Meta::tag()->name($name)); + $this->assertSame($expected, (string) (new Meta())->name($name)); } public static function dataHttpEquiv(): array @@ -80,7 +80,7 @@ public static function dataHttpEquiv(): array #[DataProvider('dataHttpEquiv')] public function testHttpEquiv(string $expected, ?string $name): void { - $this->assertSame($expected, (string) Meta::tag()->httpEquiv($name)); + $this->assertSame($expected, (string) (new Meta())->httpEquiv($name)); } public static function dataContent(): array @@ -95,7 +95,7 @@ public static function dataContent(): array #[DataProvider('dataContent')] public function testContent(string $expected, ?string $content): void { - $this->assertSame($expected, (string) Meta::tag()->content($content)); + $this->assertSame($expected, (string) (new Meta())->content($content)); } public static function dataCharset(): array @@ -110,12 +110,12 @@ public static function dataCharset(): array #[DataProvider('dataCharset')] public function testCharset(string $expected, ?string $charset): void { - $this->assertSame($expected, (string) Meta::tag()->charset($charset)); + $this->assertSame($expected, (string) (new Meta())->charset($charset)); } public function testImmutability(): void { - $tag = Meta::tag(); + $tag = new Meta(); $this->assertNotSame($tag, $tag->name(null)); $this->assertNotSame($tag, $tag->httpEquiv(null)); $this->assertNotSame($tag, $tag->content(null)); diff --git a/tests/Tag/NavTest.php b/tests/Tag/NavTest.php index f420596c..bfd8f6ba 100644 --- a/tests/Tag/NavTest.php +++ b/tests/Tag/NavTest.php @@ -15,11 +15,11 @@ public function testBase(): void { $this->assertSame( "", - (string) Nav::tag()->content( - Ul::tag()->items( - Li::tag()->content('Home'), - Li::tag()->content('About Us'), - Li::tag()->content('Contact Us'), + (string) (new Nav())->content( + (new Ul())->items( + (new Li())->content('Home'), + (new Li())->content('About Us'), + (new Li())->content('Contact Us'), ), ), ); diff --git a/tests/Tag/NoscriptTest.php b/tests/Tag/NoscriptTest.php index 5163415b..45be12d5 100644 --- a/tests/Tag/NoscriptTest.php +++ b/tests/Tag/NoscriptTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - (string) Noscript::tag()->content(Img::tag()->src('pixel.png')), + (string) (new Noscript())->content((new Img())->src('pixel.png')), ); } } diff --git a/tests/Tag/OlTest.php b/tests/Tag/OlTest.php index 9f87ecf2..cb01748a 100644 --- a/tests/Tag/OlTest.php +++ b/tests/Tag/OlTest.php @@ -12,9 +12,9 @@ final class OlTest extends TestCase { public function testBase(): void { - $ol = Ol::tag()->items( - Li::tag()->content('A'), - Li::tag()->content('B'), + $ol = (new Ol())->items( + (new Li())->content('A'), + (new Li())->content('B'), ); $this->assertSame("
      \n
    1. A
    2. \n
    3. B
    4. \n
    ", (string) $ol); diff --git a/tests/Tag/OptgroupTest.php b/tests/Tag/OptgroupTest.php index c180560c..1d272419 100644 --- a/tests/Tag/OptgroupTest.php +++ b/tests/Tag/OptgroupTest.php @@ -18,12 +18,12 @@ public function testBase(): void . '' . "\n" . '' . "\n" . '', - (string) Optgroup::tag() + (string) (new Optgroup()) ->options( - Option::tag() + (new Option()) ->value('1') ->content('One'), - Option::tag() + (new Option()) ->value('2') ->content('Two'), ) @@ -35,12 +35,12 @@ public function testOptions(): void { $this->assertSame( "\n\n\n", - (string) Optgroup::tag() + (string) (new Optgroup()) ->options( - Option::tag() + (new Option()) ->value('1') ->content('One'), - Option::tag() + (new Option()) ->value('2') ->content('Two'), ), @@ -51,7 +51,7 @@ public function testOptionsData(): void { $this->assertSame( "\n\n\n", - (string) Optgroup::tag()->optionsData(['1' => 'One', '2' => 'Two']), + (string) (new Optgroup())->optionsData(['1' => 'One', '2' => 'Two']), ); } @@ -59,7 +59,7 @@ public function testOptionsDataEncode(): void { $this->assertSame( "\n\n", - (string) Optgroup::tag()->optionsData(['1' => 'One']), + (string) (new Optgroup())->optionsData(['1' => 'One']), ); } @@ -67,7 +67,7 @@ public function testOptionsDataWithoutEncode(): void { $this->assertSame( "\n\n", - (string) Optgroup::tag()->optionsData(['1' => 'One'], false), + (string) (new Optgroup())->optionsData(['1' => 'One'], false), ); } @@ -82,14 +82,14 @@ public static function dataLabel(): array #[DataProvider('dataLabel')] public function testLabel(string $expected, ?string $label): void { - $this->assertSame($expected, (string) Optgroup::tag()->label($label)); + $this->assertSame($expected, (string) (new Optgroup())->label($label)); } public function testDisabled(): void { - $this->assertSame('', (string) Optgroup::tag()->disabled()); - $this->assertSame('', (string) Optgroup::tag()->disabled(false)); - $this->assertSame('', (string) Optgroup::tag() + $this->assertSame('', (string) (new Optgroup())->disabled()); + $this->assertSame('', (string) (new Optgroup())->disabled(false)); + $this->assertSame('', (string) (new Optgroup()) ->disabled(true) ->disabled(false)); } @@ -104,7 +104,7 @@ public static function dataSelection(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag() + [(new Option())->value('1'), (new Option()) ->value('2') ->selected(), ], [], @@ -114,7 +114,7 @@ public static function dataSelection(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [7], ], [ @@ -122,7 +122,7 @@ public static function dataSelection(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [1], ], [ @@ -130,7 +130,7 @@ public static function dataSelection(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], ['2'], ], [ @@ -138,7 +138,7 @@ public static function dataSelection(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [1, 2], ], ]; @@ -149,7 +149,7 @@ public function testSelection(string $expected, array $options, array $selection { $this->assertSame( $expected, - (string) Optgroup::tag() + (string) (new Optgroup()) ->options(...$options) ->selection(...$selection), ); @@ -157,7 +157,7 @@ public function testSelection(string $expected, array $options, array $selection public function testImmutability(): void { - $optgroup = Optgroup::tag(); + $optgroup = new Optgroup(); $this->assertNotSame($optgroup, $optgroup->options()); $this->assertNotSame($optgroup, $optgroup->optionsData([])); $this->assertNotSame($optgroup, $optgroup->label(null)); diff --git a/tests/Tag/OptionTest.php b/tests/Tag/OptionTest.php index 069b63d6..32d6762c 100644 --- a/tests/Tag/OptionTest.php +++ b/tests/Tag/OptionTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - (string) Option::tag() + (string) (new Option()) ->value('1') ->content('One'), ); @@ -31,21 +31,21 @@ public static function dataValue(): array #[DataProvider('dataValue')] public function testValue(string $expected, ?string $value): void { - $this->assertSame($expected, (string) Option::tag()->value($value)); + $this->assertSame($expected, (string) (new Option())->value($value)); } public function testSelected(): void { - $this->assertSame('', (string) Option::tag()->selected()); - $this->assertSame('', (string) Option::tag()->selected(false)); - $this->assertSame('', (string) Option::tag()->selected(true)->selected(false)); + $this->assertSame('', (string) (new Option())->selected()); + $this->assertSame('', (string) (new Option())->selected(false)); + $this->assertSame('', (string) (new Option())->selected(true)->selected(false)); } public function testDisabled(): void { - $this->assertSame('', (string) Option::tag()->disabled()); - $this->assertSame('', (string) Option::tag()->disabled(false)); - $this->assertSame('', (string) Option::tag() + $this->assertSame('', (string) (new Option())->disabled()); + $this->assertSame('', (string) (new Option())->disabled(false)); + $this->assertSame('', (string) (new Option()) ->disabled(true) ->disabled(false)); } @@ -53,10 +53,10 @@ public function testDisabled(): void public static function dataGetValue(): array { return [ - [null, Option::tag()], - [null, Option::tag()->value(null)], - ['', Option::tag()->value('')], - ['one', Option::tag()->value('one')], + [null, new Option()], + [null, (new Option())->value(null)], + ['', (new Option())->value('')], + ['one', (new Option())->value('one')], ]; } @@ -68,7 +68,7 @@ public function testGetValue(?string $expected, Option $tag): void public function testImmutability(): void { - $option = Option::tag(); + $option = new Option(); $this->assertNotSame($option, $option->value(null)); $this->assertNotSame($option, $option->selected()); $this->assertNotSame($option, $option->disabled()); diff --git a/tests/Tag/PTest.php b/tests/Tag/PTest.php index f0dcd27f..d7afd489 100644 --- a/tests/Tag/PTest.php +++ b/tests/Tag/PTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '

    Hello

    ', - (string) P::tag() + (string) (new P()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/PictureTest.php b/tests/Tag/PictureTest.php index f052013c..a051d13b 100644 --- a/tests/Tag/PictureTest.php +++ b/tests/Tag/PictureTest.php @@ -14,16 +14,16 @@ final class PictureTest extends TestCase { public function testBase(): void { - $picture = Picture::tag() - ->image(Img::tag() + $picture = (new Picture()) + ->image((new Img()) ->src('img_orange_flowers.jpg') ->alt('Flowers')) ->sources( - Source::tag() + (new Source()) ->media('(min-width:650px)') ->srcset('img_pink_flowers.jpg') ->type('image/jpeg'), - Source::tag() + (new Source()) ->media('(min-width:465px)') ->srcset('img_white_flower.jpg') ->type('image/jpeg'), @@ -45,7 +45,7 @@ public static function dataImg(): array ['', null], [ '' . "\n" . '' . "\n" . '', - Img::tag() + (new Img()) ->src('image.jpg') ->width(100) ->height(100), @@ -56,14 +56,14 @@ public static function dataImg(): array #[DataProvider('dataImg')] public function testImg(string $expected, ?Img $img): void { - $this->assertSame($expected, Picture::tag() + $this->assertSame($expected, (new Picture()) ->image($img) ->render()); } public function testImmutability(): void { - $tag = Picture::tag(); + $tag = new Picture(); $this->assertNotSame($tag, $tag->image(null)); } } diff --git a/tests/Tag/PreTest.php b/tests/Tag/PreTest.php index 1de768e3..c62e29c0 100644 --- a/tests/Tag/PreTest.php +++ b/tests/Tag/PreTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( '
    Hello
    ', - (string) Pre::tag() + (string) (new Pre()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/ScriptTest.php b/tests/Tag/ScriptTest.php index 6d9e1940..65adb8a7 100644 --- a/tests/Tag/ScriptTest.php +++ b/tests/Tag/ScriptTest.php @@ -17,14 +17,14 @@ public function testBase(): void { $this->assertSame( '', - (string) Script::tag()->url('main.js'), + (string) (new Script())->url('main.js'), ); } public function testContent(): void { $content = 'alert("4 > 2");'; - $tag = Script::tag()->content($content); + $tag = (new Script())->content($content); $this->assertSame($content, $tag->getContent()); $this->assertSame('', $tag->render()); @@ -41,8 +41,8 @@ public static function dataUrl(): array #[DataProvider('dataUrl')] public function testUrl(string $expected, ?string $url): void { - $this->assertSame($expected, (string) Script::tag()->url($url)); - $this->assertSame($expected, (string) Script::tag()->src($url)); + $this->assertSame($expected, (string) (new Script())->url($url)); + $this->assertSame($expected, (string) (new Script())->src($url)); } public static function dataType(): array @@ -56,7 +56,7 @@ public static function dataType(): array #[DataProvider('dataType')] public function testType(string $expected, ?string $type): void { - $this->assertSame($expected, (string) Script::tag()->type($type)); + $this->assertSame($expected, (string) (new Script())->type($type)); } public static function dataCharset(): array @@ -70,23 +70,23 @@ public static function dataCharset(): array #[DataProvider('dataCharset')] public function testCharset(string $expected, ?string $charset): void { - $this->assertSame($expected, (string) Script::tag()->charset($charset)); + $this->assertSame($expected, (string) (new Script())->charset($charset)); } public function testAsync(): void { - $this->assertSame('', (string) Script::tag()->async()); - $this->assertSame('', (string) Script::tag()->async(false)); - $this->assertSame('', (string) Script::tag() + $this->assertSame('', (string) (new Script())->async()); + $this->assertSame('', (string) (new Script())->async(false)); + $this->assertSame('', (string) (new Script()) ->async(true) ->async(false)); } public function testDefer(): void { - $this->assertSame('', (string) Script::tag()->defer()); - $this->assertSame('', (string) Script::tag()->defer(false)); - $this->assertSame('', (string) Script::tag() + $this->assertSame('', (string) (new Script())->defer()); + $this->assertSame('', (string) (new Script())->defer(false)); + $this->assertSame('', (string) (new Script()) ->defer(true) ->defer(false)); } @@ -95,34 +95,34 @@ public function testNoscript(): void { $this->assertSame( '', - (string) Script::tag()->noscript('hello'), + (string) (new Script())->noscript('hello'), ); $this->assertSame( '', - (string) Script::tag()->noscript(Div::tag()), + (string) (new Script())->noscript(new Div()), ); $this->assertSame( '', - (string) Script::tag()->noscript(null), + (string) (new Script())->noscript(null), ); } public function testNoscriptTag(): void { - $noscriptTag = Noscript::tag()->content('hello'); + $noscriptTag = (new Noscript())->content('hello'); $this->assertSame( '', - (string) Script::tag()->noscriptTag($noscriptTag), + (string) (new Script())->noscriptTag($noscriptTag), ); $this->assertSame( '', - (string) Script::tag()->noscriptTag(null), + (string) (new Script())->noscriptTag(null), ); } public function testImmutability(): void { - $script = Script::tag(); + $script = new Script(); $this->assertNotSame($script, $script->content('')); $this->assertNotSame($script, $script->url(null)); $this->assertNotSame($script, $script->src(null)); @@ -146,7 +146,7 @@ public static function dataNonce(): iterable #[DataProvider('dataNonce')] public function testNonce(string $expectedHtml, ?string $nonce): void { - $script = Script::tag()->nonce($nonce); + $script = (new Script())->nonce($nonce); $this->assertSame($expectedHtml, (string) $script); $this->assertSame($nonce, $script->getNonce()); @@ -154,7 +154,7 @@ public function testNonce(string $expectedHtml, ?string $nonce): void public function testNonceWithoutValue(): void { - $script = Script::tag(); + $script = new Script(); $this->assertSame('', (string) $script); $this->assertNull($script->getNonce()); @@ -162,7 +162,7 @@ public function testNonceWithoutValue(): void public function testInvalidNonce(): void { - $script = Script::tag()->attribute('nonce', []); + $script = (new Script())->attribute('nonce', []); $this->expectException(LogicException::class); $this->expectExceptionMessage('Nonce should be string or null. Got array.'); diff --git a/tests/Tag/SectionTest.php b/tests/Tag/SectionTest.php index 86ff2f27..7237f793 100644 --- a/tests/Tag/SectionTest.php +++ b/tests/Tag/SectionTest.php @@ -15,10 +15,10 @@ public function testBase(): void { $this->assertSame( '

    Section Heading

    Section Content

    ', - (string) Section::tag() + (string) (new Section()) ->content( - H1::tag()->content('Section Heading') - . P::tag()->content('Section Content'), + (new H1())->content('Section Heading') + . (new P())->content('Section Content'), ) ->encode(false), ); diff --git a/tests/Tag/SelectTest.php b/tests/Tag/SelectTest.php index 9b4d0a40..9883f1cd 100644 --- a/tests/Tag/SelectTest.php +++ b/tests/Tag/SelectTest.php @@ -28,7 +28,7 @@ public static function dataProviderName(): array #[DataProvider('dataProviderName')] public function testName(string $expected, ?string $name): void { - $this->assertSame($expected, (string) Select::tag()->name($name)); + $this->assertSame($expected, (string) (new Select())->name($name)); } public static function dataNameForMultiple(): array @@ -52,7 +52,7 @@ public static function dataNameForMultiple(): array #[DataProvider('dataNameForMultiple')] public function testNameForMultiple(string $expected, ?string $name): void { - $this->assertSame($expected, (string) Select::tag() + $this->assertSame($expected, (string) (new Select()) ->multiple() ->name($name)); } @@ -67,7 +67,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag() + [(new Option())->value('1'), (new Option()) ->value('2') ->selected(), ], [], @@ -77,7 +77,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [7], ], [ @@ -85,7 +85,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [1], ], [ @@ -93,7 +93,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], ['2'], ], [ @@ -101,7 +101,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [1, 2], ], [ @@ -113,14 +113,14 @@ public static function dataValue(): array . '' . "\n" . '', [ - Option::tag() + (new Option()) ->value('1') ->content('One'), - Optgroup::tag()->options( - Option::tag() + (new Optgroup())->options( + (new Option()) ->value('1.1') ->content('One.One'), - Option::tag() + (new Option()) ->value('1.2') ->content('One.Two'), ), @@ -136,14 +136,14 @@ public static function dataValue(): array . '' . "\n" . '', [ - Option::tag() + (new Option()) ->value('1') ->content('One'), - Optgroup::tag()->options( - Option::tag() + (new Optgroup())->options( + (new Option()) ->value('1.1') ->content('One.One'), - Option::tag() + (new Option()) ->value('1.2') ->content('One.Two'), ), @@ -157,7 +157,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [IntegerEnum::C], ], [ @@ -165,7 +165,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [IntegerEnum::A], ], [ @@ -173,7 +173,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('1'), Option::tag()->value('2')], + [(new Option())->value('1'), (new Option())->value('2')], [IntegerEnum::A, IntegerEnum::B], ], [ @@ -181,7 +181,7 @@ public static function dataValue(): array . '' . "\n" . '' . "\n" . '', - [Option::tag()->value('one'), Option::tag()->value('two')], + [(new Option())->value('one'), (new Option())->value('two')], [StringEnum::B], ], ]; @@ -192,11 +192,11 @@ public function testValue(string $expected, array $items, array $value): void { $this->assertSame( $expected, - (string) Select::tag()->items(...$items)->value(...$value), + (string) (new Select())->items(...$items)->value(...$value), ); $this->assertSame( $expected, - (string) Select::tag()->items(...$items)->values($value), + (string) (new Select())->items(...$items)->values($value), ); } @@ -212,7 +212,7 @@ public static function dataForm(): array #[DataProvider('dataForm')] public function testForm(string $expected, ?string $formId): void { - $this->assertSame($expected, Select::tag() + $this->assertSame($expected, (new Select()) ->form($formId) ->render()); } @@ -230,10 +230,10 @@ public static function dataItems(): array . '' . "\n" . '', [ - Option::tag() + (new Option()) ->value('1') ->content('One'), - Option::tag() + (new Option()) ->value('2') ->content('Two'), ], @@ -247,14 +247,14 @@ public static function dataItems(): array . '' . "\n" . '', [ - Option::tag() + (new Option()) ->value('1') ->content('One'), - Optgroup::tag()->options( - Option::tag() + (new Optgroup())->options( + (new Option()) ->value('1.1') ->content('One.One'), - Option::tag() + (new Option()) ->value('1.2') ->content('One.Two'), ), @@ -266,19 +266,19 @@ public static function dataItems(): array #[DataProvider('dataItems')] public function testItems(string $expected, array $items): void { - $this->assertSame($expected, (string) Select::tag()->items(...$items)); + $this->assertSame($expected, (string) (new Select())->items(...$items)); } public function testOptions(): void { $this->assertSame( "", - (string) Select::tag() + (string) (new Select()) ->options( - Option::tag() + (new Option()) ->value('1') ->content('One'), - Option::tag() + (new Option()) ->value('2') ->content('Two'), ), @@ -289,7 +289,7 @@ public function testOptionsData(): void { $this->assertSame( "", - (string) Select::tag()->optionsData(['1' => 'One', '2' => 'Two']), + (string) (new Select())->optionsData(['1' => 'One', '2' => 'Two']), ); } @@ -297,7 +297,7 @@ public function testOptionsDataEncode(): void { $this->assertSame( "", - (string) Select::tag()->optionsData(['1' => 'One']), + (string) (new Select())->optionsData(['1' => 'One']), ); } @@ -305,13 +305,13 @@ public function testOptionsDataWithoutEncode(): void { $this->assertSame( "", - (string) Select::tag()->optionsData(['1' => 'One'], false), + (string) (new Select())->optionsData(['1' => 'One'], false), ); } public function testOptionsDataWithGroups(): void { - $tag = Select::tag() + $tag = (new Select()) ->optionsData([ 1 => 'One', 'Test Group' => [ @@ -336,7 +336,7 @@ public function testOptionsDataWithGroups(): void public function testOptionsAndGroupsAttributes(): void { - $tag = Select::tag() + $tag = (new Select()) ->optionsData( [ 1 => 'One', @@ -401,9 +401,9 @@ public function testPrompt(string $expected, ?string $text): void { $this->assertSame( $expected, - (string) Select::tag() + (string) (new Select()) ->prompt($text) - ->options(Option::tag() + ->options((new Option()) ->value('1') ->content('One')), ); @@ -423,7 +423,7 @@ public static function dataPromptOption(): array . '' . "\n" . '' . "\n" . '', - Option::tag()->content('Please select...'), + (new Option())->content('Please select...'), ], ]; } @@ -433,9 +433,9 @@ public function testPromptOption(string $expected, ?Option $option): void { $this->assertSame( $expected, - (string) Select::tag() + (string) (new Select()) ->promptOption($option) - ->options(Option::tag() + ->options((new Option()) ->value('1') ->content('One')), ); @@ -443,27 +443,27 @@ public function testPromptOption(string $expected, ?Option $option): void public function testDisabled(): void { - $this->assertSame('', (string) Select::tag()->disabled()); - $this->assertSame('', (string) Select::tag()->disabled(false)); - $this->assertSame('', (string) Select::tag() + $this->assertSame('', (string) (new Select())->disabled()); + $this->assertSame('', (string) (new Select())->disabled(false)); + $this->assertSame('', (string) (new Select()) ->disabled(true) ->disabled(false)); } public function testMultiple(): void { - $this->assertSame('', (string) Select::tag()->multiple()); - $this->assertSame('', (string) Select::tag()->multiple(false)); - $this->assertSame('', (string) Select::tag() + $this->assertSame('', (string) (new Select())->multiple()); + $this->assertSame('', (string) (new Select())->multiple(false)); + $this->assertSame('', (string) (new Select()) ->multiple(true) ->multiple(false)); } public function testRequired(): void { - $this->assertSame('', (string) Select::tag()->required()); - $this->assertSame('', (string) Select::tag()->required(false)); - $this->assertSame('', (string) Select::tag() + $this->assertSame('', (string) (new Select())->required()); + $this->assertSame('', (string) (new Select())->required(false)); + $this->assertSame('', (string) (new Select()) ->required(true) ->required(false)); } @@ -479,7 +479,7 @@ public static function dataSize(): array #[DataProvider('dataSize')] public function testSize(string $expected, ?int $size): void { - $this->assertSame($expected, (string) Select::tag()->size($size)); + $this->assertSame($expected, (string) (new Select())->size($size)); } public static function dataUnselectValue(): array @@ -509,7 +509,7 @@ public function testUnselectValue(string $expected, ?string $name, $value): void { $this->assertSame( $expected, - Select::tag() + (new Select()) ->name($name) ->unselectValue($value) ->render(), @@ -521,7 +521,7 @@ public function testUnselectValueDisabled(): void $this->assertSame( '' . "\n" . '', - Select::tag() + (new Select()) ->name('test') ->unselectValue(7) ->disabled() @@ -534,7 +534,7 @@ public function testUnselectValueForm(): void $this->assertSame( '' . "\n" . '', - Select::tag() + (new Select()) ->name('test') ->unselectValue(7) ->form('post') @@ -547,7 +547,7 @@ public function testUnselectValueMultiple(): void $this->assertSame( '' . "\n" . '', - Select::tag() + (new Select()) ->name('test') ->unselectValue(7) ->multiple() @@ -557,7 +557,7 @@ public function testUnselectValueMultiple(): void public function testImmutability(): void { - $select = Select::tag(); + $select = new Select(); $this->assertNotSame($select, $select->name('')); $this->assertNotSame($select, $select->value()); $this->assertNotSame($select, $select->values([])); @@ -566,7 +566,7 @@ public function testImmutability(): void $this->assertNotSame($select, $select->options()); $this->assertNotSame($select, $select->optionsData([])); $this->assertNotSame($select, $select->prompt('')); - $this->assertNotSame($select, $select->promptOption(Option::tag())); + $this->assertNotSame($select, $select->promptOption(new Option())); $this->assertNotSame($select, $select->disabled()); $this->assertNotSame($select, $select->multiple()); $this->assertNotSame($select, $select->required()); @@ -576,7 +576,7 @@ public function testImmutability(): void public function testNullValue(): void { - $select = Select::tag() + $select = (new Select()) ->optionsData(['red' => 'RED', 'green' => 'GREEN']) ->value(null); @@ -593,7 +593,7 @@ public function testNullValue(): void public function testNullValueOverride(): void { - $select = Select::tag() + $select = (new Select()) ->optionsData(['red' => 'RED', 'green' => 'GREEN']) ->value('red') ->value(null); diff --git a/tests/Tag/SmallTest.php b/tests/Tag/SmallTest.php index 18c331cf..d14d4f80 100644 --- a/tests/Tag/SmallTest.php +++ b/tests/Tag/SmallTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Hello', - (string) Small::tag() + (string) (new Small()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/SourceTest.php b/tests/Tag/SourceTest.php index 0b02e337..c21d28b7 100644 --- a/tests/Tag/SourceTest.php +++ b/tests/Tag/SourceTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - (string) Source::tag() + (string) (new Source()) ->src('audio.ogg') ->type('audio/ogg; codecs=vorbis'), ); @@ -31,7 +31,7 @@ public static function dataType(): array #[DataProvider('dataType')] public function testType(string $expected, ?string $url): void { - $this->assertSame($expected, (string) Source::tag()->type($url)); + $this->assertSame($expected, (string) (new Source())->type($url)); } public static function dataSrc(): array @@ -45,7 +45,7 @@ public static function dataSrc(): array #[DataProvider('dataSrc')] public function testSrc(string $expected, ?string $url): void { - $this->assertSame($expected, (string) Source::tag()->src($url)); + $this->assertSame($expected, (string) (new Source())->src($url)); } public static function dataSrcset(): array @@ -64,7 +64,7 @@ public static function dataSrcset(): array #[DataProvider('dataSrcset')] public function testSrcset(string $expected, array $items): void { - $this->assertSame($expected, (string) Source::tag()->srcset(...$items)); + $this->assertSame($expected, (string) (new Source())->srcset(...$items)); } public static function dataSizes(): array @@ -83,7 +83,7 @@ public static function dataSizes(): array #[DataProvider('dataSizes')] public function testSizes(string $expected, array $items): void { - $this->assertSame($expected, (string) Source::tag()->sizes(...$items)); + $this->assertSame($expected, (string) (new Source())->sizes(...$items)); } public static function dataWidth(): array @@ -98,7 +98,7 @@ public static function dataWidth(): array #[DataProvider('dataWidth')] public function testWidth(string $expected, $width): void { - $this->assertSame($expected, (string) Source::tag()->width($width)); + $this->assertSame($expected, (string) (new Source())->width($width)); } public static function dataHeight(): array @@ -113,12 +113,12 @@ public static function dataHeight(): array #[DataProvider('dataHeight')] public function testHeight(string $expected, $height): void { - $this->assertSame($expected, (string) Source::tag()->height($height)); + $this->assertSame($expected, (string) (new Source())->height($height)); } public function testImmutability(): void { - $source = Source::tag(); + $source = new Source(); $this->assertNotSame($source, $source->type(null)); $this->assertNotSame($source, $source->src(null)); $this->assertNotSame($source, $source->srcset(null)); diff --git a/tests/Tag/SpanTest.php b/tests/Tag/SpanTest.php index 6c9260f7..c595864f 100644 --- a/tests/Tag/SpanTest.php +++ b/tests/Tag/SpanTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Hello', - (string) Span::tag() + (string) (new Span()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/StrongTest.php b/tests/Tag/StrongTest.php index 6cfc575c..08c43d1e 100644 --- a/tests/Tag/StrongTest.php +++ b/tests/Tag/StrongTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Hello', - (string) Strong::tag() + (string) (new Strong()) ->class('red') ->content('Hello'), ); diff --git a/tests/Tag/StyleTest.php b/tests/Tag/StyleTest.php index 6a948f88..9dc8310d 100644 --- a/tests/Tag/StyleTest.php +++ b/tests/Tag/StyleTest.php @@ -14,14 +14,14 @@ public function testBase(): void { $this->assertSame( '', - (string) Style::tag()->content('.red { color: #f00; }'), + (string) (new Style())->content('.red { color: #f00; }'), ); } public function testContent(): void { $content = 'body { display: block }'; - $tag = Style::tag()->content($content); + $tag = (new Style())->content($content); $this->assertSame($content, $tag->getContent()); $this->assertSame('', $tag->render()); @@ -38,7 +38,7 @@ public static function dataMedia(): array #[DataProvider('dataMedia')] public function testMedia(string $expected, ?string $media): void { - $this->assertSame($expected, (string) Style::tag()->media($media)); + $this->assertSame($expected, (string) (new Style())->media($media)); } public static function dataType(): array @@ -52,12 +52,12 @@ public static function dataType(): array #[DataProvider('dataType')] public function testType(string $expected, ?string $type): void { - $this->assertSame($expected, (string) Style::tag()->type($type)); + $this->assertSame($expected, (string) (new Style())->type($type)); } public function testImmutability(): void { - $tag = Style::tag(); + $tag = new Style(); $this->assertNotSame($tag, $tag->content('')); $this->assertNotSame($tag, $tag->media(null)); $this->assertNotSame($tag, $tag->type(null)); diff --git a/tests/Tag/TableTest.php b/tests/Tag/TableTest.php index 2312da40..d3339990 100644 --- a/tests/Tag/TableTest.php +++ b/tests/Tag/TableTest.php @@ -19,21 +19,21 @@ class TableTest extends TestCase { public function testEmpty(): void { - $this->assertSame('
    ', Table::tag()->render()); + $this->assertSame('
    ', (new Table())->render()); } public static function dataCaption(): array { return [ ['
    ', null], - ["\n\n
    Hello
    ", Caption::tag()->content('Hello')], + ["\n\n
    Hello
    ", (new Caption())->content('Hello')], ]; } #[DataProvider('dataCaption')] public function testCaption(string $expected, ?Caption $caption): void { - $this->assertSame($expected, Table::tag() + $this->assertSame($expected, (new Table()) ->caption($caption) ->render()); } @@ -42,7 +42,7 @@ public function testCaptionString(): void { $this->assertSame( "\n\n
    Hello
    ", - Table::tag() + (new Table()) ->captionString('Hello') ->render(), ); @@ -52,7 +52,7 @@ public function testCaptionStringWithEncode(): void { $this->assertSame( "\n\n
    <b>Hello</b>
    ", - Table::tag() + (new Table()) ->captionString('Hello') ->render(), ); @@ -62,7 +62,7 @@ public function testCaptionStringWithoutEncode(): void { $this->assertSame( "\n\n
    Hello
    ", - Table::tag() + (new Table()) ->captionString('Hello', false) ->render(), ); @@ -70,12 +70,12 @@ public function testCaptionStringWithoutEncode(): void public function testColumnGroups(): void { - $tag = Table::tag()->columnGroups( - Colgroup::tag()->columns( - Col::tag(), - Col::tag()->span(2), + $tag = (new Table())->columnGroups( + (new Colgroup())->columns( + new Col(), + (new Col())->span(2), ), - Colgroup::tag()->span(4), + (new Colgroup())->span(4), ); $this->assertSame( @@ -92,16 +92,16 @@ public function testColumnGroups(): void public function testAddColumnGroups(): void { - $tag = Table::tag() + $tag = (new Table()) ->columnGroups( - Colgroup::tag()->columns( - Col::tag(), - Col::tag()->span(2), + (new Colgroup())->columns( + new Col(), + (new Col())->span(2), ), ) ->addColumnGroups( - Colgroup::tag()->span(4), - Colgroup::tag()->span(5), + (new Colgroup())->span(4), + (new Colgroup())->span(5), ); $this->assertSame( @@ -119,9 +119,9 @@ public function testAddColumnGroups(): void public function testColumns(): void { - $tag = Table::tag()->columns( - Col::tag(), - Col::tag()->span(2), + $tag = (new Table())->columns( + new Col(), + (new Col())->span(2), ); $this->assertSame( @@ -135,14 +135,14 @@ public function testColumns(): void public function testAddColumns(): void { - $tag = Table::tag() + $tag = (new Table()) ->columns( - Col::tag(), - Col::tag()->span(2), + new Col(), + (new Col())->span(2), ) ->addColumns( - Col::tag()->span(3), - Col::tag()->span(4), + (new Col())->span(3), + (new Col())->span(4), ); $this->assertSame( @@ -160,23 +160,23 @@ public static function dataHeader(): array { return [ ['
    ', null], - ["\n\n
    ", Thead::tag()], + ["\n\n
    ", new Thead()], ]; } #[DataProvider('dataHeader')] public function testHeader(string $expected, ?Thead $header): void { - $this->assertSame($expected, Table::tag() + $this->assertSame($expected, (new Table()) ->header($header) ->render()); } public function testBody(): void { - $tag = Table::tag()->body( - Tbody::tag(), - Tbody::tag()->class('red'), + $tag = (new Table())->body( + new Tbody(), + (new Tbody())->class('red'), ); $this->assertSame( @@ -190,13 +190,13 @@ public function testBody(): void public function testAddBody(): void { - $tag = Table::tag() + $tag = (new Table()) ->body( - Tbody::tag(), + new Tbody(), ) ->addBody( - Tbody::tag()->class('red'), - Tbody::tag()->class('green'), + (new Tbody())->class('red'), + (new Tbody())->class('green'), ); $this->assertSame( @@ -211,9 +211,9 @@ public function testAddBody(): void public function testRows(): void { - $tag = Table::tag()->rows( - Tr::tag()->dataStrings(['A', 'B']), - Tr::tag()->dataStrings(['C', 'D']), + $tag = (new Table())->rows( + (new Tr())->dataStrings(['A', 'B']), + (new Tr())->dataStrings(['C', 'D']), ); $this->assertSame( @@ -233,13 +233,13 @@ public function testRows(): void public function testAddRows(): void { - $tag = Table::tag() + $tag = (new Table()) ->rows( - Tr::tag()->dataStrings(['A', 'B']), + (new Tr())->dataStrings(['A', 'B']), ) ->addRows( - Tr::tag()->dataStrings(['C', 'D']), - Tr::tag()->dataStrings(['E', 'F']), + (new Tr())->dataStrings(['C', 'D']), + (new Tr())->dataStrings(['E', 'F']), ); $this->assertSame( @@ -265,14 +265,14 @@ public static function dataFooter(): array { return [ ['
    ', null], - ["\n\n
    ", Tfoot::tag()], + ["\n\n
    ", new Tfoot()], ]; } #[DataProvider('dataFooter')] public function testFooter(string $expected, ?Tfoot $footer): void { - $this->assertSame($expected, Table::tag() + $this->assertSame($expected, (new Table()) ->footer($footer) ->render()); } @@ -288,12 +288,12 @@ public static function dataItemsOrder(): array . '' . "\n" . '' . "\n" . '', - Table::tag() + (new Table()) ->captionString('Caption of Table') - ->columnGroups(Colgroup::tag()) - ->header(Thead::tag()) - ->body(Tbody::tag()) - ->footer(Tfoot::tag()), + ->columnGroups(new Colgroup()) + ->header(new Thead()) + ->body(new Tbody()) + ->footer(new Tfoot()), ], [ '' . "\n" @@ -303,12 +303,12 @@ public static function dataItemsOrder(): array . '' . "\n" . '' . "\n" . '
    ', - Table::tag() + (new Table()) ->captionString('Caption of Table') - ->columns(Col::tag()) - ->header(Thead::tag()) - ->rows(Tr::tag()) - ->footer(Tfoot::tag()), + ->columns(new Col()) + ->header(new Thead()) + ->rows(new Tr()) + ->footer(new Tfoot()), ], ]; } @@ -321,7 +321,7 @@ public function testItemsOrder(string $expected, Table $tag): void public function testImmutability(): void { - $tag = Table::tag(); + $tag = new Table(); $this->assertNotSame($tag, $tag->caption(null)); $this->assertNotSame($tag, $tag->captionString('')); $this->assertNotSame($tag, $tag->columnGroups()); diff --git a/tests/Tag/TbodyTest.php b/tests/Tag/TbodyTest.php index c7d770fd..29005466 100644 --- a/tests/Tag/TbodyTest.php +++ b/tests/Tag/TbodyTest.php @@ -23,11 +23,11 @@ public function testBase(): void . 'D' . "\n" . '' . "\n" . '', - Tbody::tag() + (new Tbody()) ->class('gray') ->rows( - Tr::tag()->dataStrings(['A', 'B']), - Tr::tag()->dataStrings(['C', 'D']), + (new Tr())->dataStrings(['A', 'B']), + (new Tr())->dataStrings(['C', 'D']), ) ->render(), ); diff --git a/tests/Tag/TdTest.php b/tests/Tag/TdTest.php index 88503564..47407d7e 100644 --- a/tests/Tag/TdTest.php +++ b/tests/Tag/TdTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'hello', - Td::tag() + (new Td()) ->content('hello') ->render(), ); diff --git a/tests/Tag/TextareaTest.php b/tests/Tag/TextareaTest.php index 6eab4258..e77ebd37 100644 --- a/tests/Tag/TextareaTest.php +++ b/tests/Tag/TextareaTest.php @@ -13,7 +13,7 @@ final class TextareaTest extends TestCase { public function testBase(): void { - $textarea = Textarea::tag() + $textarea = (new Textarea()) ->name('body') ->value('content') ->rows(6); @@ -32,7 +32,7 @@ public static function dataProviderName(): array #[DataProvider('dataProviderName')] public function testName(string $expected, ?string $name): void { - $this->assertSame($expected, (string) Textarea::tag()->name($name)); + $this->assertSame($expected, (string) (new Textarea())->name($name)); } public static function dataRows(): array @@ -46,7 +46,7 @@ public static function dataRows(): array #[DataProvider('dataRows')] public function testRows(string $expected, ?int $rows): void { - $this->assertSame($expected, (string) Textarea::tag()->rows($rows)); + $this->assertSame($expected, (string) (new Textarea())->rows($rows)); } public static function dataColumns(): array @@ -60,7 +60,7 @@ public static function dataColumns(): array #[DataProvider('dataColumns')] public function testColumns(string $expected, ?int $columns): void { - $this->assertSame($expected, (string) Textarea::tag()->columns($columns)); + $this->assertSame($expected, (string) (new Textarea())->columns($columns)); } public static function dataValue(): array @@ -88,7 +88,7 @@ public static function dataValue(): array #[DataProvider('dataValue')] public function testValue(string $expected, mixed $value): void { - $this->assertSame($expected, (string) Textarea::tag()->value($value)); + $this->assertSame($expected, (string) (new Textarea())->value($value)); } public static function dataForm(): array @@ -103,14 +103,14 @@ public static function dataForm(): array #[DataProvider('dataForm')] public function testForm(string $expected, ?string $formId): void { - $this->assertSame($expected, Textarea::tag() + $this->assertSame($expected, (new Textarea()) ->form($formId) ->render()); } public function testImmutability(): void { - $textarea = Textarea::tag(); + $textarea = new Textarea(); $this->assertNotSame($textarea, $textarea->name(null)); $this->assertNotSame($textarea, $textarea->rows(null)); $this->assertNotSame($textarea, $textarea->columns(null)); diff --git a/tests/Tag/TfootTest.php b/tests/Tag/TfootTest.php index fa9c0526..276bc764 100644 --- a/tests/Tag/TfootTest.php +++ b/tests/Tag/TfootTest.php @@ -23,11 +23,11 @@ public function testBase(): void . 'D' . "\n" . '' . "\n" . '', - Tfoot::tag() + (new Tfoot()) ->class('gray') ->rows( - Tr::tag()->dataStrings(['A', 'B']), - Tr::tag()->dataStrings(['C', 'D']), + (new Tr())->dataStrings(['A', 'B']), + (new Tr())->dataStrings(['C', 'D']), ) ->render(), ); diff --git a/tests/Tag/ThTest.php b/tests/Tag/ThTest.php index 1baf9c4c..b1846b26 100644 --- a/tests/Tag/ThTest.php +++ b/tests/Tag/ThTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'hello', - Th::tag() + (new Th()) ->content('hello') ->render(), ); diff --git a/tests/Tag/TheadTest.php b/tests/Tag/TheadTest.php index e1115619..09530128 100644 --- a/tests/Tag/TheadTest.php +++ b/tests/Tag/TheadTest.php @@ -23,11 +23,11 @@ public function testBase(): void . 'D' . "\n" . '' . "\n" . '', - Thead::tag() + (new Thead()) ->class('gray') ->rows( - Tr::tag()->dataStrings(['A', 'B']), - Tr::tag()->dataStrings(['C', 'D']), + (new Tr())->dataStrings(['A', 'B']), + (new Tr())->dataStrings(['C', 'D']), ) ->render(), ); diff --git a/tests/Tag/TitleTest.php b/tests/Tag/TitleTest.php index e4b5c052..1e7a8086 100644 --- a/tests/Tag/TitleTest.php +++ b/tests/Tag/TitleTest.php @@ -13,7 +13,7 @@ public function testBase(): void { $this->assertSame( 'Hello, World!', - (string) Title::tag()->content('Hello, World!'), + (string) (new Title())->content('Hello, World!'), ); } } diff --git a/tests/Tag/TrTest.php b/tests/Tag/TrTest.php index 5027d225..6fd75942 100644 --- a/tests/Tag/TrTest.php +++ b/tests/Tag/TrTest.php @@ -19,7 +19,7 @@ public function testBase(): void . 'Two' . "\n" . 'Three' . "\n" . '', - Tr::tag() + (new Tr()) ->class('row') ->dataStrings(['One', 'Two', 'Three'], ['class' => 'cell']) ->render(), @@ -28,9 +28,9 @@ public function testBase(): void public function testCells(): void { - $tr = Tr::tag()->cells( - Th::tag()->content('A'), - Td::tag()->content('B'), + $tr = (new Tr())->cells( + (new Th())->content('A'), + (new Td())->content('B'), ); $this->assertSame("\nA\nB\n", (string) $tr); @@ -38,16 +38,16 @@ public function testCells(): void public function testAddCells(): void { - $tr = Tr::tag() - ->cells(Td::tag()->content('A')) - ->addCells(Td::tag()->content('B')); + $tr = (new Tr()) + ->cells((new Td())->content('A')) + ->addCells((new Td())->content('B')); $this->assertSame("\nA\nB\n", (string) $tr); } public function testDataStrings(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->dataStrings(['A', 'B']); $this->assertSame("\nA\nB\n", (string) $tr); @@ -55,7 +55,7 @@ public function testDataStrings(): void public function testDataStringsAttributes(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->dataStrings(['A', 'B'], ['class' => 'red']); $this->assertSame("\nA\nB\n", (string) $tr); @@ -63,7 +63,7 @@ public function testDataStringsAttributes(): void public function testDataStringsEncode(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->dataStrings(['A > B']); $this->assertSame("\nA > B\n", (string) $tr); @@ -71,7 +71,7 @@ public function testDataStringsEncode(): void public function testDataStringsWithoutEncode(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->dataStrings(['A'], [], false); $this->assertSame("\nA\n", (string) $tr); @@ -79,7 +79,7 @@ public function testDataStringsWithoutEncode(): void public function testAddDataStrings(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->dataStrings(['A']) ->addDataStrings(['B', 'C']); @@ -88,7 +88,7 @@ public function testAddDataStrings(): void public function testAddDataStringsAttributes(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->dataStrings(['A']) ->addDataStrings(['B'], ['class' => 'red']); @@ -97,7 +97,7 @@ public function testAddDataStringsAttributes(): void public function testAddDataStringsEncode(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->dataStrings(['A']) ->addDataStrings(['B > 1']); @@ -106,7 +106,7 @@ public function testAddDataStringsEncode(): void public function testAddDataStringsWithoutEncode(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->dataStrings(['A']) ->addDataStrings(['B'], [], false); @@ -115,7 +115,7 @@ public function testAddDataStringsWithoutEncode(): void public function testHeaderStrings(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->headerStrings(['A', 'B']); $this->assertSame("\nA\nB\n", (string) $tr); @@ -123,7 +123,7 @@ public function testHeaderStrings(): void public function testHeaderStringsAttributes(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->headerStrings(['A', 'B'], ['class' => 'red']); $this->assertSame("\nA\nB\n", (string) $tr); @@ -131,7 +131,7 @@ public function testHeaderStringsAttributes(): void public function testHeaderStringsEncode(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->headerStrings(['A > B']); $this->assertSame("\nA > B\n", (string) $tr); @@ -139,7 +139,7 @@ public function testHeaderStringsEncode(): void public function testHeaderStringsWithoutEncode(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->headerStrings(['A'], [], false); $this->assertSame("\nA\n", (string) $tr); @@ -147,7 +147,7 @@ public function testHeaderStringsWithoutEncode(): void public function testAddHeaderStrings(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->headerStrings(['A']) ->addHeaderStrings(['B', 'C']); @@ -156,7 +156,7 @@ public function testAddHeaderStrings(): void public function testAddHeaderStringsAttributes(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->headerStrings(['A']) ->addHeaderStrings(['B'], ['class' => 'red']); @@ -165,7 +165,7 @@ public function testAddHeaderStringsAttributes(): void public function testAddHeaderStringsEncode(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->headerStrings(['A']) ->addHeaderStrings(['B > 1']); @@ -174,7 +174,7 @@ public function testAddHeaderStringsEncode(): void public function testAddHeaderStringsWithoutEncode(): void { - $tr = Tr::tag() + $tr = (new Tr()) ->headerStrings(['A']) ->addHeaderStrings(['B'], [], false); @@ -183,7 +183,7 @@ public function testAddHeaderStringsWithoutEncode(): void public function testImmutability(): void { - $tr = Tr::tag(); + $tr = new Tr(); $this->assertNotSame($tr, $tr->cells()); $this->assertNotSame($tr, $tr->addCells()); $this->assertNotSame($tr, $tr->dataStrings([])); diff --git a/tests/Tag/TrackTest.php b/tests/Tag/TrackTest.php index 69b94090..eb55f2f4 100644 --- a/tests/Tag/TrackTest.php +++ b/tests/Tag/TrackTest.php @@ -14,7 +14,7 @@ public function testBase(): void { $this->assertSame( '', - (string) Track::tag() + (string) (new Track()) ->kind(Track::SUBTITLES) ->src('brave.en.vtt') ->srclang('en') @@ -24,20 +24,20 @@ public function testBase(): void public function testDefault(): void { - $this->assertSame('', (string) Track::tag()->default()); - $this->assertSame('', (string) Track::tag()->default(false)); - $this->assertSame('', (string) Track::tag() + $this->assertSame('', (string) (new Track())->default()); + $this->assertSame('', (string) (new Track())->default(false)); + $this->assertSame('', (string) (new Track()) ->default(true) ->default(false)); } public function testIsDefault(): void { - $this->assertFalse(Track::tag()->isDefault()); - $this->assertFalse(Track::tag() + $this->assertFalse((new Track())->isDefault()); + $this->assertFalse((new Track()) ->default(false) ->isDefault()); - $this->assertTrue(Track::tag() + $this->assertTrue((new Track()) ->default() ->isDefault()); } @@ -53,7 +53,7 @@ public static function dataKind(): array #[DataProvider('dataKind')] public function testKind(string $expected, ?string $kind): void { - $this->assertSame($expected, (string) Track::tag()->kind($kind)); + $this->assertSame($expected, (string) (new Track())->kind($kind)); } public static function dataLabel(): array @@ -67,14 +67,14 @@ public static function dataLabel(): array #[DataProvider('dataLabel')] public function testLabel(string $expected, ?string $label): void { - $this->assertSame($expected, (string) Track::tag()->label($label)); + $this->assertSame($expected, (string) (new Track())->label($label)); } public function testSrc(): void { $this->assertSame( '', - (string) Track::tag()->src('brave.en.vtt'), + (string) (new Track())->src('brave.en.vtt'), ); } @@ -89,12 +89,12 @@ public static function dataSrclang(): array #[DataProvider('dataSrclang')] public function testSrclang(string $expected, ?string $lang): void { - $this->assertSame($expected, (string) Track::tag()->srclang($lang)); + $this->assertSame($expected, (string) (new Track())->srclang($lang)); } public function testImmutability(): void { - $track = Track::tag(); + $track = new Track(); $this->assertNotSame($track, $track->default()); $this->assertNotSame($track, $track->kind(null)); $this->assertNotSame($track, $track->label(null)); diff --git a/tests/Tag/UlTest.php b/tests/Tag/UlTest.php index a2eef02b..ef2bc697 100644 --- a/tests/Tag/UlTest.php +++ b/tests/Tag/UlTest.php @@ -12,9 +12,9 @@ final class UlTest extends TestCase { public function testBase(): void { - $ul = Ul::tag()->items( - Li::tag()->content('A'), - Li::tag()->content('B'), + $ul = (new Ul())->items( + (new Li())->content('A'), + (new Li())->content('B'), ); $this->assertSame("
      \n
    • A
    • \n
    • B
    • \n
    ", (string) $ul); diff --git a/tests/Tag/VideoTest.php b/tests/Tag/VideoTest.php index b0a8b586..5a3e9c63 100644 --- a/tests/Tag/VideoTest.php +++ b/tests/Tag/VideoTest.php @@ -21,10 +21,10 @@ public function testBase(): void . '' . "\n" . 'Your browser does not support video.' . "\n" . '', - (string) Video::tag() + (string) (new Video()) ->controls() - ->sources(Source::tag()->src('a.mp4'), Source::tag()->src('b.avi')) - ->tracks(Track::tag()->src('c.mp4')) + ->sources((new Source())->src('a.mp4'), (new Source())->src('b.avi')) + ->tracks((new Track())->src('c.mp4')) ->fallback('Your browser does not support video.'), ); } @@ -40,7 +40,7 @@ public static function dataPoster(): array #[DataProvider('dataPoster')] public function testPoster(string $expected, ?string $poster): void { - $this->assertSame($expected, (string) Video::tag()->poster($poster)); + $this->assertSame($expected, (string) (new Video())->poster($poster)); } public static function dataWidth(): array @@ -55,7 +55,7 @@ public static function dataWidth(): array #[DataProvider('dataWidth')] public function testWidth(string $expected, $width): void { - $this->assertSame($expected, (string) Video::tag()->width($width)); + $this->assertSame($expected, (string) (new Video())->width($width)); } public static function dataHeight(): array @@ -70,12 +70,12 @@ public static function dataHeight(): array #[DataProvider('dataHeight')] public function testHeight(string $expected, $height): void { - $this->assertSame($expected, (string) Video::tag()->height($height)); + $this->assertSame($expected, (string) (new Video())->height($height)); } public function testImmutability(): void { - $tag = Video::tag(); + $tag = new Video(); $this->assertNotSame($tag, $tag->poster(null)); $this->assertNotSame($tag, $tag->width(null)); $this->assertNotSame($tag, $tag->height(null)); diff --git a/tests/Widget/ButtonGroupTest.php b/tests/Widget/ButtonGroupTest.php index 8ec51357..57d84157 100644 --- a/tests/Widget/ButtonGroupTest.php +++ b/tests/Widget/ButtonGroupTest.php @@ -13,6 +13,25 @@ final class ButtonGroupTest extends TestCase { public function testBase(): void + { + $widget = (new ButtonGroup()) + ->buttons( + Html::resetButton('Reset Data'), + Html::submitButton('Send'), + ); + + $this->assertStringContainsStringIgnoringLineEndings( + << + + + + HTML, + $widget->render(), + ); + } + + public function testCreate(): void { $widget = ButtonGroup::create() ->buttons( @@ -33,12 +52,12 @@ public function testBase(): void public function testWithoutButtons(): void { - $this->assertSame('', ButtonGroup::create()->render()); + $this->assertSame('', (new ButtonGroup())->render()); } public function testButtonsData(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttonsData([ ['Reset Data', 'type' => 'reset'], ['Send >', 'type' => 'submit', 'class' => 'primary'], @@ -74,7 +93,7 @@ public static function dataButtonsDataEncode(): array #[DataProvider('dataButtonsDataEncode')] public function testButtonsDataEncode(string $expected, string $label, ?bool $encode): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttonsData( [ [$label], @@ -88,7 +107,7 @@ public function testButtonsDataEncode(string $expected, string $label, ?bool $en public function testInvalidButtonsData(): void { - $widget = ButtonGroup::create(); + $widget = new ButtonGroup(); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( @@ -100,7 +119,7 @@ public function testInvalidButtonsData(): void public function testWithoutContainer(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::resetButton('Reset Data'), Html::submitButton('Send'), @@ -141,7 +160,7 @@ public static function dataContainerTag(): array #[DataProvider('dataContainerTag')] public function testContainerTag(string $expected, ?string $tagName): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons(Html::button('Show')) ->containerTag($tagName); @@ -150,7 +169,7 @@ public function testContainerTag(string $expected, ?string $tagName): void public function testBaseContainerAttributes(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons(Html::button('Show')) ->containerAttributes(['id' => 'actions']); @@ -166,7 +185,7 @@ public function testBaseContainerAttributes(): void public function testAddNewButtonAttributes(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::button('Show'), Html::button('Hide'), @@ -186,7 +205,7 @@ public function testAddNewButtonAttributes(): void public function testMergeButtonAttributes(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::button('Show'), Html::button('Hide'), @@ -208,7 +227,7 @@ public function testMergeButtonAttributes(): void public function testUnionButtonAttributes(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::button('Show')->class('red'), Html::button('Hide'), @@ -228,7 +247,7 @@ public function testUnionButtonAttributes(): void public function testReplaceButtonAttributes(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::button('Show'), Html::button('Hide'), @@ -277,7 +296,7 @@ public static function dataDisabled(): array #[DataProvider('dataDisabled')] public function testDisabled(string $expected, ?bool $disabled): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::button('Show'), Html::button('Hide'), @@ -311,7 +330,7 @@ public static function dataForm(): array #[DataProvider('dataForm')] public function testForm($expected, ?string $id): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::button('Show'), Html::button('Hide'), @@ -324,7 +343,7 @@ public function testForm($expected, ?string $id): void public function testSeparator(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::button('Show'), Html::button('Hide'), @@ -343,7 +362,7 @@ public function testSeparator(): void public function testStringable(): void { - $widget = ButtonGroup::create() + $widget = (new ButtonGroup()) ->buttons( Html::resetButton('Reset Data'), Html::submitButton('Send'), @@ -354,7 +373,7 @@ public function testStringable(): void public function testImmutability(): void { - $widget = ButtonGroup::create(); + $widget = new ButtonGroup(); $this->assertNotSame($widget, $widget->withoutContainer()); $this->assertNotSame($widget, $widget->containerTag(null)); diff --git a/tests/Widget/CheckboxListTest.php b/tests/Widget/CheckboxListTest.php index 52d3b9ed..6c5b1be4 100644 --- a/tests/Widget/CheckboxListTest.php +++ b/tests/Widget/CheckboxListTest.php @@ -25,7 +25,7 @@ public function testBase(): void . '' . "\n" . '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two', 5 => 'Five']) ->uncheckValue(0) ->value(2, 5) @@ -36,7 +36,7 @@ public function testBase(): void public function testName(): void { - $widget = CheckboxList::create('a') + $widget = (new CheckboxList('a')) ->items([1 => 'One']) ->name('b'); @@ -48,11 +48,24 @@ public function testName(): void ); } + public function testCreate(): void + { + $widget = CheckboxList::create('b') + ->items([1 => 'One']); + + $this->assertSame( + '
    ' . "\n" + . '' . "\n" + . '
    ', + $widget->render(), + ); + } + public function testWithoutContainer(): void { $this->assertSame( '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([1 => 'One']) ->withoutContainer() ->render(), @@ -84,7 +97,7 @@ public function testContainerTag(string $expected, ?string $name): void { $this->assertSame( $expected, - CheckboxList::create('test') + (new CheckboxList('test')) ->items([1 => 'One']) ->containerTag($name) ->render(), @@ -97,7 +110,7 @@ public function testContainerAttributes(): void '
    ' . "\n" . '' . "\n" . '
    ', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([1 => 'One']) ->containerAttributes(['id' => 'main']) ->render(), @@ -109,7 +122,7 @@ public function testCheckboxAttributes(): void $this->assertSame( '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -125,7 +138,7 @@ public function testCheckboxAttributesMerge(): void $this->assertSame( '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -142,7 +155,7 @@ public function testReplaceCheckboxAttributes(): void $this->assertSame( '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -159,7 +172,7 @@ public function testCheckboxLabelAttributes(): void $this->assertSame( '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two']) ->checkboxLabelAttributes(['class' => 'red']) ->withoutContainer() @@ -172,7 +185,7 @@ public function testCheckboxLabelAttributesMerge(): void $this->assertSame( '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two']) ->checkboxLabelAttributes(['class' => 'red']) ->addCheckboxLabelAttributes(['data-type' => 'label']) @@ -187,7 +200,7 @@ public function testAddIndividualInputAttributes(): void '' . "\n" . '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -209,7 +222,7 @@ public function testIndividualUncheckInputAttributes(): void '' . "\n" . '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -230,7 +243,7 @@ public function testIndividualInputAttributesMerge(): void '' . "\n" . '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -256,7 +269,7 @@ public function testIndividualInputAttributesReplace(): void '' . "\n" . '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -280,7 +293,7 @@ public function testItems(): void $this->assertSame( '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -295,7 +308,7 @@ public function testItemsWithoutEncodeLabel(): void $this->assertSame( '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -331,7 +344,7 @@ public function testItemsFromValues(string $expected, array $values): void { $this->assertSame( $expected, - CheckboxList::create('test') + (new CheckboxList('test')) ->itemsFromValues($values) ->withoutContainer() ->render(), @@ -343,7 +356,7 @@ public function testItemsFromValuesWithoutEncodeLabel(): void $this->assertSame( '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->itemsFromValues([ 'One', 'Two', @@ -459,28 +472,28 @@ public function testValue(string $expected, array $items, array $value): void { $this->assertSame( $expected, - CheckboxList::create('test') + (new CheckboxList('test')) ->items($items) ->value(...$value) ->render(), ); $this->assertSame( $expected, - CheckboxList::create('test') + (new CheckboxList('test')) ->items($items) ->values($value) ->render(), ); $this->assertSame( $expected, - CheckboxList::create('test') + (new CheckboxList('test')) ->items($items) ->values(new ArrayObject($value)) ->render(), ); $this->assertSame( $expected, - CheckboxList::create('test') + (new CheckboxList('test')) ->items($items) ->values(new IterableObject($value)) ->render(), @@ -519,7 +532,7 @@ public function testForm(string $expected, ?string $formId): void { $this->assertSame( $expected, - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -531,7 +544,7 @@ public function testForm(string $expected, ?string $formId): void public function testReadonly(): void { - $checkbox = CheckboxList::create('test') + $checkbox = (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -570,7 +583,7 @@ public function testReadonly(): void public function testDisabled(): void { - $checkbox = CheckboxList::create('test') + $checkbox = (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -652,7 +665,7 @@ public function testUncheckValue(string $expected, string $name, $value): void { $this->assertSame( $expected, - CheckboxList::create($name) + (new CheckboxList($name)) ->items([ 1 => 'One', 2 => 'Two', @@ -668,7 +681,7 @@ public function testUncheckValueDisabled(): void '' . "\n" . '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -686,7 +699,7 @@ public function testUncheckValueForm(): void '' . "\n" . '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -705,7 +718,7 @@ public function testSeparator(): void . '
    ' . '' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two']) ->separator('
    ') ->render(), @@ -719,7 +732,7 @@ public function testItemFormatter(): void . '
    0)
    ' . '
    1)
    ' . "\n" . '', - CheckboxList::create('test') + (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two']) ->itemFormatter(fn(CheckboxItem $item): string => '
    ' . $item->index . ') ' @@ -738,7 +751,7 @@ public function testItemFormatter(): void public function testDisableCheckboxLabelWrap(): void { - $html = CheckboxList::create('test') + $html = (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two']) ->addIndividualInputAttributes([ 1 => ['id' => 'id1'], @@ -760,7 +773,7 @@ public function testDisableCheckboxLabelWrap(): void public function testCheckboxWrap(): void { - $html = CheckboxList::create('test') + $html = (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two']) ->checkboxWrapTag('div') ->checkboxWrapAttributes(['class' => 'form-check']) @@ -796,7 +809,7 @@ public static function dataCheckboxWrapClass(): array #[DataProvider('dataCheckboxWrapClass')] public function testCheckboxWrapClass(string $expected, array $class): void { - $html = CheckboxList::create('test') + $html = (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two']) ->checkboxWrapTag('div') ->checkboxWrapAttributes(['class' => 'form-check']) @@ -832,7 +845,7 @@ public static function dataAddCheckboxWrapClass(): array #[DataProvider('dataAddCheckboxWrapClass')] public function testAddCheckboxWrapClass(string $expected, array $class): void { - $html = CheckboxList::create('test') + $html = (new CheckboxList('test')) ->items([1 => 'One', 2 => 'Two']) ->checkboxWrapTag('div') ->checkboxWrapAttributes(['class' => 'form-check']) @@ -858,13 +871,13 @@ public function testStringable(): void { $this->assertSame( "
    \n
    ", - (string) CheckboxList::create('test'), + (string) new CheckboxList('test'), ); } public function testImmutability(): void { - $widget = CheckboxList::create('test'); + $widget = new CheckboxList('test'); $this->assertNotSame($widget, $widget->name('test')); $this->assertNotSame($widget, $widget->withoutContainer()); $this->assertNotSame($widget, $widget->containerTag('')); diff --git a/tests/Widget/RadioListTest.php b/tests/Widget/RadioListTest.php index 48139d3e..35d70adb 100644 --- a/tests/Widget/RadioListTest.php +++ b/tests/Widget/RadioListTest.php @@ -15,6 +15,24 @@ final class RadioListTest extends TestCase { public function testBase(): void + { + $this->assertSame( + '' . "\n" + . '
    ' . "\n" + . '' . "\n" + . '' . "\n" + . '' . "\n" + . '
    ', + (new RadioList('test')) + ->items([1 => 'One', 2 => 'Two', 5 => 'Five']) + ->uncheckValue(0) + ->value(2) + ->containerAttributes(['id' => 'main']) + ->render(), + ); + } + + public function testCreate(): void { $this->assertSame( '' . "\n" @@ -34,7 +52,7 @@ public function testBase(): void public function testName(): void { - $widget = RadioList::create('a') + $widget = (new RadioList('a')) ->items([1 => 'One']) ->name('b'); @@ -50,7 +68,7 @@ public function testWithoutContainer(): void { $this->assertSame( '', - RadioList::create('test') + (new RadioList('test')) ->items([1 => 'One']) ->withoutContainer() ->render(), @@ -82,7 +100,7 @@ public function testContainerTag(string $expected, ?string $name): void { $this->assertSame( $expected, - RadioList::create('test') + (new RadioList('test')) ->items([1 => 'One']) ->containerTag($name) ->render(), @@ -95,7 +113,7 @@ public function testContainerAttributes(): void '
    ' . "\n" . '' . "\n" . '
    ', - RadioList::create('test') + (new RadioList('test')) ->items([1 => 'One']) ->containerAttributes(['id' => 'main']) ->render(), @@ -107,7 +125,7 @@ public function testRadioAttributes(): void $this->assertSame( '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -123,7 +141,7 @@ public function testRadioAttributesMerge(): void $this->assertSame( '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -140,7 +158,7 @@ public function testReplaceRadioAttributes(): void $this->assertSame( '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -157,7 +175,7 @@ public function testRadioLabelAttributes(): void $this->assertSame( '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([1 => 'One', 2 => 'Two']) ->radioLabelAttributes(['class' => 'red']) ->withoutContainer() @@ -170,7 +188,7 @@ public function testRadioLabelAttributesMerge(): void $this->assertSame( '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([1 => 'One', 2 => 'Two']) ->radioLabelAttributes(['class' => 'red']) ->addRadioLabelAttributes(['data-type' => 'label']) @@ -185,7 +203,7 @@ public function testIndividualInputAttributes(): void '' . "\n" . '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -207,7 +225,7 @@ public function testIndividualUncheckInputAttributes(): void '' . "\n" . '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -228,7 +246,7 @@ public function testIndividualInputAttributesMerge(): void '' . "\n" . '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -254,7 +272,7 @@ public function testIndividualInputAttributesReplace(): void '' . "\n" . '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -278,7 +296,7 @@ public function testItems(): void $this->assertSame( '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -293,7 +311,7 @@ public function testItemsWithoutEncodeLabel(): void $this->assertSame( '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -329,7 +347,7 @@ public function testItemsFromValues(string $expected, array $values): void { $this->assertSame( $expected, - RadioList::create('test') + (new RadioList('test')) ->itemsFromValues($values) ->withoutContainer() ->render(), @@ -341,7 +359,7 @@ public function testItemsFromValuesWithoutEncodeLabel(): void $this->assertSame( '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->itemsFromValues([ 'One', 'Two', @@ -430,7 +448,7 @@ public function testValue(string $expected, array $items, $value): void { $this->assertSame( $expected, - RadioList::create('test') + (new RadioList('test')) ->items($items) ->value($value) ->render(), @@ -469,7 +487,7 @@ public function testForm(string $expected, ?string $formId): void { $this->assertSame( $expected, - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -481,7 +499,7 @@ public function testForm(string $expected, ?string $formId): void public function testReadonly(): void { - $checkbox = RadioList::create('test') + $checkbox = (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -520,7 +538,7 @@ public function testReadonly(): void public function testDisabled(): void { - $checkbox = RadioList::create('test') + $checkbox = (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -602,7 +620,7 @@ public function testUncheckValue(string $expected, string $name, $value): void { $this->assertSame( $expected, - RadioList::create($name) + (new RadioList($name)) ->items([ 1 => 'One', 2 => 'Two', @@ -618,7 +636,7 @@ public function testUncheckValueDisabled(): void '' . "\n" . '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -636,7 +654,7 @@ public function testUncheckValueForm(): void '' . "\n" . '' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([ 1 => 'One', 2 => 'Two', @@ -655,7 +673,7 @@ public function testSeparator(): void . '
    ' . '' . "\n" . '
    ', - RadioList::create('test') + (new RadioList('test')) ->items([1 => 'One', 2 => 'Two']) ->separator('
    ') ->render(), @@ -669,7 +687,7 @@ public function testItemFormatter(): void . '
    0)
    ' . '
    1)
    ' . "\n" . '', - RadioList::create('test') + (new RadioList('test')) ->items([1 => 'One', 2 => 'Two']) ->itemFormatter(fn(RadioItem $item): string => '
    ' . $item->index . ') ' @@ -688,7 +706,7 @@ public function testItemFormatter(): void public function testDisableRadioLabelWrap(): void { - $html = RadioList::create('test') + $html = (new RadioList('test')) ->items([1 => 'One', 2 => 'Two']) ->addIndividualInputAttributes([ 1 => ['id' => 'id1'], @@ -710,7 +728,7 @@ public function testDisableRadioLabelWrap(): void public function testRadioWrap(): void { - $html = RadioList::create('test') + $html = (new RadioList('test')) ->items([1 => 'One', 2 => 'Two']) ->radioWrapTag('div') ->radioWrapAttributes(['class' => 'form-check']) @@ -747,7 +765,7 @@ public static function dataRadioWrapClass(): array #[DataProvider('dataRadioWrapClass')] public function testRadioWrapClass(string $expected, array $class): void { - $html = RadioList::create('test') + $html = (new RadioList('test')) ->items([1 => 'One', 2 => 'Two']) ->radioWrapTag('div') ->radioWrapAttributes(['class' => 'form-check']) @@ -784,7 +802,7 @@ public static function dataAddRadioWrapClass(): array #[DataProvider('dataAddRadioWrapClass')] public function testAddRadioWrapClass(string $expected, array $class): void { - $html = RadioList::create('test') + $html = (new RadioList('test')) ->items([1 => 'One', 2 => 'Two']) ->radioWrapTag('div') ->radioWrapAttributes(['class' => 'form-check']) @@ -810,13 +828,13 @@ public function testStringable(): void { $this->assertSame( "
    \n
    ", - (string) RadioList::create('test'), + (string) new RadioList('test'), ); } public function testImmutability(): void { - $widget = RadioList::create('test'); + $widget = new RadioList('test'); $this->assertNotSame($widget, $widget->name('test')); $this->assertNotSame($widget, $widget->withoutContainer()); $this->assertNotSame($widget, $widget->containerTag(''));