Skip to content

Commit

Permalink
Windows build (#213)
Browse files Browse the repository at this point in the history
* Windows build

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Fix code styling

* wip

* wip

* wip

* Fix code styling

* wip

* Fix code styling

* wip

* wip

* Fix code styling

* wip

---------

Co-authored-by: driesvints <[email protected]>
  • Loading branch information
driesvints and driesvints authored Jun 9, 2023
1 parent 156e165 commit 4d6b6b2
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 42 deletions.
34 changes: 32 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- cron: '0 0 * * *'

jobs:
tests:
ubuntu:
runs-on: ubuntu-latest

strategy:
Expand All @@ -28,7 +28,7 @@ jobs:
- php: 8.2
laravel: 8

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
name: Ubuntu - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
Expand All @@ -48,3 +48,33 @@ jobs:
- name: Execute tests
run: vendor/bin/phpunit --verbose

windows:
runs-on: windows-latest

strategy:
fail-fast: true
matrix:
php: [8.2]
laravel: [10]

name: Windows - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, pdo_mysql, fileinfo, ftp, gmp
coverage: none

- name: Install dependencies
run: |
composer require "illuminate/contracts=^${{ matrix.laravel }}" --prefer-dist --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/phpunit --verbose
1 change: 1 addition & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"notPath": [
"tests/fixtures/blade-icons.php",
"tests/fixtures/generated-manifest.php"
]
}
4 changes: 2 additions & 2 deletions src/IconsManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function delete(): bool
private function format(string $pathname, string $path): string
{
return (string) Str::of($pathname)
->after($path.'/')
->replace('/', '.')
->after($path.DIRECTORY_SEPARATOR)
->replace(DIRECTORY_SEPARATOR, '.')
->basename('.svg');
}

Expand Down
10 changes: 7 additions & 3 deletions src/Svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ protected function deferContent(string $contents, $defer = false): string
}

$svgContent = strip_tags($contents, ['circle', 'ellipse', 'line', 'path', 'polygon', 'polyline', 'rect', 'g', 'mask', 'defs', 'use']);
$hash = 'icon-'.(is_string($defer) ? $defer : md5($svgContent));
$contents = str_replace($svgContent, strtr('<use href=":href"></use>', [':href' => '#'.$hash]), $contents);
$contents .= <<<BLADE

// Force Unix line endings for hash.
$hashContent = str_replace(PHP_EOL, "\n", $svgContent);
$hash = 'icon-'.(is_string($defer) ? $defer : md5($hashContent));

$contents = str_replace($svgContent, strtr('<use href=":href"></use>', [':href' => '#'.$hash]), $contents).PHP_EOL;
$svgContent = ltrim($svgContent, PHP_EOL);
$contents .= <<<BLADE
@once("{$hash}")
@push("bladeicons")
<g id="{$hash}">
Expand Down
12 changes: 8 additions & 4 deletions tests/IconsManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function tearDown(): void
private function expectedManifest(): string
{
return trim(str_replace(
'{{ dir }}',
__DIR__,
['{{ dir }}', '/'],
[__DIR__, DIRECTORY_SEPARATOR],
file_get_contents(__DIR__.'/fixtures/generated-manifest.php'),
));
}
Expand All @@ -43,9 +43,13 @@ public function it_can_write_the_manifest_file()
$manifest->write($this->prepareSets()->all());

$this->assertTrue(file_exists($this->manifestPath));
$this->assertSame(
$this->assertEquals(
$this->expectedManifest(),
str_replace(" \n", "\n", file_get_contents($this->manifestPath)),
stripslashes(str_replace(
["\n", '=> '.PHP_EOL],
[PHP_EOL, '=>'.PHP_EOL],
file_get_contents($this->manifestPath)
)),
);
}

