Skip to content

Commit d8e51ce

Browse files
authored
Merge pull request #13 from tattersoftware/styles
Allow style skipping
2 parents 3039a64 + 675d29a commit d8e51ce

File tree

9 files changed

+146
-62
lines changed

9 files changed

+146
-62
lines changed

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: tattersoftware
2+
custom: "https://paypal.me/tatter"

.github/workflows/analyze.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
paths:
1010
- 'src/**'
1111
- 'tests/**'
12+
- 'composer.**'
1213
- 'phpstan*'
1314
- '.github/workflows/analyze.yml'
1415
push:
@@ -17,21 +18,26 @@ on:
1718
paths:
1819
- 'src/**'
1920
- 'tests/**'
21+
- 'composer.**'
2022
- 'phpstan*'
2123
- '.github/workflows/analyze.yml'
2224

2325
jobs:
2426
build:
25-
name: Analyze code
27+
name: PHP ${{ matrix.php-versions }} Static Analysis
2628
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
php-versions: ['7.3', '7.4', '8.0']
2733
steps:
2834
- name: Checkout
2935
uses: actions/checkout@v2
3036

3137
- name: Setup PHP
3238
uses: shivammathur/setup-php@v2
3339
with:
34-
php-version: '7.4'
40+
php-version: ${{ matrix.php-versions }}
3541
tools: composer, pecl, phpunit
3642
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
3743

@@ -60,7 +66,7 @@ jobs:
6066
restore-keys: ${{ runner.os }}-phpstan-
6167

6268
- name: Install dependencies
63-
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
69+
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
6470
env:
6571
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
6672

.github/workflows/test.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ on:
1010

1111
jobs:
1212
main:
13-
name: Build and test
13+
name: PHP ${{ matrix.php-versions }} Unit Tests
1414

1515
strategy:
1616
matrix:
17-
php-versions: ['7.2', '7.3', '7.4']
17+
php-versions: ['7.3', '7.4', '8.0']
1818

1919
runs-on: ubuntu-latest
2020

@@ -44,9 +44,37 @@ jobs:
4444
restore-keys: ${{ runner.os }}-composer-
4545

4646
- name: Install dependencies
47-
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
47+
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
4848
env:
4949
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
5050

