Skip to content

Commit

Permalink
test: add phpunit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swashata committed Oct 13, 2018
1 parent 288f974 commit d120767
Show file tree
Hide file tree
Showing 12 changed files with 646 additions and 0 deletions.
146 changes: 146 additions & 0 deletions .gitignore
@@ -1 +1,147 @@
/coverage/
composer.phar
/vendor/

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless
1 change: 1 addition & 0 deletions phpcs.xml
Expand Up @@ -62,4 +62,5 @@
<exclude-pattern>*/bower_components/*</exclude-pattern>
<exclude-pattern>*/dist/*</exclude-pattern>
<exclude-pattern>*/includes/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
</ruleset>
39 changes: 39 additions & 0 deletions phpunit.xml
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
bootstrap="tests/bootstrap.php"
backupGlobals="true" colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
printerClass="PHPUnit\TextUI\ResultPrinter"
>
<testsuites>
<testsuite name="WPackIO Enqueue Test Suit">
<directory suffix="Test.php">
./tests
</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">
./inc
</directory>
</whitelist>
</filter>
<logging>
<log
type="coverage-text"
target="php://stdout"
showUncoveredFiles="true"
/>
<log
type="coverage-clover"
target="coverage/phpunit/clover.xml"
showUncoveredFiles="true"
/>
</logging>
</phpunit>
17 changes: 17 additions & 0 deletions tests/bootstrap.php
@@ -0,0 +1,17 @@
<?php
/**
* The following snippets uses `PLUGIN` to prefix
* the constants and class names. You should replace
* it with something that matches your plugin name.
*
* @package WPackio\Tests
*/

// define test environment
// define fake ABSPATH
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', sys_get_temp_dir() );
}

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/inc/TestCase.php';
35 changes: 35 additions & 0 deletions tests/data/dist/app/manifest.json
@@ -0,0 +1,35 @@
{
"app/assets/image.png": "app/assets/asset-c7cf665262fc289aea5bbe16b4f9aa67.png",
"main.css": "app/main.css",
"main.css.map": "app/main.css.map",
"main.js": "app/main.js",
"main.js.map": "app/main.js.map",
"mobile.js": "app/mobile.js",
"mobile.js.map": "app/mobile.js.map",
"wpackioEp": {
"main": {
"css": [
"app/main.css",
"app/foo.css"
],
"js": [
"app/main.js",
"app/foo.js"
],
"css.map": [
"app/main.css.map"
],
"js.map": [
"app/main.js.map"
]
},
"mobile": {
"js": [
"app/mobile.js"
],
"js.map": [
"app/mobile.js.map"
]
}
}
}
33 changes: 33 additions & 0 deletions tests/data/dist/broken/manifest.json
@@ -0,0 +1,33 @@
{
"app/assets/image.png": "app/assets/asset-c7cf665262fc289aea5bbe16b4f9aa67.png",
"main.css": "app/main.css",
"main.css.map": "app/main.css.map",
"main.js": "app/main.js",
"main.js.map": "app/main.js.map",
"mobile.js": "app/mobile.js",
"mobile.js.map": "app/mobile.js.map",
"blablabla": {
"main": {
"css": [
"app/main.css"
],
"js": [
"app/main.js"
],
"css.map": [
"app/main.css.map"
],
"js.map": [
"app/main.js.map"
]
},
"mobile": {
"js": [
"app/mobile.js"
],
"js.map": [
"app/mobile.js.map"
]
}
}
}
51 changes: 51 additions & 0 deletions tests/inc/TestCase.php
@@ -0,0 +1,51 @@
<?php
/**
* Primary class for all test cases.
*
* @package WPackio\Test
*/

namespace WPackioTest;

use Spatie\Snapshots\MatchesSnapshots;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Brain\Monkey;

/**
* An enhanced testcase framework with mockery
* and brainmonkey integration.
*
* @link https://swas.io/blog/wordpress-plugin-unit-test-with-brainmonkey/
*/
class TestCase extends \PHPUnit\Framework\TestCase {
use MatchesSnapshots;
use MockeryPHPUnitIntegration;

/**
* Setup which calls \WP_Mock setup
*
* @return void
*/
public function setUp() {
parent::setUp();
Monkey\setUp();
// A few common passthrough
// 1. WordPress i18n functions
Monkey\Functions\when( '__' )
->returnArg( 1 );
Monkey\Functions\when( '_e' )
->returnArg( 1 );
Monkey\Functions\when( '_n' )
->returnArg( 1 );
}

/**
* Teardown which calls \WP_Mock tearDown
*
* @return void
*/
public function tearDown() {
Monkey\tearDown();
parent::tearDown();
}
}

0 comments on commit d120767

Please sign in to comment.