Skip to content

Commit d120767

Browse files
committed
test: add phpunit tests
1 parent 288f974 commit d120767

12 files changed

+646
-0
lines changed

.gitignore

+146
Original file line numberDiff line numberDiff line change
@@ -1 +1,147 @@
1+
/coverage/
2+
composer.phar
13
/vendor/
4+
5+
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
6+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
7+
# composer.lock
8+
9+
# General
10+
.DS_Store
11+
.AppleDouble
12+
.LSOverride
13+
14+
# Icon must end with two \r
15+
Icon
16+
17+
18+
# Thumbnails
19+
._*
20+
21+
# Files that might appear in the root of a volume
22+
.DocumentRevisions-V100
23+
.fseventsd
24+
.Spotlight-V100
25+
.TemporaryItems
26+
.Trashes
27+
.VolumeIcon.icns
28+
.com.apple.timemachine.donotpresent
29+
30+
# Directories potentially created on remote AFP share
31+
.AppleDB
32+
.AppleDesktop
33+
Network Trash Folder
34+
Temporary Items
35+
.apdisk
36+
37+
# Windows thumbnail cache files
38+
Thumbs.db
39+
ehthumbs.db
40+
ehthumbs_vista.db
41+
42+
# Dump file
43+
*.stackdump
44+
45+
# Folder config file
46+
[Dd]esktop.ini
47+
48+
# Recycle Bin used on file shares
49+
$RECYCLE.BIN/
50+
51+
# Windows Installer files
52+
*.cab
53+
*.msi
54+
*.msix
55+
*.msm
56+
*.msp
57+
58+
# Windows shortcuts
59+
*.lnk
60+
61+
*~
62+
63+
# temporary files which can be created if a process still has a handle open of a deleted file
64+
.fuse_hidden*
65+
66+
# KDE directory preferences
67+
.directory
68+
69+
# Linux trash folder which might appear on any partition or disk
70+
.Trash-*
71+
72+
# .nfs files are created when an open file is removed but is still being accessed
73+
.nfs*
74+
75+
# Logs
76+
logs
77+
*.log
78+
npm-debug.log*
79+
yarn-debug.log*
80+
yarn-error.log*
81+
82+
# Runtime data
83+
pids
84+
*.pid
85+
*.seed
86+
*.pid.lock
87+
88+
# Directory for instrumented libs generated by jscoverage/JSCover
89+
lib-cov
90+
91+
# Coverage directory used by tools like istanbul
92+
coverage
93+
94+
# nyc test coverage
95+
.nyc_output
96+
97+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
98+
.grunt
99+
100+
# Bower dependency directory (https://bower.io/)
101+
bower_components
102+
103+
# node-waf configuration
104+
.lock-wscript
105+
106+
# Compiled binary addons (https://nodejs.org/api/addons.html)
107+
build/Release
108+
109+
# Dependency directories
110+
node_modules/
111+
jspm_packages/
112+
113+
# TypeScript v1 declaration files
114+
typings/
115+
116+
# Optional npm cache directory
117+
.npm
118+
119+
# Optional eslint cache
120+
.eslintcache
121+
122+
# Optional REPL history
123+
.node_repl_history
124+
125+
# Output of 'npm pack'
126+
*.tgz
127+
128+
# Yarn Integrity file
129+
.yarn-integrity
130+
131+
# dotenv environment variables file
132+
.env
133+
134+
# parcel-bundler cache (https://parceljs.org/)
135+
.cache
136+
137+
# next.js build output
138+
.next
139+
140+
# nuxt.js build output
141+
.nuxt
142+
143+
# vuepress build output
144+
.vuepress/dist
145+
146+
# Serverless directories
147+
.serverless

phpcs.xml