Expand Down
49 changes: 20 additions & 29 deletions tests/SvgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,18 @@ public function it_can_compile_to_defered_html_with_group_custom_defer()
/** @test */
public function it_can_compile_to_defered_html_with_group_and_whitespace()
{
$svgPath = '
<g id="test" transform="translate(1 1)">
$svgPath = '<g id="test" transform="translate(1 1)">
<path d="M14 5l7 7m0 0l-7 7m7-7H3"></path>
</g>';
$svg = new Svg('heroicon-o-arrow-right', '<svg>'.$svgPath.'</svg>', ['defer' => true]);

$svgHtml = $svg->toHtml();

$this->assertEquals('<svg defer="1"><use href="#icon-e691490d4580d7276ba2a39a287f365f"></use></svg>
@once("icon-e691490d4580d7276ba2a39a287f365f")
$this->assertEquals('<svg defer="1"><use href="#icon-7f6f192a3c61bd15e25530394ec18d86"></use></svg>
@once("icon-7f6f192a3c61bd15e25530394ec18d86")
@push("bladeicons")
<g id="icon-e691490d4580d7276ba2a39a287f365f">
<g id="test" transform="translate(1 1)">
<g id="icon-7f6f192a3c61bd15e25530394ec18d86">
<g id="test" transform="translate(1 1)">
<path d="M14 5l7 7m0 0l-7 7m7-7H3"></path>
</g>
</g>
Expand All @@ -122,20 +120,18 @@ public function it_can_compile_to_defered_html_with_group_and_whitespace()
/** @test */
public function it_can_compile_to_defered_html_with_mask_tag()
{
$svgPath = '
<mask id="test" fill="#fff">
$svgPath = '<mask id="test" fill="#fff">
<path d="M0 30c0 16.56 13.44 30 30 30 16.56 0 30-13.44 30-30C60 13.44 46.56 0 30 0 13.44 0 0 13.44 0 30Zm4.35 0C4.35 15.84 15.845 4.35 30 4.35c6.295 0 12.08 2.27 16.495 6.04l-29.87 29.93-6.165 6.17C6.625 42.075 4.35 36.3 4.35 30Zm45.26-16.555c3.77 4.475 6.04 10.26 6.04 16.49 0 14.22-11.49 25.715-25.65 25.715-6.3 0-12.08-2.275-16.49-6.04l5.905-5.91-.005-.005 30.2-30.25Z" />
</mask>';
$svg = new Svg('heroicon-o-arrow-right', '<svg>'.$svgPath.'</svg>', ['defer' => true]);

$svgHtml = $svg->toHtml();

$this->assertEquals('<svg defer="1"><use href="#icon-e993fd00a973c62bf85d410a1a01dfe9"></use></svg>
@once("icon-e993fd00a973c62bf85d410a1a01dfe9")
$this->assertEquals('<svg defer="1"><use href="#icon-75e079eb3e6f7403d66f76ff7f0475c5"></use></svg>
@once("icon-75e079eb3e6f7403d66f76ff7f0475c5")
@push("bladeicons")
<g id="icon-e993fd00a973c62bf85d410a1a01dfe9">
<mask id="test" fill="#fff">
<g id="icon-75e079eb3e6f7403d66f76ff7f0475c5">
<mask id="test" fill="#fff">
<path d="M0 30c0 16.56 13.44 30 30 30 16.56 0 30-13.44 30-30C60 13.44 46.56 0 30 0 13.44 0 0 13.44 0 30Zm4.35 0C4.35 15.84 15.845 4.35 30 4.35c6.295 0 12.08 2.27 16.495 6.04l-29.87 29.93-6.165 6.17C6.625 42.075 4.35 36.3 4.35 30Zm45.26-16.555c3.77 4.475 6.04 10.26 6.04 16.49 0 14.22-11.49 25.715-25.65 25.715-6.3 0-12.08-2.275-16.49-6.04l5.905-5.91-.005-.005 30.2-30.25Z" />
</mask>
</g>
Expand All @@ -146,8 +142,7 @@ public function it_can_compile_to_defered_html_with_mask_tag()
/** @test */
public function it_can_compile_to_defered_html_with_defs_tag()
{
$svgPath = '
<defs>
$svgPath = '<defs>
<path d="M0 29.997495C0 46.567015 13.427975 60 30.002505 60 46.567015 60 60 46.567015 60 29.997495 60 13.432985 46.567015 0 30.002505 0 13.427975 0 0 13.432985 0 29.997495Z" id="fodmap-a"/>
<path d="M15.685498 3.670797C2.64507 10.886334-3.260408 26.270404 1.80359 40.303137c3.280262 9.091274 9.639234 15.2328 18.784665 18.459875.408143.141184.745743.226903 1.022877.236988h.100776c.665122-.025211.92714-.529442.891869-1.699256-.105815-3.101018.146125-6.222204-.095738-9.303052-.403104-5.0776 3.824453-8.718143 8.591162-8.460986 3.900035.206735 7.825264.095804 11.730338.005043 2.7008-.060508 4.252751-1.724468 4.167092-4.175028-.08566-2.279122-1.72831-3.711136-4.378722-3.731305-4.04616-.02017-8.09232 0-12.13848 0-1.360478 0-2.715916.010084-4.076394.025211-2.957778.030254-5.920595.060508-8.868296-.070592-5.376405-.226904-8.581085-5.985215-6.177575-10.760277 1.451176-2.899325 3.814376-4.255705 6.978745-4.301085 4.111665-.060508 8.228368-.050423 12.334994-.141185 3.174447-.070592 4.51477-1.482437 4.539963-4.659089.020155-3.232117-.04031-6.474318.025194-9.711477.025194-1.321084-.569385-1.81523-1.76862-1.905991C32.479834.040338 31.492228 0 30.5147 0c-5.189969 0-10.168308 1.09418-14.829202 3.670797Z" id="fodmap-c"/>
<path d="M24.539044 1.93889c-.005033 2.724387.005033 5.453746.0151 8.178134.0151 5.210143-3.110582 8.25768-8.44085 8.247736-3.840411-.009943-7.680822-.019886-11.5162.009943-2.81865.019886-4.660839 1.635627-4.595406 3.942408.0604 2.306781 1.726423 3.738576 4.535007 3.763434 4.107176.044743 8.214352.009943 12.321528.009943v-.034801h5.657433c1.952922.004971 3.905844.014915 5.863799.019886 4.721239.004972 8.179119 3.19171 8.158985 7.521896-.025166 4.330185-3.462913 7.482123-8.199252 7.511952-3.905843.019886-7.811687.014915-11.71753.059658-3.437747.039772-4.711173 1.332365-4.731306 4.757736-.020134 3.19171.130866 6.388391-.0604 9.57513-.115766 1.90906.649296 2.366438 2.370686 2.455925 14.13855.750699 27.230174-8.605684 30.80382-22.093393C48.905267 21.163721 41.03318 5.861411 26.809063.477265 26.02387.178975 25.510472 0 25.178274 0c-.583864 0-.634197.541895-.63923 1.93889Z" id="fodmap-e"/>
Expand All @@ -156,12 +151,11 @@ public function it_can_compile_to_defered_html_with_defs_tag()

$svgHtml = $svg->toHtml();

$this->assertEquals('<svg defer="1"><use href="#icon-50715b5a52a453df06f228c92c5882b1"></use></svg>
@once("icon-50715b5a52a453df06f228c92c5882b1")
$this->assertEquals('<svg defer="1"><use href="#icon-cf7005271ce6acebfa1a20cb123ad8b0"></use></svg>
@once("icon-cf7005271ce6acebfa1a20cb123ad8b0")
@push("bladeicons")
<g id="icon-50715b5a52a453df06f228c92c5882b1">
<defs>
<g id="icon-cf7005271ce6acebfa1a20cb123ad8b0">
<defs>
<path d="M0 29.997495C0 46.567015 13.427975 60 30.002505 60 46.567015 60 60 46.567015 60 29.997495 60 13.432985 46.567015 0 30.002505 0 13.427975 0 0 13.432985 0 29.997495Z" id="fodmap-a"/>
<path d="M15.685498 3.670797C2.64507 10.886334-3.260408 26.270404 1.80359 40.303137c3.280262 9.091274 9.639234 15.2328 18.784665 18.459875.408143.141184.745743.226903 1.022877.236988h.100776c.665122-.025211.92714-.529442.891869-1.699256-.105815-3.101018.146125-6.222204-.095738-9.303052-.403104-5.0776 3.824453-8.718143 8.591162-8.460986 3.900035.206735 7.825264.095804 11.730338.005043 2.7008-.060508 4.252751-1.724468 4.167092-4.175028-.08566-2.279122-1.72831-3.711136-4.378722-3.731305-4.04616-.02017-8.09232 0-12.13848 0-1.360478 0-2.715916.010084-4.076394.025211-2.957778.030254-5.920595.060508-8.868296-.070592-5.376405-.226904-8.581085-5.985215-6.177575-10.760277 1.451176-2.899325 3.814376-4.255705 6.978745-4.301085 4.111665-.060508 8.228368-.050423 12.334994-.141185 3.174447-.070592 4.51477-1.482437 4.539963-4.659089.020155-3.232117-.04031-6.474318.025194-9.711477.025194-1.321084-.569385-1.81523-1.76862-1.905991C32.479834.040338 31.492228 0 30.5147 0c-5.189969 0-10.168308 1.09418-14.829202 3.670797Z" id="fodmap-c"/>
<path d="M24.539044 1.93889c-.005033 2.724387.005033 5.453746.0151 8.178134.0151 5.210143-3.110582 8.25768-8.44085 8.247736-3.840411-.009943-7.680822-.019886-11.5162.009943-2.81865.019886-4.660839 1.635627-4.595406 3.942408.0604 2.306781 1.726423 3.738576 4.535007 3.763434 4.107176.044743 8.214352.009943 12.321528.009943v-.034801h5.657433c1.952922.004971 3.905844.014915 5.863799.019886 4.721239.004972 8.179119 3.19171 8.158985 7.521896-.025166 4.330185-3.462913 7.482123-8.199252 7.511952-3.905843.019886-7.811687.014915-11.71753.059658-3.437747.039772-4.711173 1.332365-4.731306 4.757736-.020134 3.19171.130866 6.388391-.0604 9.57513-.115766 1.90906.649296 2.366438 2.370686 2.455925 14.13855.750699 27.230174-8.605684 30.80382-22.093393C48.905267 21.163721 41.03318 5.861411 26.809063.477265 26.02387.178975 25.510472 0 25.178274 0c-.583864 0-.634197.541895-.63923 1.93889Z" id="fodmap-e"/>
Expand All @@ -174,18 +168,15 @@ public function it_can_compile_to_defered_html_with_defs_tag()
/** @test */
public function it_can_compile_to_defered_html_with_use_tag()
{
$svgPath = '
<use xlink:href="#fodmap-e"/>';
$svg = new Svg('heroicon-o-arrow-right', '<svg>'.$svgPath.'</svg>', ['defer' => true]);
$svg = new Svg('heroicon-o-arrow-right', '<svg><use xlink:href="#fodmap-e"/></svg>', ['defer' => true]);

$svgHtml = $svg->toHtml();

$this->assertEquals('<svg defer="1"><use href="#icon-7f8be00eb404e323e6b73eb94cf8a0d7"></use></svg>
@once("icon-7f8be00eb404e323e6b73eb94cf8a0d7")
$this->assertEquals('<svg defer="1"><use href="#icon-540a77d3751047fd94004bffda3ffb55"></use></svg>
@once("icon-540a77d3751047fd94004bffda3ffb55")
@push("bladeicons")
<g id="icon-7f8be00eb404e323e6b73eb94cf8a0d7">
<use xlink:href="#fodmap-e"/>
<g id="icon-540a77d3751047fd94004bffda3ffb55">
<use xlink:href="#fodmap-e"/>
</g>
@endpush
@endonce', $svgHtml);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ protected function prepareSets(array $config = [], array $setOptions = []): Fact

$factory = $factory
->add('default', array_merge([
'path' => __DIR__.'/resources/svg',
'path' => __DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'svg',
'prefix' => 'icon',
], $setOptions['default'] ?? []))
->add('zondicons', array_merge([
'path' => __DIR__.'/resources/zondicons',
'path' => __DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'zondicons',
'prefix' => 'zondicon',
], $setOptions['zondicons'] ?? []));

Expand Down

0 comments on commit 4d6b6b2

Please sign in to comment.