5151
- name: Test with PHPUnit
5252
run: vendor/bin/phpunit --verbose --coverage-text
53+
env:
54+
TERM: xterm-256color
55+
56+
- if: matrix.php-versions == '8.0'
57+
name: Mutate with Infection
58+
run: |
59+
composer global require infection/infection
60+
git fetch --depth=1 origin $GITHUB_BASE_REF
61+
infection --threads=2 --skip-initial-tests --coverage=build/phpunit --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github --ignore-msi-with-no-mutations
62+
63+
- if: matrix.php-versions == '8.0'
64+
name: Run Coveralls
65+
run: vendor/bin/php-coveralls --verbose --coverage_clover=build/phpunit/clover.xml --json_path build/phpunit/coveralls-upload.json
66+
env:
67+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
COVERALLS_PARALLEL: true
69+
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}
70+
71+
coveralls:
72+
needs: [main]
73+
name: Coveralls Finished
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Upload Coveralls results
77+
uses: coverallsapp/github-action@master
78+
with:
79+
github-token: ${{ secrets.GITHUB_TOKEN }}
80+
parallel-finished: true

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
],
2323
"require": {
24-
"php": ">=7.2",
24+
"php": "^7.3 || ^8.0",
2525
"components/jquery": "^3.3",
2626
"tatter/assets": "^2.2",
2727
"tijsverkoyen/css-to-inline-styles": "^2.2",
@@ -30,7 +30,7 @@
3030
"require-dev": {
3131
"codeigniter4/codeigniter4": "dev-develop",
3232
"myth/auth": "dev-develop",
33-
"tatter/tools": "^1.3"
33+
"tatter/tools": "^1.6"
3434
},
3535
"autoload": {
3636
"psr-4": {
@@ -55,6 +55,7 @@
5555
"prefer-stable": true,
5656
"scripts": {
5757
"analyze": "phpstan analyze",
58+
"mutate": "infection --threads=2 --coverage=build/phpunit",
5859
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 tests/ src/",
5960
"test": "phpunit"
6061
}

examples/Outbox.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class Outbox extends \Tatter\Outbox\Config\Outbox
3434
public $layout = 'Tatter\Outbox\Views\layout';
3535

3636
/**
37-
* View path for the default CSS styles to inline.
37+
* View path for the default CSS styles to inline, `null` to disable
3838
*
39-
* @var string
39+
* @var string|null
4040
*/
4141
public $styles = 'Tatter\Outbox\Views\Defaults\styles';
4242
}

infection.json.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"source": {
3+
"directories": [
4+
"src"
5+
],
6+
"excludes": [
7+
"Config",
8+
"Database/Migrations",
9+
"Views"
10+
]
11+
},
12+
"logs": {
13+
"text": "build/infection.log"
14+
},
15+
"mutators": {
16+
"@default": true
17+
},
18+
"bootstrap": "vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
19+
}

phpunit.xml.dist

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,71 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
4-
<include>
5-
<directory suffix=".php">./src</directory>
6-
</include>
7-
<exclude>
8-
<directory suffix=".php">./src/Views</directory>
9-
<file>./src/Config/Routes.php</file>
10-
</exclude>
11-
<report>
12-
<clover outputFile="build/logs/clover.xml"/>
13-
<html outputDirectory="build/logs/html"/>
14-
<php outputFile="build/logs/coverage.serialized"/>
15-
<text outputFile="php://stdout" showUncoveredFiles="false"/>
16-
</report>
17-
</coverage>
18-
<testsuites>
19-
<testsuite name="app">
20-
<directory>./tests</directory>
21-
</testsuite>
22-
</testsuites>
23-
<logging>
24-
<testdoxHtml outputFile="build/logs/testdox.html"/>
25-
<testdoxText outputFile="build/logs/testdox.txt"/>
26-
<junit outputFile="build/logs/logfile.xml"/>
27-
</logging>
28-
<php>
29-
<server name="app.baseURL" value="http://example.com"/>
30-
<!-- Directory containing phpunit.xml -->
31-
<const name="HOMEPATH" value="./"/>
32-
<!-- Directory containing the Paths config file -->
33-
<const name="CONFIGPATH" value="./vendor/codeigniter4/codeigniter4/app/Config/"/>
34-
<!-- Directory containing the front controller (index.php) -->
35-
<const name="PUBLICPATH" value="./vendor/codeigniter4/codeigniter4/public/"/>
36-
<!-- https://getcomposer.org/xdebug -->
37-
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
38-
<!-- Database configuration -->
39-
<!-- <env name="database.tests.hostname" value="localhost"/> -->
40-
<!-- <env name="database.tests.database" value="tests"/> -->
41-
<!-- <env name="database.tests.username" value="tests_user"/> -->
42-
<!-- <env name="database.tests.password" value=""/> -->
43-
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
44-
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
45-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
4+
backupGlobals="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
executionOrder="random"
10+
stopOnError="false"
11+
stopOnFailure="false"
12+
stopOnIncomplete="false"
13+
stopOnSkipped="false"
14+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
15+
16+
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
17+
<include>
18+
<directory suffix=".php">./src</directory>
19+
</include>
20+
<exclude>
21+
<directory suffix=".php">./src/Views</directory>
22+
<file>./src/Config/Routes.php</file>
23+
</exclude>
24+
<report>
25+
<clover outputFile="build/phpunit/clover.xml"/>
26+
<html outputDirectory="build/phpunit/html"/>
27+
<php outputFile="build/phpunit/coverage.serialized"/>
28+
<text outputFile="php://stdout" showUncoveredFiles="false"/>
29+
<xml outputDirectory="build/phpunit/xml-coverage"/>
30+
</report>
31+
</coverage>
32+
33+
<testsuites>
34+
<testsuite name="app">
35+
<directory>./tests</directory>
36+
</testsuite>
37+
</testsuites>
38+
39+
<logging>
40+
<testdoxHtml outputFile="build/phpunit/testdox.html"/>
41+
<testdoxText outputFile="build/phpunit/testdox.txt"/>
42+
<junit outputFile="build/phpunit/junit.xml"/>
43+
</logging>
44+
45+
<php>
46+
<env name="XDEBUG_MODE" value="coverage"/>
47+
<server name="app.baseURL" value="http://example.com"/>
48+
49+
<!-- Directory containing phpunit.xml -->
50+
<const name="HOMEPATH" value="./"/>
51+
52+
<!-- Directory containing the Paths config file -->
53+
<const name="CONFIGPATH" value="./vendor/codeigniter4/codeigniter4/app/Config/"/>
54+
55+
<!-- Directory containing the front controller (index.php) -->
56+
<const name="PUBLICPATH" value="./vendor/codeigniter4/codeigniter4/public/"/>
57+
58+
<!-- https://getcomposer.org/xdebug -->
59+
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
60+
61+
<!-- Database configuration -->
62+
<!-- Uncomment to use alternate testing database configuration
63+
<env name="database.tests.hostname" value="localhost"/>
64+
<env name="database.tests.database" value="tests"/>
65+
<env name="database.tests.username" value="tests_user"/>
66+
<env name="database.tests.password" value=""/>
67+
<env name="database.tests.DBDriver" value="MySQLi"/>
68+
<env name="database.tests.DBPrefix" value="tests_"/>
69+
-->
70+
</php>
4671
</phpunit>

src/Config/Outbox.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class Outbox extends BaseConfig
2626
public $layout = 'Tatter\Outbox\Views\layout';
2727

2828
/**
29-
* View path for the default CSS styles to inline.
29+
* View path for the default CSS styles to inline, `null` to disable
3030
*
31-
* @var string
31+
* @var string|null
3232
*/
3333
public $styles = 'Tatter\Outbox\Views\Defaults\styles';
3434
}

src/Entities/Template.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ public function getTokens(): array
8585
/**
8686
* Renders the body with inlined CSS.
8787
*
88-
* @param array $data Variables to exchange for Template tokens
89-
* @param string|null $styles CSS to use for inlining, defaults to configured view
88+
* @param array $data Variables to exchange for Template tokens
89+
* @param string|null $css CSS to use for inlining, null to use view from config
9090
*
9191
* @return string
9292
*/
93-
public function renderBody($data = [], string $styles = null): string
93+
public function renderBody($data = [], string $css = null): string
9494
{
9595
if (empty($this->attributes['body']))
9696
{
@@ -107,13 +107,16 @@ public function renderBody($data = [], string $styles = null): string
107107
{
108108
$data['body'] = $body;
109109

110-
return $parent->renderBody($data, $styles);
110+
return $parent->renderBody($data, $css);
111111
}
112112

113113
// Determine styling
114-
$styles = $styles ?? view(config('Outbox')->styles, [], ['debug' => false]);
114+
if (is_null($css) && config('Outbox')->styles)
115+
{
116+
$css = view(config('Outbox')->styles, [], ['debug' => false]);
117+
}
115118

116-
return $styles === '' ? $body : (new CssToInlineStyles)->convert($body, $styles);
119+
return $css === '' ? $body : (new CssToInlineStyles)->convert($body, $css);
117120
}
118121

119122
/**

0 commit comments

Comments
 (0)