Skip to content

Commit

Permalink
refs #10 Added static method
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Jul 21, 2024
1 parent ba24f6c commit 9072a68
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/Icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Support\Arr;
use Illuminate\Support\HtmlString;
use DOMDocument;
use Stringable;

class Icon extends HtmlString implements Stringable
Expand Down
11 changes: 11 additions & 0 deletions src/IconComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Orchid\Icons;

use Illuminate\View\Component;
use Illuminate\View\View;

class IconComponent extends Component
{
Expand Down Expand Up @@ -96,4 +97,14 @@ public function render(): callable
]);
};
}

/**
* @param ...$params
*
* @return \Illuminate\View\View
*/
public static function make(...$params): View
{
return resolve(static::class, $params)->render()();
}
}
29 changes: 22 additions & 7 deletions tests/BladeComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Orchid\Icons\Tests;

use Illuminate\Support\Facades\Blade;
use Orchid\Icons\IconComponent;
use Orchid\Icons\IconFinder;

class BladeComponentTest extends TestUnitCase
Expand All @@ -16,7 +17,6 @@ protected function setUp(): void
$this->artisan('view:clear');
}


public function testWithPrefixComponent(): void
{
$this->app->make(IconFinder::class)
Expand Down Expand Up @@ -121,19 +121,34 @@ public function testHtmlAttributesDuplicate(): void
$this->assertStringContainsString('id="2"', $view);
}

/**
* @return void
*/
public function testAverageSpeed()
public function testAverageSpeed(): void
{
$this->app->make(IconFinder::class)
->setSize('54px', '54px')
->registerIconDirectory('feather', __DIR__ . '/stubs/feather');


collect(range(0, 10000))->each(function (int $key){
collect(range(0, 10000))->each(function (int $key) {
$view = Blade::render('<x-orchid-icon path="feather.alert-triangle" id="2" :id="$id" />', ['id' => $key]);
$this->assertStringContainsString('id="'.$key, $view);
$this->assertStringContainsString('id="' . $key, $view);
});
}

public function testStaticRender():void
{
$this->app->make(IconFinder::class)
->setSize('54px', '54px')
->registerIconDirectory('feather', __DIR__ . '/stubs/feather');

$view = IconComponent::make(
path: 'feather.alert-triangle',
id: 2,
class: 'test',
);

$this->assertStringContainsString('id="2"', $view->toHtml());
$this->assertStringContainsString('class="test"', $view->toHtml());
$this->assertStringContainsString('stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"', (string) $view);
}

}

0 comments on commit 9072a68

Please sign in to comment.