Skip to content

Commit

Permalink
tests update wip
Browse files Browse the repository at this point in the history
  • Loading branch information
erikyo committed Oct 13, 2023
1 parent 8e26419 commit 04f1973
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 69 deletions.
6 changes: 4 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
bootstrap="tests/phpunit/bootstrap.php"
backupGlobals="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="Php tests">
<directory suffix=".php" phpVersion="*">tests/phpunit/tests</directory>
<directory prefix="CF7_AntiSpam" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
49 changes: 24 additions & 25 deletions tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* PHPUnit bootstrap file.
*
* @package Cf7_Antispam
*/
// Debug settings for parity with WordPress Core's PHPUnit tests.
if ( ! defined( 'WP_DEBUG' ) ) {
define( 'WP_DEBUG', true );
Expand All @@ -17,42 +21,37 @@
define( 'LOCAL_WP_ENVIRONMENT_TYPE', 'local' );
}

// If we're running in WP's build directory, ensure that WP knows that, too.
if ( 'build' === getenv( 'LOCAL_DIR' ) ) {
define( 'WP_RUN_CORE_TESTS', true );
}
include("vendor/autoload.php");

// Determine the tests directory (from a WP dev checkout).
// Try the WP_TESTS_DIR environment variable first.
$_tests_dir = getenv( 'WP_TESTS_DIR' );

// See if we're installed inside an existing WP dev instance.
if ( ! $_tests_dir ) {
$_try_tests_dir = __DIR__ . '/../../../../../tests/phpunit';
if ( file_exists( $_try_tests_dir . '/includes/functions.php' ) ) {
$_tests_dir = $_try_tests_dir;
}
}
// Fallback.
if ( ! $_tests_dir ) {
$_tests_dir = '/tmp/wordpress-tests-lib';
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}

// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';
// Forward custom PHPUnit Polyfills configuration to PHPUnit bootstrap file.
$_phpunit_polyfills_path = getenv( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' );
if ( false !== $_phpunit_polyfills_path ) {
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path );
}

function manually_load_plugin() {
require_once __DIR__ . '/../../cf7-antispam.php';
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit( 1 );
}
tests_add_filter( 'plugins_loaded', 'manually_load_plugin' );

// Give access to tests_add_filter() function.
require_once "{$_tests_dir}/includes/functions.php";

/**
* Manually load the plugin being tested.
*/
// function _manually_load_plugin() {
// require dirname( __DIR__ ) . '/lib/load.php';
// }
// tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
function _manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/../cf7-antispam.php';
}

tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );


/**
* Adds a wp_die handler for use during tests.
Expand Down
39 changes: 0 additions & 39 deletions tests/phpunit/includes/bootstrap.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

use PHPUnit\Framework\TestCase;

// require_once '../../../cf7-antispam.php';
// require_once '../../../includes/cf7a-activator.php';

class CF7_AntiSpam_ActivatorTest extends TestCase {

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace CF7_AntiSpam\Tests;

use CF7_AntiSpam\Core\CF7_AntiSpam_Filters;
use PHPUnit\Framework\TestCase;

class CF7_AntiSpam_FiltersTest extends TestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CF7_AntiSpam\Core\CF7_AntiSpam;
use CF7_AntiSpam\Core\CF7_AntiSpam_Frontend;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -21,9 +23,13 @@ class CF7_AntiSpam_FrontendTest extends TestCase {
*/
private $frontend;

public $options;

public function __construct( $name = null, $data = array(), $dataName = '' ) {

parent::__construct( $name, $data, $dataName );
$this->frontend = new CF7_AntiSpam_Frontend(CF7ANTISPAM_NAME, CF7ANTISPAM_VERSION);
$this->options = CF7_AntiSpam::get_options();
}

public function testCf7a_honeypot_count_and_validate() {
Expand Down

0 comments on commit 04f1973

Please sign in to comment.