Adding PHPUnit Test feature/phpUnitTest
authorSteve Sutton <ssutton@gmail.com>
Sat, 28 May 2016 21:51:13 +0000 (17:51 -0400)
committerSteve Sutton <ssutton@gmail.com>
Sat, 28 May 2016 21:51:13 +0000 (17:51 -0400)
tests/bootstrap.php [new file with mode: 0644]
tests/phpunit.xml [new file with mode: 0644]
tests/test-products.php [new file with mode: 0644]

diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644 (file)
index 0000000..c16863c
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Set up environment for my plugin's tests suite.
+ */
+/**
+ * The path to the WordPress tests checkout.
+ */
+define( 'WP_TESTS_DIR', '/home/steven/Development/wordpress-dev/tests/phpunit/' );
+/**
+ * The path to the main file of the plugin to test.
+ */
+define( 'TEST_PLUGIN_FILE', '/home/steven/Development/GLMPlugins/michsci-products/index.php' );
+/**
+ * The WordPress tests functions.
+ *
+ * We are loading this so that we can add our tests filter
+ * to load the plugin, using tests_add_filter().
+ */
+require_once WP_TESTS_DIR . 'includes/functions.php';
+/**
+ * Manually load the plugin main file.
+ *
+ * The plugin won't be activated within the test WP environment,
+ * that's why we need to load it manually.
+ *
+ * You will also need to perform any installation necessary after
+ * loading your plugin, since it won't be installed.
+ */
+function _manually_load_plugin() {
+    require TEST_PLUGIN_FILE;
+    // Make sure plugin is installed here ...
+}
+tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
+/**
+ * Sets up the WordPress test environment.
+ *
+ * We've got our action set up, so we can load this now,
+ * and viola, the tests begin.
+ */
+require WP_TESTS_DIR . 'includes/bootstrap.php';
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644 (file)
index 0000000..fbeb639
--- /dev/null
@@ -0,0 +1,14 @@
+<phpunit
+    bootstrap="bootstrap.php"
+    backupGlobals="false"
+    colors="true"
+    convertErrorsToExceptions="true"
+    convertNoticesToExceptions="true"
+    convertWarningsToExceptions="true"
+    >
+    <testsuites>
+        <testsuite>
+            <directory prefix="test-" suffix=".php">./</directory>
+        </testsuite>
+    </testsuites>
+</phpunit>
diff --git a/tests/test-products.php b/tests/test-products.php
new file mode 100644 (file)
index 0000000..176cdbc
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+/**
+ * An example test case.
+ */
+class MyPlugin_Test_Example extends WP_UnitTestCase {
+    /**
+     * An example test.
+     *
+     * We just want to make sure that false is still false.
+     */
+    function test_false_is_false() {
+        $this->assertFalse( false );
+    }
+}