Skip to content

Commit 0180463

Browse files
committed
Add basic tests and MarkdownConverter interface
1 parent 78862d5 commit 0180463

File tree

11 files changed

+179
-9
lines changed

11 files changed

+179
-9
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
max_line_length = 120
11+
tab_width = 4
12+
13+
[*.{yml,yaml}]
14+
indent_size = 2

.github/workflows/run-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: run-tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
os: [ubuntu-latest]
12+
php: [8.0, 8.1]
13+
laravel: [8.*]
14+
dependency-version: [prefer-stable]
15+
include:
16+
- laravel: 8.*
17+
testbench: 6.*
18+
19+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v2
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ matrix.php }}
29+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
30+
coverage: none
31+
32+
- name: Setup problem matchers
33+
run: |
34+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
35+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
36+
37+
- name: Install dependencies
38+
run: |
39+
composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_PASSWORD }}"
40+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
41+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
42+
env:
43+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
44+
45+
- name: Execute tests
46+
run: vendor/bin/phpunit

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
/.idea
2-
/vendor
31
/node_modules
2+
yarn.lock
43
package-lock.json
4+
5+
/vendor
56
composer.phar
67
composer.lock
8+
auth.json
9+
710
phpunit.xml
811
.phpunit.result.cache
12+
913
.DS_Store
1014
Thumbs.db
15+
/.idea

composer.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,29 @@
1111
],
1212
"license": "MIT",
1313
"require": {
14-
"php": ">=7.1.0"
14+
"php": ">=8.0",
15+
"laravel/nova": "^3.0"
1516
},
17+
"require-dev": {
18+
"mockery/mockery": "^1.4",
19+
"orchestra/testbench": "^6.0",
20+
"phpunit/phpunit": "^9.4"
21+
},
22+
"repositories": [
23+
{
24+
"type": "composer", "url": "https://nova.laravel.com"
25+
}
26+
],
1627
"autoload": {
1728
"psr-4": {
1829
"IDF\\HtmlCard\\": "src/"
1930
}
2031
},
32+
"autoload-dev": {
33+
"psr-4": {
34+
"IDF\\HtmlCard\\Tests\\": "tests"
35+
}
36+
},
2137
"extra": {
2238
"laravel": {
2339
"providers": [

phpunit.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="IxDF Test Suite">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<php>
14+
</php>
15+
</phpunit>

src/CardServiceProvider.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace IDF\HtmlCard;
44

5+
use Illuminate\Contracts\Support\DeferrableProvider;
56
use Laravel\Nova\Nova;
67
use Laravel\Nova\Events\ServingNova;
7-
use Illuminate\Support\Facades\Route;
88
use Illuminate\Support\ServiceProvider;
99

10-
class CardServiceProvider extends ServiceProvider
10+
class CardServiceProvider extends ServiceProvider implements DeferrableProvider
1111
{
1212
/**
1313
* Bootstrap any application services.
14-
*
1514
* @return void
1615
*/
1716
public function boot()
@@ -20,4 +19,18 @@ public function boot()
2019
Nova::script('html-card', __DIR__.'/../dist/js/card.js');
2120
});
2221
}
22+
23+
/** @inheritDoc */
24+
public function register(): void
25+
{
26+
$this->app->singleton(MarkdownConverter::class, LaravelMarkdownConverter::class);
27+
}
28+
29+
/** @inheritDoc */
30+
public function provides(): array
31+
{
32+
return [
33+
MarkdownConverter::class,
34+
];
35+
}
2336
}

src/HtmlCard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace IDF\HtmlCard;
44

55
use Illuminate\Mail\Markdown;
6+
use Illuminate\Support\Facades\App;
67
use Laravel\Nova\Card;
78

89
class HtmlCard extends Card
@@ -18,7 +19,6 @@ class HtmlCard extends Card
1819
* Create a new element.
1920
*
2021
* @param string|null $component
21-
* @return void
2222
*/
2323
public function __construct($component = null)
2424
{
@@ -59,7 +59,7 @@ public function html(string $htmlContent)
5959
*/
6060
public function markdown(string $markdownContent)
6161
{
62-
$htmlContent = Markdown::parse($markdownContent)->toHtml();
62+
$htmlContent = App::make(MarkdownConverter::class)::parse($markdownContent)->toHtml();
6363

6464
return $this->html($htmlContent);
6565
}
@@ -74,7 +74,7 @@ public function markdown(string $markdownContent)
7474
*/
7575
public function view(string $view, array $viewData = [])
7676
{
77-
$htmlContent = view($view, $viewData);
77+
$htmlContent = view($view, $viewData)->render();
7878

7979
return $this->html($htmlContent);
8080
}

src/LaravelMarkdownConverter.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace IDF\HtmlCard;
4+
5+
use Illuminate\Mail\Markdown;
6+
7+
final class LaravelMarkdownConverter extends Markdown implements MarkdownConverter
8+
{
9+
10+
}

src/MarkdownConverter.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace IDF\HtmlCard;
4+
5+
interface MarkdownConverter
6+
{
7+
/**
8+
* Parse the given Markdown text into HTML.
9+
* @param string $text
10+
* @return \Illuminate\Support\HtmlString
11+
*/
12+
public static function parse($text);
13+
}

tests/CardServiceProviderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace IDF\HtmlCard\Tests;
4+
5+
use IDF\HtmlCard\MarkdownConverter;
6+
use Illuminate\Support\Facades\App;
7+
8+
final class CardServiceProviderTest extends TestCase
9+
{
10+
/** @test */
11+
public function it_registers_markdown_converter_implementation(): void
12+
{
13+
$converter = App::make(MarkdownConverter::class);
14+
15+
$this->assertInstanceOf(MarkdownConverter::class, $converter);
16+
}
17+
}

0 commit comments

Comments
 (0)