Files

45 lines
1.0 KiB
PHP

<?php
/**
* Minimal test runner for the WordPress-free parts of the plugin.
*
* php tests/run.php
*/
define( 'ABSPATH', __DIR__ . '/' );
require_once dirname( __DIR__ ) . '/includes/class-vc-structure.php';
function vc_assert_same( $expected, $actual, $msg = '' ) {
if ( $expected !== $actual ) {
throw new Exception( $msg . "\n expected: " . var_export( $expected, true ) . "\n actual: " . var_export( $actual, true ) );
}
}
function vc_assert_contains( $needle, array $errors ) {
if ( ! in_array( $needle, $errors, true ) ) {
throw new Exception( 'Missing error: ' . $needle . "\n got: " . var_export( $errors, true ) );
}
}
foreach ( glob( __DIR__ . '/test-*.php' ) as $file ) {
require_once $file;
}
$passed = 0;
$failed = 0;
foreach ( get_defined_functions()['user'] as $fn ) {
if ( 0 !== strpos( $fn, 'test_' ) ) {
continue;
}
try {
$fn();
$passed++;
} catch ( Throwable $e ) {
$failed++;
echo 'FAIL ' . $fn . ': ' . $e->getMessage() . "\n";
}
}
echo $passed . ' passed, ' . $failed . " failed\n";
exit( $failed ? 1 : 0 );