Skip to content

Commit 60060eb

Browse files
authored
Merge pull request #13 from eXolnet/feature/spatie-laravel-html-migration
feat: migrate laravelcollective/html to spatie/laravel-html
2 parents 8d8534a + c3e6be7 commit 60060eb

File tree

7 files changed

+26
-47
lines changed

7 files changed

+26
-47
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ jobs:
4040
extensions: json, dom, curl, libxml, mbstring
4141
coverage: none
4242

43-
- name: Contraint HTML Collective on PHP 8
44-
if: ${{matrix.php == '8.0'}}
45-
run: composer require "laravelcollective/html:^6.2.1" --no-interaction --no-update
46-
4743
- name: Install dependencies
4844
run: |
4945
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require": {
2424
"php": "^8.0",
2525
"illuminate/support": "^9.0|^10.0",
26-
"laravelcollective/html": "^6.3"
26+
"spatie/laravel-html": "^3.2"
2727
},
2828
"require-dev": {
2929
"exolnet/phpcs-config": "^2.0",

src/HtmlList.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Exolnet\HtmlList;
44

5-
use Collective\Html\FormFacade;
65
use Exolnet\HtmlList\Items\HtmlItem;
76
use Illuminate\Support\Collection;
8-
use Illuminate\Support\HtmlString;
7+
use Spatie\Html\Elements\Select;
8+
use Spatie\Html\Facades\Html;
99

1010
class HtmlList extends Collection
1111
{
@@ -159,25 +159,10 @@ public function buildArray(): array
159159
/**
160160
* @param string $name
161161
* @param mixed $selected
162-
* @param array $selectAttributes
163-
* @param array $optionsAttributes
164-
* @param array $optgroupsAttributes
165-
* @return \Illuminate\Support\HtmlString
162+
* @return \Spatie\Html\Elements\Select
166163
*/
167-
public function select(
168-
string $name,
169-
$selected = null,
170-
array $selectAttributes = [],
171-
array $optionsAttributes = [],
172-
array $optgroupsAttributes = []
173-
): HtmlString {
174-
return FormFacade::select(
175-
$name,
176-
$this->buildArray(),
177-
$selected,
178-
$selectAttributes,
179-
$optionsAttributes,
180-
$optgroupsAttributes
181-
);
164+
public function select(string $name, $selected = null): Select
165+
{
166+
return Html::select($name, $this->buildArray(), $selected);
182167
}
183168
}

src/HtmlListItem.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Exolnet\HtmlList;
44

5-
use Collective\Html\FormFacade;
65
use Exolnet\HtmlList\Items\HtmlItem;
7-
use Illuminate\Support\HtmlString;
6+
use Spatie\Html\Elements\Input;
7+
use Spatie\Html\Facades\Html;
88

99
class HtmlListItem
1010
{
@@ -95,21 +95,21 @@ public function setHtmlItem(HtmlItem $htmlItem): self
9595
* @param string $name
9696
* @param bool $checked
9797
* @param array $options
98-
* @return \Illuminate\Support\HtmlString
98+
* @return \Spatie\Html\Elements\Input
9999
*/
100-
public function checkbox(string $name, ?bool $checked = null, array $options = []): HtmlString
100+
public function checkbox(string $name, ?bool $checked = null, array $options = []): Input
101101
{
102-
return FormFacade::checkbox($name, $this->getKey(), $checked, $options);
102+
return Html::checkbox($name, $checked, $this->getKey())->attributes($options);
103103
}
104104

105105
/**
106106
* @param string $name
107107
* @param bool $checked
108108
* @param array $options
109-
* @return \Illuminate\Support\HtmlString
109+
* @return \Spatie\Html\Elements\Input
110110
*/
111-
public function radio(string $name, ?bool $checked = null, array $options = []): HtmlString
111+
public function radio(string $name, ?bool $checked = null, array $options = []): Input
112112
{
113-
return FormFacade::radio($name, $this->getKey(), $checked, $options);
113+
return Html::radio($name, $checked, $this->getKey())->attributes($options);
114114
}
115115
}

tests/Integration/HtmlListItemTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ public function testCheckbox()
1010
{
1111
$item = new HtmlListItem('Checkbox', 999);
1212

13-
$checkbox = $item->checkbox('checkbox');
13+
$checkbox = $item->checkbox('checkbox')->toHtml();
1414

15-
$this->assertEquals('<input name="checkbox" type="checkbox" value="999">', $checkbox);
15+
$this->assertEquals('<input type="checkbox" name="checkbox" id="checkbox" value="999">', $checkbox);
1616
}
1717

1818
public function testRadio()
1919
{
2020
$item = new HtmlListItem('Radio', 999);
2121

22-
$radio = $item->radio('radio');
22+
$radio = $item->radio('radio')->toHtml();
2323

24-
$this->assertEquals('<input name="radio" type="radio" value="999">', $radio);
24+
$this->assertEquals('<input type="radio" name="radio" id="radio_999" value="999">', $radio);
2525
}
2626
}

tests/Integration/HtmlListTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ public function testSelect()
160160
/** @var HtmlList $actual */
161161
$htmlList = $collection->toHtmlList();
162162

163-
$select = $htmlList->select('select');
163+
$select = $htmlList->select('select')->toHtml();
164164

165-
$this->assertEquals('<select name="select"><option value="9999">AAAAA</option></select>', $select);
165+
$this->assertEquals('<select name="select" id="select"><option value="9999">AAAAA</option></select>', $select);
166166
}
167167

168168
public function testSelectWithEmptyLabel()
@@ -179,10 +179,10 @@ public function testSelectWithEmptyLabel()
179179
$htmlList = $collection->toHtmlList();
180180
$htmlList->allowEmpty('Empty Label');
181181

182-
$select = $htmlList->select('select');
182+
$select = $htmlList->select('select')->toHtml();
183183

184184
$this->assertEquals(
185-
'<select name="select"><option value="" selected="selected">Empty Label</option><option value="9999">Second element label</option></select>', // phpcs:ignore
185+
'<select name="select" id="select"><option value>Empty Label</option><option value="9999">Second element label</option></select>', // phpcs:ignore
186186
$select
187187
);
188188
}

tests/Integration/TestCase.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace Exolnet\HtmlList\Tests\Integration;
44

5-
use Collective\Html\FormFacade;
6-
use Collective\Html\HtmlFacade;
7-
use Collective\Html\HtmlServiceProvider;
85
use Exolnet\HtmlList\HtmlListServiceProvider;
96
use Orchestra\Testbench\TestCase as Orchestra;
7+
use Spatie\Html\Facades\Html;
8+
use Spatie\Html\HtmlServiceProvider;
109

1110
abstract class TestCase extends Orchestra
1211
{
@@ -26,8 +25,7 @@ protected function getPackageProviders($app)
2625
protected function getPackageAliases($app)
2726
{
2827
return [
29-
'form' => FormFacade::class,
30-
'Html' => HtmlFacade::class,
28+
'Html' => Html::class,
3129
];
3230
}
3331
}

0 commit comments

Comments
 (0)