Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raulcodes committed Oct 28, 2024
1 parent 962385e commit 68f3f17
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
33 changes: 17 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<phpunit colors="true" bootstrap="test/bootstrap.php" convertNoticesToExceptions="true">
<logging>
<log type="coverage-html" target="build/logs/code_coverage"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<directory>build</directory>
<directory>test</directory>
<directory>vendor</directory>
</exclude>
</whitelist>
</filter>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="test/bootstrap.php" convertNoticesToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>build</directory>
<directory>test</directory>
<directory>vendor</directory>
</exclude>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/logs/code_coverage"/>
</report>
</coverage>
<logging/>
</phpunit>
14 changes: 13 additions & 1 deletion test/Dockerfile.integration
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ ARG PHP_MAJOR_VERSION
RUN set -ex; \
apt-get update && apt-get install -qq -y --fix-missing --no-install-recommends \
mariadb-client \
mariadb-server; \
mariadb-server \
curl; \
apt-get clean; \
rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /srv/provision/;

# Install node and npm for dev assets
RUN curl -fsSL https://deb.nodesource.com/setup_23.x | bash - && \
apt-get install -y nodejs \
build-essential && \
node --version && \
npm --version

# Install and enable xdebug
RUN set -ex; \
pecl install xdebug; \
Expand All @@ -23,6 +31,10 @@ RUN set -ex; \
tar -xf /wordpress.tar.gz -C /wordpress --strip-components=1; \
rm /wordpress.tar.gz;

RUN cd /wordpress; \
npm i; \
npm run build:dev;

# Env vars
ENV WORDPRESS_DB_NAME wordpress
ENV WORDPRESS_DB_USER wordpress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace WPEngine;

/**
* Unit tests for GeoIP class
* Smoke tests for GeoIP class
*/
class GeoIp_SmokeTest extends \WP_UnitTestCase {
class GeoIpSmokeTest extends \WP_UnitTestCase {
public function test_shortcode_continent() {
$this->assertEquals('NA', do_shortcode('[geoip-continent]'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Unit tests for GeoIP class
*/
class GeoIp_Test extends \WP_UnitTestCase {
class GeoIpTest extends \WP_UnitTestCase {

/**
* Name of class under test
Expand Down Expand Up @@ -79,12 +79,12 @@ public function test_init($hook, $method_name) {
// Test that the plugin adds the action via constructor side effect
$geoip = GeoIp::instance();
$priority = has_action( $hook, array( $geoip, $method_name ) );
$this->assertInternalType( 'int', $priority );
$this->assertIsInt( $priority );

// remove and readd action using init then test
remove_action( $hook, array( $geoip, $method_name ), $priority );
$geoip::init();
$this->assertInternalType( 'int', has_action( $hook, array( $geoip, $method_name ) ) );
$this->assertIsInt( has_action( $hook, array( $geoip, $method_name ) ) );
}

public function data_test_init()
Expand Down Expand Up @@ -124,7 +124,7 @@ public function test_setup() {

$geoip_mock->setup();
$this->assertEquals($expected_geos, $geoip_mock->geos);
$this->assertInternalType('array', $geoip_mock->admin_notices);
$this->assertIsArray( $geoip_mock->admin_notices );
}

/**
Expand Down Expand Up @@ -161,7 +161,7 @@ public function test_enqueue_admin_js() {
if (isset($wp_dependency->extra['data'])) {
$nonce_var_string = $wp_dependency->extra['data'];
}
$this->assertContains('nonce', $nonce_var_string);
$this->assertStringContainsString('nonce', $nonce_var_string);
}

/**
Expand Down Expand Up @@ -194,7 +194,7 @@ public function test_action_admin_notices() {
);

foreach ( $expected_output as $line ) {
$this->assertContains( $line, $actual_output );
$this->assertStringContainsString( $line, $actual_output );
}
}

Expand Down Expand Up @@ -314,8 +314,8 @@ public function test_do_shortcode_location() {
$geoip_mock->method( 'city' )
->will( $this->onConsecutiveCalls(null, $city) );

$this->assertEquals("${region} ${country}", $geoip_mock->do_shortcode_location(null));
$this->assertEquals("${city}, ${region} ${country}", $geoip_mock->do_shortcode_location(null));
$this->assertEquals("{$region} {$country}", $geoip_mock->do_shortcode_location(null));
$this->assertEquals("{$city}, {$region} {$country}", $geoip_mock->do_shortcode_location(null));
}

public function test_compare_location_type() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace WPEngine;

class wpengineGeoipTest extends \WP_UnitTestCase
require_once 'src/wpengine-geoip.php';

class wpengine_geoipTest extends \WP_UnitTestCase
{
/**
* Verify that wpengine-geoip correctly replaces the old plugin filename
Expand Down

0 comments on commit 68f3f17

Please sign in to comment.