<?php

/**

 * Simple Test Runner for SensFRX DB Helper

 * 

 * Run this file directly: php tests/run-tests.php

 * 

 * @package SensFRX

 */





echo "\n";

echo "========================================\n";

echo "SensFRX DB Helper - Test Runner\n";

echo "========================================\n\n";



// Load bootstrap

require_once __DIR__ . '/bootstrap.php';



// Load test class

require_once __DIR__ . '/test-sensfrx-db-helper.php';



// Initialize test results

$total_tests = 0;

$passed_tests = 0;

$failed_tests = 0;

$results = array();



// Get all test methods

$test_class = new Test_SensFRX_DB_Helper();

$methods = get_class_methods( $test_class );



echo "Running tests...\n\n";



foreach ( $methods as $method ) {

	if ( strpos( $method, 'test_' ) === 0 ) {

		$total_tests++;

		$test_name = str_replace( 'test_', '', $method );

		$test_name = str_replace( '_', ' ', $test_name );

		$test_name = ucwords( $test_name );

		

		echo "Testing: {$test_name}... ";

		

		try {

			// Run setUp before each test

			if ( method_exists( $test_class, 'setUp' ) ) {

				$test_class->setUp();

			}

			

			// Run the test

			$test_class->$method();

			

			// Run tearDown after each test

			if ( method_exists( $test_class, 'tearDown' ) ) {

				$test_class->tearDown();

			}

			

			echo "✓ PASSED\n";

			$passed_tests++;

			$results[] = array(

				'name' => $test_name,

				'status' => 'passed',

				'message' => '',

			);

			

		} catch ( Exception $e ) {

			echo "✗ FAILED\n";

			echo "   Error: " . $e->getMessage() . "\n";

			$failed_tests++;

			$results[] = array(

				'name' => $test_name,

				'status' => 'failed',

				'message' => $e->getMessage(),

			);

		}

	}

}



// Print summary

echo "\n";

echo "========================================\n";

echo "Test Summary\n";

echo "========================================\n";

echo "Total Tests:  {$total_tests}\n";

echo "Passed:       {$passed_tests} ✓\n";

echo "Failed:       {$failed_tests} " . ( $failed_tests > 0 ? '✗' : '' ) . "\n";

echo "Success Rate: " . ( $total_tests > 0 ? round( ( $passed_tests / $total_tests ) * 100, 2 ) : 0 ) . "%\n";

echo "========================================\n\n";



if ( $failed_tests > 0 ) {

	echo "Failed Tests:\n";

	foreach ( $results as $result ) {

		if ( $result['status'] === 'failed' ) {

			echo "  - {$result['name']}: {$result['message']}\n";

		}

	}

	echo "\n";

	exit( 1 );

}



echo "All tests passed! ✓\n\n";

exit( 0 );



