Fix bin/publish: use correct .env path for rspade_system Fix bin/publish script: prevent grep exit code 1 from terminating script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
260 lines
7.0 KiB
PHP
Executable File
260 lines
7.0 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* CODING CONVENTION:
|
|
* This file follows the coding convention where variable_names and function_names
|
|
* use snake_case (underscore_wherever_possible).
|
|
*/
|
|
|
|
namespace App\RSpade\Testing;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
/**
|
|
* Rsx_Test_Abstract - Base class for RSX framework tests
|
|
*
|
|
* Provides simple test framework in the RSX spirit - no complex dependencies,
|
|
* just straightforward testing with clear pass/fail results
|
|
*/
|
|
abstract class Rsx_Test_Abstract
|
|
{
|
|
/**
|
|
* Test results storage
|
|
*/
|
|
protected static $results = [];
|
|
protected static $current_test = null;
|
|
|
|
/**
|
|
* Initialize the test class
|
|
* Called before running tests
|
|
*/
|
|
public static function setup()
|
|
{
|
|
// Override in child classes for test setup
|
|
}
|
|
|
|
/**
|
|
* Clean up after tests
|
|
* Called after all tests complete
|
|
*/
|
|
public static function teardown()
|
|
{
|
|
// Override in child classes for cleanup
|
|
}
|
|
|
|
/**
|
|
* Run all test methods in this class
|
|
*
|
|
* @return array Test results
|
|
*/
|
|
public static function run()
|
|
{
|
|
static::$results = [];
|
|
|
|
// Call setup
|
|
static::setup();
|
|
|
|
// Get all methods starting with 'test_'
|
|
$reflection = new \ReflectionClass(static::class);
|
|
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
|
|
|
|
foreach ($methods as $method) {
|
|
if (strpos($method->getName(), 'test_') === 0) {
|
|
static::$current_test = $method->getName();
|
|
|
|
try {
|
|
// Run the test
|
|
$method->invoke(null);
|
|
|
|
// If we got here without an exception, test passed
|
|
if (!isset(static::$results[static::$current_test])) {
|
|
static::$results[static::$current_test] = [
|
|
'status' => 'passed',
|
|
'message' => 'Test completed successfully'
|
|
];
|
|
}
|
|
} catch (\Exception $e) {
|
|
static::$results[static::$current_test] = [
|
|
'status' => 'failed',
|
|
'message' => $e->getMessage(),
|
|
'file' => $e->getFile(),
|
|
'line' => $e->getLine()
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Call teardown
|
|
static::teardown();
|
|
|
|
return static::$results;
|
|
}
|
|
|
|
/**
|
|
* Assert that a condition is true
|
|
*
|
|
* @param bool $condition
|
|
* @param string $message
|
|
*/
|
|
protected static function __assert_true($condition, $message = 'Assertion failed')
|
|
{
|
|
if (!$condition) {
|
|
throw new \Exception($message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Assert that a condition is false
|
|
*
|
|
* @param bool $condition
|
|
* @param string $message
|
|
*/
|
|
protected static function __assert_false($condition, $message = 'Assertion failed')
|
|
{
|
|
static::__assert_true(!$condition, $message);
|
|
}
|
|
|
|
/**
|
|
* Assert that two values are equal
|
|
*
|
|
* @param mixed $expected
|
|
* @param mixed $actual
|
|
* @param string $message
|
|
*/
|
|
protected static function __assert_equals($expected, $actual, $message = null)
|
|
{
|
|
if ($expected !== $actual) {
|
|
$message = $message ?: "Expected '" . var_export($expected, true) .
|
|
"' but got '" . var_export($actual, true) . "'";
|
|
throw new \Exception($message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Assert that two values are not equal
|
|
*
|
|
* @param mixed $expected
|
|
* @param mixed $actual
|
|
* @param string $message
|
|
*/
|
|
protected static function __assert_not_equals($expected, $actual, $message = null)
|
|
{
|
|
if ($expected === $actual) {
|
|
$message = $message ?: "Values should not be equal: '" . var_export($expected, true) . "'";
|
|
throw new \Exception($message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Assert that a string contains a substring
|
|
*
|
|
* @param string $needle
|
|
* @param string $haystack
|
|
* @param string $message
|
|
*/
|
|
protected static function __assert_contains($needle, $haystack, $message = null)
|
|
{
|
|
if (strpos($haystack, $needle) === false) {
|
|
$message = $message ?: "String does not contain '{$needle}'";
|
|
throw new \Exception($message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Assert that an array has a key
|
|
*
|
|
* @param string $key
|
|
* @param array $array
|
|
* @param string $message
|
|
*/
|
|
protected static function __assert_array_has_key($key, $array, $message = null)
|
|
{
|
|
if (!array_key_exists($key, $array)) {
|
|
$message = $message ?: "Array does not have key '{$key}'";
|
|
throw new \Exception($message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Assert that a value is null
|
|
*
|
|
* @param mixed $value
|
|
* @param string $message
|
|
*/
|
|
protected static function __assert_null($value, $message = 'Value should be null')
|
|
{
|
|
static::__assert_true($value === null, $message);
|
|
}
|
|
|
|
/**
|
|
* Assert that a value is not null
|
|
*
|
|
* @param mixed $value
|
|
* @param string $message
|
|
*/
|
|
protected static function __assert_not_null($value, $message = 'Value should not be null')
|
|
{
|
|
static::__assert_true($value !== null, $message);
|
|
}
|
|
|
|
/**
|
|
* Make a test HTTP request
|
|
*
|
|
* @param string $url
|
|
* @param string $method
|
|
* @param array $data
|
|
* @return \Illuminate\Http\Client\Response
|
|
*/
|
|
protected static function __request($url, $method = 'GET', $data = [])
|
|
{
|
|
$full_url = 'http://localhost' . $url;
|
|
|
|
switch (strtoupper($method)) {
|
|
case 'POST':
|
|
return Http::post($full_url, $data);
|
|
case 'GET':
|
|
return Http::get($full_url, $data);
|
|
default:
|
|
throw new \Exception("Unsupported HTTP method: {$method}");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Mark current test as passed with optional message
|
|
*
|
|
* @param string $message
|
|
*/
|
|
protected static function __pass($message = 'Test passed')
|
|
{
|
|
static::$results[static::$current_test] = [
|
|
'status' => 'passed',
|
|
'message' => $message
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Mark current test as failed
|
|
*
|
|
* @param string $message
|
|
*/
|
|
protected static function __fail($message = 'Test failed')
|
|
{
|
|
throw new \Exception($message);
|
|
}
|
|
|
|
/**
|
|
* Skip current test
|
|
*
|
|
* @param string $reason
|
|
*/
|
|
protected static function __skip($reason = 'Test skipped')
|
|
{
|
|
static::$results[static::$current_test] = [
|
|
'status' => 'skipped',
|
|
'message' => $reason
|
|
];
|
|
|
|
// Throw special exception to stop test execution but not mark as failed
|
|
throw new \Exception('__SKIP__:' . $reason);
|
|
}
|
|
} |