Skip to content

Commit

Permalink
Add PHPUnit tests for PHP 8.1, 8.2 and 8.3 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Dec 5, 2023
1 parent efdc311 commit 40f7b9b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ node_modules/

# dotenv environment variables file
.env

.phpunit.result.cache
10 changes: 10 additions & 0 deletions phpunit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="" tests="1" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.318031">
<testsuite name="sb-post-edit-block" tests="1" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.318031">
<testsuite name="Tests_load_libs" file="C:\apache\htdocs\wordpress\wp-content\plugins\sb-post-edit-block\tests\test-a-load-php.php" tests="1" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.318031">
<testcase name="test_load_plugin" class="Tests_load_libs" classname="Tests_load_libs" file="C:\apache\htdocs\wordpress\wp-content\plugins\sb-post-edit-block\tests\test-a-load-php.php" line="57" assertions="1" time="0.318031"/>
</testsuite>
</testsuite>
</testsuite>
</testsuites>
15 changes: 15 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<phpunit
bootstrap="../oik-batch/oik-wp.php"
backupGlobals="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<!-- for PHPUnit 9.6 -->
<testsuites>
<testsuite name="sb-post-edit-block">
<directory prefix="test-" suffix=".php">tests/</directory>
</testsuite>
</testsuites>
</phpunit>
62 changes: 62 additions & 0 deletions tests/test-a-load-php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* @package sb-post-edit-block
* @copyright (C) Copyright Bobbing Wide 2023
*
* Unit tests to load all the files for PHP 8.2, except batch ones
*/

class Tests_load_libs extends BW_UnitTestCase
{

/**
* set up logic
*
* - ensure any database updates are rolled back
* - we need oik-googlemap to load the functions we're testing
*/
function setUp(): void
{
parent::setUp();

}

/*
function test_load_admin() {
$this->load_dir_files( 'admin' );
$this->assertTrue( true );
}
function test_load_includes() {
//$this->load_dir_files( 'shortcodes' );
oik_require( 'includes/oikp-lazy-nav.inc', 'sb-post-edit-block');
$this->assertTrue( true );
}
function load_dir_files( $dir, $excludes=[] ) {
$files = glob( "$dir/*.php");
//print_r( $files );
foreach ( $files as $file ) {
if ( !in_array( $file, $excludes ) ) {
//echo "Loading $file";
oik_require( $file, 'sb-post-edit-block');
}
}
}
*/

/**
* Test that the plugin is loaded
*/
function test_load_plugin() {
oik_require( 'sb-post-edit-block.php', 'sb-post-edit-block');
$this->assertTrue( true );
}

}

0 comments on commit 40f7b9b

Please sign in to comment.