Skip to content

Commit

Permalink
setup unit tests seperate from WordPress 'unit' tests #2701
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Oct 18, 2018
1 parent 4e5ca18 commit 4f5a904
Show file tree
Hide file tree
Showing 452 changed files with 44,139 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ npm-debug.log
**/.DS_Store
includes/freemius/assets/img/caldera-forms.png
bin/caldera-forms

wordpress/*
wp-content/*
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ The local server is [http://localhost:8228](http://localhost:8228)

### Test Structures
* PHP tests go in /tests and are run using phpunit
- Integration tests, which require WordPress, are in tests. These used to be all the tests we have.
- Unit tests -- isolated tests that do NOT require WordPress -- go in `tests/Unit`.
- The trait `calderawp\calderaforms\Util\Traits` should have all of the factories used for integration and unit tests (aspirational.)
* JavaScript UNIT tests go in clients/tests
- Unit tests go in clients/tests/unit and are run using [Jest](https://facebook.github.io/jest/docs/en/getting-started.html)
- Unit tests must have the word test in file name. For example, `formConfig.test.js`
Expand Down
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,27 @@
"calderawp\\calderaforms\\pro\\": "includes/cf-pro-client/classes/"
}
},
"autoload-dev": {
"psr-4": {
"calderawp\\calderaforms\\Tests\\Unit\\": "tests/Unit/",
"calderawp\\calderaforms\\Tests\\Util\\": "tests/Util/",
"calderawp\\calderaforms\\Tests\\Util\\Traits\\": "tests/Util/Traits/"
}
},
"require-dev": {
"phpunit/phpunit":"~5.5.0",
"wpackagist-plugin/gutenberg":"*",
"johnpbloch/wordpress" : "*"
"johnpbloch/wordpress" : "*",
"brain/monkey": "^2.2",
"mockery/mockery": ">=0.9 <2"
},
"scripts" : {
"wp:install": "bash ./bin/install-docker.sh && composer wp:config",
"wp:activate": "bash ./bin/activate-plugin.sh",
"wp:config": "docker-compose run --rm cli wp rewrite structure '/%postname%/'",
"wp:start": "docker-compose up -d",
"wp:tests": "docker-compose run --rm wordpress_phpunit phpunit --configuration phpunit-integration.xml.dist",
"wp:destroy": "docker-compose rm --stop --force"
"wp:destroy": "docker-compose rm --stop --force",
"test:unit": "phpunit --configuration phpunit-unit.xml.dist"
}
}
220 changes: 219 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions phpunit-unit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<phpunit
bootstrap="tests/bootstrap-unit.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="unit" suffix=".php">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<log type="coverage-clover" target="clover.xml"/>
</phpunit>
25 changes: 25 additions & 0 deletions tests/Unit/SampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


namespace calderawp\calderaforms\Tests\Unit;


class SampleTest extends TestCase
{

/**
* Super basic test for educational purposes
*
* @covers TestCase
*/
public function testTheTruth()
{
//What should the value be?
$excepted = true;
//What is the value actually
$actual = false;
//Are they not the same?
$this->assertNotEquals($excepted, $actual);
}

}
56 changes: 56 additions & 0 deletions tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php


namespace calderawp\calderaforms\Tests\Unit;


use Brain\Monkey;

use calderawp\calderaforms\Tests\Util\Traits\SharedFactories;
use PHPUnit\Framework\TestCase as FrameworkTestCase;

/**
* Class TestCase
*
* Default test case for all unit tests
* @package CalderaLearn\RestSearch\Tests\Unit
*/
abstract class TestCase extends FrameworkTestCase
{
use SharedFactories;
/**
* Prepares the test environment before each test.
*/
protected function setUp()
{
parent::setUp();
Monkey\setUp();

$this->setup_common_wp_stubs();
}

/**
* Cleans up the test environment after each test.
*/
protected function tearDown()
{
Monkey\tearDown();
parent::tearDown();
}

//phpcs:disable
/**
* Set up the stubs for the common WordPress escaping and internationalization functions.
*/
protected function setup_common_wp_stubs()
{
// Common internationalization functions.
Monkey\Functions\stubs(array(
'__',
'esc_html__',
'esc_html_x',
'esc_attr_x',
));
}
//phpcs:enable
}
Loading

0 comments on commit 4f5a904

Please sign in to comment.