Skip to content

Commit

Permalink
Add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
alies-dev committed Dec 6, 2021
1 parent 948d79e commit ac7266d
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 18 deletions.
46 changes: 46 additions & 0 deletions .github/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: run-tests

on: [ push, pull_request ]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.0, 8.1 ]
laravel: [ 8.* ]
dependency-version: [ prefer-stable ]
include:
- laravel: 8.*
testbench: 6.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

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, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_PASSWORD }}"
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Execute tests
run: composer test
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/vendor
/node_modules
package-lock.json
yarn.lock
package-lock.json

/vendor
composer.phar
composer.lock
auth.json

phpunit.xml
.phpunit.result.cache

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

### Compiling Assets

```bash
# Compile and minify your assets:
npm run prod

# Compile your assets for local development:
npm run dev

# Run the NPM "watch" command to auto-compile your assets when they are changed:
npm run watch
```

## Code of Conduct

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Full example:
```php
HtmlCode::make('HTML content')
->styles([asset(mix('css/app.css'))]),
->previewTemplate('<section class="panel">%CODE%<section>')
->previewTemplate('<section class="panel">%CODE%</section>')
```

### Changelog
Expand Down
23 changes: 21 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@
],
"license": "MIT",
"require": {
"php": ">=7.4"
"php": ">=8.0",
"laravel/nova": "^3.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.4"
},
"repositories": [
{
"type": "composer", "url": "https://nova.laravel.com"
}
],
"autoload": {
"psr-4": {
"InteractionDesignFoundation\\NovaHtmlCodeField\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"InteractionDesignFoundation\\NovaHtmlCodeField\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
Expand All @@ -25,5 +41,8 @@
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"scripts": {
"test": "phpunit"
}
}
23 changes: 23 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Compiling Assets

```bash
# Install npm dependencies
npm install
```

```bash
# Compile and minify your assets:
npm run prod

# Compile your assets for local development:
npm run dev

# Run the NPM "watch" command to auto-compile your assets when they are changed:
npm run watch
```

## Run tests

```bash
composer test
```
15 changes: 15 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="IxDF Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
</php>
</phpunit>
2 changes: 1 addition & 1 deletion src/HtmlCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class HtmlCode extends Field
/**
* Set default HTML code (template).
* In order to instruct package where to inject generated HTML, please provide a special marker: "%CODE%"
* Example: <section>%CODE%<section>
* Example: <section>%CODE%</section>
* @param string|\Closure():string $template
*/
public function previewTemplate($template): self
Expand Down
20 changes: 20 additions & 0 deletions tests/HtmlCodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace InteractionDesignFoundation\NovaHtmlCodeField\Tests;

use InteractionDesignFoundation\HtmlCard\MarkdownConverter;
use Illuminate\Support\Facades\App;
use InteractionDesignFoundation\NovaHtmlCodeField\HtmlCode;

final class HtmlCodeTest extends TestCase
{
/** @test */
public function it_throws_an_exception_if_invlid_template_used(): void
{
$this->expectException(\InvalidArgumentException::class);

$field = new HtmlCode('any_name');

$field->previewTemplate('<p></p>');
}
}
21 changes: 21 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);

namespace InteractionDesignFoundation\NovaHtmlCodeField\Tests;

use InteractionDesignFoundation\NovaHtmlCodeField\ServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;

abstract class TestCase extends OrchestraTestCase
{
public function setUp(): void
{
parent::setUp();
}

protected function getPackageProviders($app)
{
return [
ServiceProvider::class,
];
}
}

0 comments on commit ac7266d

Please sign in to comment.