+1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@
6262
<exclude-pattern>*/bower_components/*</exclude-pattern>
6363
<exclude-pattern>*/dist/*</exclude-pattern>
6464
<exclude-pattern>*/includes/*</exclude-pattern>
65+
<exclude-pattern>*/tests/*</exclude-pattern>
6566
</ruleset>

phpunit.xml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
5+
bootstrap="tests/bootstrap.php"
6+
backupGlobals="true" colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
verbose="true"
11+
printerClass="PHPUnit\TextUI\ResultPrinter"
12+
>
13+
<testsuites>
14+
<testsuite name="WPackIO Enqueue Test Suit">
15+
<directory suffix="Test.php">
16+
./tests
17+
</directory>
18+
</testsuite>
19+
</testsuites>
20+
<filter>
21+
<whitelist processUncoveredFilesFromWhitelist="false">
22+
<directory suffix=".php">
23+
./inc
24+
</directory>
25+
</whitelist>
26+
</filter>
27+
<logging>
28+
<log
29+
type="coverage-text"
30+
target="php://stdout"
31+
showUncoveredFiles="true"
32+
/>
33+
<log
34+
type="coverage-clover"
35+
target="coverage/phpunit/clover.xml"
36+
showUncoveredFiles="true"
37+
/>
38+
</logging>
39+
</phpunit>

tests/bootstrap.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* The following snippets uses `PLUGIN` to prefix
4+
* the constants and class names. You should replace
5+
* it with something that matches your plugin name.
6+
*
7+
* @package WPackio\Tests
8+
*/
9+
10+
// define test environment
11+
// define fake ABSPATH
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
define( 'ABSPATH', sys_get_temp_dir() );
14+
}
15+
16+
require_once __DIR__ . '/../vendor/autoload.php';
17+
require_once __DIR__ . '/inc/TestCase.php';

tests/data/dist/app/manifest.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"app/assets/image.png": "app/assets/asset-c7cf665262fc289aea5bbe16b4f9aa67.png",
3+
"main.css": "app/main.css",
4+
"main.css.map": "app/main.css.map",
5+
"main.js": "app/main.js",
6+
"main.js.map": "app/main.js.map",
7+
"mobile.js": "app/mobile.js",
8+
"mobile.js.map": "app/mobile.js.map",
9+
"wpackioEp": {
10+
"main": {
11+
"css": [
12+
"app/main.css",
13+
"app/foo.css"
14+
],
15+
"js": [
16+
"app/main.js",
17+
"app/foo.js"
18+
],
19+
"css.map": [
20+
"app/main.css.map"
21+
],
22+
"js.map": [
23+
"app/main.js.map"
24+
]
25+
},
26+
"mobile": {
27+
"js": [
28+
"app/mobile.js"
29+
],
30+
"js.map": [
31+
"app/mobile.js.map"
32+
]
33+
}
34+
}
35+
}

tests/data/dist/broken/manifest.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"app/assets/image.png": "app/assets/asset-c7cf665262fc289aea5bbe16b4f9aa67.png",
3+
"main.css": "app/main.css",
4+
"main.css.map": "app/main.css.map",
5+
"main.js": "app/main.js",
6+
"main.js.map": "app/main.js.map",
7+
"mobile.js": "app/mobile.js",
8+
"mobile.js.map": "app/mobile.js.map",
9+
"blablabla": {
10+
"main": {
11+
"css": [
12+
"app/main.css"
13+
],
14+
"js": [
15+
"app/main.js"
16+
],
17+
"css.map": [
18+
"app/main.css.map"
19+
],
20+
"js.map": [
21+
"app/main.js.map"
22+
]
23+
},
24+
"mobile": {
25+
"js": [
26+
"app/mobile.js"
27+
],
28+
"js.map": [
29+
"app/mobile.js.map"
30+
]
31+
}
32+
}
33+
}

tests/inc/TestCase.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Primary class for all test cases.
4+
*
5+
* @package WPackio\Test
6+
*/
7+
8+
namespace WPackioTest;
9+
10+
use Spatie\Snapshots\MatchesSnapshots;
11+
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
12+
use Brain\Monkey;
13+
14+
/**
15+
* An enhanced testcase framework with mockery
16+
* and brainmonkey integration.
17+
*
18+
* @link https://swas.io/blog/wordpress-plugin-unit-test-with-brainmonkey/
19+
*/
20+
class TestCase extends \PHPUnit\Framework\TestCase {
21+
use MatchesSnapshots;
22+
use MockeryPHPUnitIntegration;
23+
24+
/**
25+
* Setup which calls \WP_Mock setup
26+
*
27+
* @return void
28+
*/
29+
public function setUp() {
30+
parent::setUp();
31+
Monkey\setUp();
32+
// A few common passthrough
33+
// 1. WordPress i18n functions
34+
Monkey\Functions\when( '__' )
35+
->returnArg( 1 );
36+
Monkey\Functions\when( '_e' )
37+
->returnArg( 1 );
38+
Monkey\Functions\when( '_n' )
39+
->returnArg( 1 );
40+
}
41+
42+
/**
43+
* Teardown which calls \WP_Mock tearDown
44+
*
45+
* @return void
46+
*/
47+
public function tearDown() {
48+
Monkey\tearDown();
49+
parent::tearDown();
50+
}
51+
}

0 commit comments

Comments
 (0)