Skip to content

Commit

Permalink
feat: Add configuration for running tests
Browse files Browse the repository at this point in the history
Thanks to the work done in roots/bedrock#366 .
  • Loading branch information
takotakot committed Apr 7, 2023
1 parent c1d1b20 commit 24167f7
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ docker compose -f docker-compose.yml --env-file=docker_configs/.env.compose.deve
```
git --git-dir= apply application_php.patch
```

If there are some update with autoload's run:

```
composer dump-autoload
```

Run tests

```
# ./vendor/bin/phpunit
composer test
```
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@
"scripts": {
"lint": "phpcs",
"test": "phpunit"
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/src"
}
}
}
20 changes: 20 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">./tests/unit/</directory>
<exclude>./tests/test-sample.php</exclude>
</testsuite>
</testsuites>
<php>
<env name="WP_ENV" value="testing"/>
<env name="WP_PHPUNIT__TABLE_PREFIX" value="tests_"/>
</php>
</phpunit>
19 changes: 19 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* PHPUnit bootstrap file
*
* Composer autoloader must be loaded before WP_PHPUNIT__DIR will be available.
*/

require_once(dirname(__DIR__) . '/vendor/autoload.php');

// Give access to tests_add_filter() function.
require_once(getenv('WP_PHPUNIT__DIR') . '/includes/functions.php');

tests_add_filter('muplugins_loaded', function () {
// test set up, plugin activation, etc.
});

// Start up the WP testing environment.
putenv(sprintf('WP_PHPUNIT__TESTS_CONFIG=%s/wp-config.php', __DIR__));
require(getenv('WP_PHPUNIT__DIR') . '/includes/bootstrap.php');
11 changes: 11 additions & 0 deletions tests/src/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Tests;

class TestCase extends \WP_UnitTestCase
{
/**
* Here you can define your own custom assertions or helper methods
* which will be available to all your tests that extend it.
*/
}
12 changes: 12 additions & 0 deletions tests/unit/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Tests;

class ExampleTest extends TestCase
{
/** @test */
function it_works()
{
$this->assertTrue(function_exists('add_action'));
}
}
7 changes: 7 additions & 0 deletions tests/wp-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
/**
* Do not edit this file. Edit the config files found in the config/ dir instead.
* Test-specific configuration is found in config/environments/testing.php.
*/
require_once(dirname(__DIR__) . '/vendor/autoload.php');
require_once(dirname(__DIR__) . '/bedrock/config/application.php');

0 comments on commit 24167f7

Please sign in to comment.