Skip to content

Commit ac7266d

Browse files
committed
Add basic test
1 parent 948d79e commit ac7266d

File tree

10 files changed

+158
-18
lines changed

10 files changed

+158
-18
lines changed

.github/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: composer test

.gitignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
/vendor
21
/node_modules
3-
package-lock.json
42
yarn.lock
3+
package-lock.json
4+
5+
/vendor
6+
composer.phar
57
composer.lock
8+
auth.json
9+
610
phpunit.xml
711
.phpunit.result.cache
12+
13+
.DS_Store
14+
Thumbs.db
15+
/.idea

CONTRIBUTING.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ Please note we have a code of conduct, please follow it in all your interactions
1212
2. Update the README.md with details of changes to reflect important changes (new options, changed API, etc).
1313
3. Regenerate dist assets using production env: `npm run prod`.
1414

15-
### Compiling Assets
16-
17-
```bash
18-
# Compile and minify your assets:
19-
npm run prod
20-
21-
# Compile your assets for local development:
22-
npm run dev
23-
24-
# Run the NPM "watch" command to auto-compile your assets when they are changed:
25-
npm run watch
26-
```
2715

2816
## Code of Conduct
2917

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Full example:
4343
```php
4444
HtmlCode::make('HTML content')
4545
->styles([asset(mix('css/app.css'))]),
46-
->previewTemplate('<section class="panel">%CODE%<section>')
46+
->previewTemplate('<section class="panel">%CODE%</section>')
4747
```
4848

4949
### Changelog

composer.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@
77
],
88
"license": "MIT",
99
"require": {
10-
"php": ">=7.4"
10+
"php": ">=8.0",
11+
"laravel/nova": "^3.0"
1112
},
13+
"require-dev": {
14+
"mockery/mockery": "^1.4",
15+
"orchestra/testbench": "^6.0",
16+
"phpunit/phpunit": "^9.4"
17+
},
18+
"repositories": [
19+
{
20+
"type": "composer", "url": "https://nova.laravel.com"
21+
}
22+
],
1223
"autoload": {
1324
"psr-4": {
1425
"InteractionDesignFoundation\\NovaHtmlCodeField\\": "src/"
1526
}
1627
},
28+
"autoload-dev": {
29+
"psr-4": {
30+
"InteractionDesignFoundation\\NovaHtmlCodeField\\Tests\\": "tests"
31+
}
32+
},
1733
"extra": {
1834
"laravel": {
1935
"providers": [
@@ -25,5 +41,8 @@
2541
"sort-packages": true
2642
},
2743
"minimum-stability": "dev",
28-
"prefer-stable": true
44+
"prefer-stable": true,
45+
"scripts": {
46+
"test": "phpunit"
47+
}
2948
}

docs/CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Compiling Assets
2+
3+
```bash
4+
# Install npm dependencies
5+
npm install
6+
```
7+
8+
```bash
9+
# Compile and minify your assets:
10+
npm run prod
11+
12+
# Compile your assets for local development:
13+
npm run dev
14+
15+
# Run the NPM "watch" command to auto-compile your assets when they are changed:
16+
npm run watch
17+
```
18+
19+
## Run tests
20+
21+
```bash
22+
composer test
23+
```

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/HtmlCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class HtmlCode extends Field
2727
/**
2828
* Set default HTML code (template).
2929
* In order to instruct package where to inject generated HTML, please provide a special marker: "%CODE%"
30-
* Example: <section>%CODE%<section>
30+
* Example: <section>%CODE%</section>
3131
* @param string|\Closure():string $template
3232
*/
3333
public function previewTemplate($template): self

tests/HtmlCodeTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace InteractionDesignFoundation\NovaHtmlCodeField\Tests;
4+
5+
use InteractionDesignFoundation\HtmlCard\MarkdownConverter;
6+
use Illuminate\Support\Facades\App;
7+
use InteractionDesignFoundation\NovaHtmlCodeField\HtmlCode;
8+
9+
final class HtmlCodeTest extends TestCase
10+
{
11+
/** @test */
12+
public function it_throws_an_exception_if_invlid_template_used(): void
13+
{
14+
$this->expectException(\InvalidArgumentException::class);
15+
16+
$field = new HtmlCode('any_name');
17+
18+
$field->previewTemplate('<p></p>');
19+
}
20+
}

tests/TestCase.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace InteractionDesignFoundation\NovaHtmlCodeField\Tests;
4+
5+
use InteractionDesignFoundation\NovaHtmlCodeField\ServiceProvider;
6+
use Orchestra\Testbench\TestCase as OrchestraTestCase;
7+
8+
abstract class TestCase extends OrchestraTestCase
9+
{
10+
public function setUp(): void
11+
{
12+
parent::setUp();
13+
}
14+
15+
protected function getPackageProviders($app)
16+
{
17+
return [
18+
ServiceProvider::class,
19+
];
20+
}
21+
}

0 commit comments

Comments
 (0)