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); } }