Skip to content

Commit

Permalink
Merge pull request #13 from eXolnet/feature/spatie-laravel-html-migra…
Browse files Browse the repository at this point in the history
…tion

feat: migrate laravelcollective/html to spatie/laravel-html
  • Loading branch information
Gandhi11 authored Jul 10, 2023
2 parents 8d8534a + c3e6be7 commit 60060eb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 47 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ jobs:
extensions: json, dom, curl, libxml, mbstring
coverage: none

- name: Contraint HTML Collective on PHP 8
if: ${{matrix.php == '8.0'}}
run: composer require "laravelcollective/html:^6.2.1" --no-interaction --no-update

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require": {
"php": "^8.0",
"illuminate/support": "^9.0|^10.0",
"laravelcollective/html": "^6.3"
"spatie/laravel-html": "^3.2"
},
"require-dev": {
"exolnet/phpcs-config": "^2.0",
Expand Down
27 changes: 6 additions & 21 deletions src/HtmlList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Exolnet\HtmlList;

use Collective\Html\FormFacade;
use Exolnet\HtmlList\Items\HtmlItem;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Spatie\Html\Elements\Select;
use Spatie\Html\Facades\Html;

class HtmlList extends Collection
{
Expand Down Expand Up @@ -159,25 +159,10 @@ public function buildArray(): array
/**
* @param string $name
* @param mixed $selected
* @param array $selectAttributes
* @param array $optionsAttributes
* @param array $optgroupsAttributes
* @return \Illuminate\Support\HtmlString
* @return \Spatie\Html\Elements\Select
*/
public function select(
string $name,
$selected = null,
array $selectAttributes = [],
array $optionsAttributes = [],
array $optgroupsAttributes = []
): HtmlString {
return FormFacade::select(
$name,
$this->buildArray(),
$selected,
$selectAttributes,
$optionsAttributes,
$optgroupsAttributes
);
public function select(string $name, $selected = null): Select
{
return Html::select($name, $this->buildArray(), $selected);
}
}
16 changes: 8 additions & 8 deletions src/HtmlListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Exolnet\HtmlList;

use Collective\Html\FormFacade;
use Exolnet\HtmlList\Items\HtmlItem;
use Illuminate\Support\HtmlString;
use Spatie\Html\Elements\Input;
use Spatie\Html\Facades\Html;

class HtmlListItem
{
Expand Down Expand Up @@ -95,21 +95,21 @@ public function setHtmlItem(HtmlItem $htmlItem): self
* @param string $name
* @param bool $checked
* @param array $options
* @return \Illuminate\Support\HtmlString
* @return \Spatie\Html\Elements\Input
*/
public function checkbox(string $name, ?bool $checked = null, array $options = []): HtmlString
public function checkbox(string $name, ?bool $checked = null, array $options = []): Input
{
return FormFacade::checkbox($name, $this->getKey(), $checked, $options);
return Html::checkbox($name, $checked, $this->getKey())->attributes($options);
}

/**
* @param string $name
* @param bool $checked
* @param array $options
* @return \Illuminate\Support\HtmlString
* @return \Spatie\Html\Elements\Input
*/
public function radio(string $name, ?bool $checked = null, array $options = []): HtmlString
public function radio(string $name, ?bool $checked = null, array $options = []): Input
{
return FormFacade::radio($name, $this->getKey(), $checked, $options);
return Html::radio($name, $checked, $this->getKey())->attributes($options);
}
}
8 changes: 4 additions & 4 deletions tests/Integration/HtmlListItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ public function testCheckbox()
{
$item = new HtmlListItem('Checkbox', 999);

$checkbox = $item->checkbox('checkbox');
$checkbox = $item->checkbox('checkbox')->toHtml();

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

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

$radio = $item->radio('radio');
$radio = $item->radio('radio')->toHtml();

$this->assertEquals('<input name="radio" type="radio" value="999">', $radio);
$this->assertEquals('<input type="radio" name="radio" id="radio_999" value="999">', $radio);
}
}
8 changes: 4 additions & 4 deletions tests/Integration/HtmlListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ public function testSelect()
/** @var HtmlList $actual */
$htmlList = $collection->toHtmlList();

$select = $htmlList->select('select');
$select = $htmlList->select('select')->toHtml();

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

public function testSelectWithEmptyLabel()
Expand All @@ -179,10 +179,10 @@ public function testSelectWithEmptyLabel()
$htmlList = $collection->toHtmlList();
$htmlList->allowEmpty('Empty Label');

$select = $htmlList->select('select');
$select = $htmlList->select('select')->toHtml();

$this->assertEquals(
'<select name="select"><option value="" selected="selected">Empty Label</option><option value="9999">Second element label</option></select>', // phpcs:ignore
'<select name="select" id="select"><option value>Empty Label</option><option value="9999">Second element label</option></select>', // phpcs:ignore
$select
);
}
Expand Down
8 changes: 3 additions & 5 deletions tests/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Exolnet\HtmlList\Tests\Integration;

use Collective\Html\FormFacade;
use Collective\Html\HtmlFacade;
use Collective\Html\HtmlServiceProvider;
use Exolnet\HtmlList\HtmlListServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;
use Spatie\Html\Facades\Html;
use Spatie\Html\HtmlServiceProvider;

abstract class TestCase extends Orchestra
{
Expand All @@ -26,8 +25,7 @@ protected function getPackageProviders($app)
protected function getPackageAliases($app)
{
return [
'form' => FormFacade::class,
'Html' => HtmlFacade::class,
'Html' => Html::class,
];
}
}

0 comments on commit 60060eb

Please sign in to comment.