Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,34 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache-key: ${{ matrix.target }}-${{ matrix.php-version }}-${{ matrix.platform }}-${{ matrix.distro }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: none

- name: Generate version for tag
if: github.ref_type == 'tag'
run: echo "ERROR_MESSAGE_FORMAT_VERSION=${{github.ref_name}}" >> $GITHUB_ENV

- run: php -i -c tests/php.ini

- name: Generate version for branch
if: github.ref_type == 'branch'
run: echo "ERROR_MESSAGE_FORMAT_VERSION=0.0.1+${{github.ref_name}}" | sed 's!/!-!g' >> $GITHUB_ENV

- name: Update Cargo.toml version
run: sed -i "s/^version = .*/version = \"${{ env.ERROR_MESSAGE_FORMAT_VERSION }}\"/" Cargo.toml

- uses: mxschmitt/action-tmate@v3
if: runner.debug == '1'

- name: Test
run: cargo test -- --nocapture

- run: cargo build --release --target ${{ matrix.target }}

- run: ls -la target/${{ matrix.target }}/release/
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ $url = $_SERVER['REQUEST_URI'];
ini_set( 'error_message_format', '{message} from URL' . $url );
```

## Compatibily

Supports PHP versions 8+

⚠️ Currently `error_message_format` is not compatible with Xdebug.

## Resources

- [ext-php-rs Documentation](https://docs.rs/ext-php-rs)
Expand Down
37 changes: 33 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
use assertables::assert_contains;
use std::sync::{Arc, Condvar, Mutex, OnceLock};

mod utils;

// Global state to track build completion
static BUILD_STATE: OnceLock<(Arc<Mutex<bool>>, Arc<Condvar>)> = OnceLock::new();

// Call this function to ensure the build has happened and completed
// All threads will wait for the build to finish before proceeding
fn ensure_setup() {
let (build_complete, condvar) = BUILD_STATE.get_or_init(|| {
let pair = (Arc::new(Mutex::new(false)), Arc::new(Condvar::new()));
let (build_complete, condvar) = pair.clone();

// Start the build in the background
std::thread::spawn(move || {
utils::build();
let mut completed = build_complete.lock().unwrap();
*completed = true;
condvar.notify_all();
});

pair
});

// Wait for build to complete
let mut completed = build_complete.lock().unwrap();
while !*completed {
completed = condvar.wait(completed).unwrap();
}
}

#[test]
fn test_build() {
utils::build();
ensure_setup();
}

#[test]
fn test_version() {
utils::build();
ensure_setup();
let output = utils::run_cli("<?php phpinfo(); ?>");
assert_contains!(
output.trim(),
Expand All @@ -22,7 +51,7 @@ fn test_version() {

#[test]
fn test_cli_error_output_default() {
utils::build();
ensure_setup();
let code = r#"
<?php
trigger_error('This is a test error', E_USER_WARNING);
Expand All @@ -33,7 +62,7 @@ trigger_error('This is a test error', E_USER_WARNING);

#[test]
fn test_cli_error_output() {
utils::build();
ensure_setup();
let code = r#"
<?php
ini_set('error_message_format', '{message} with an append');
Expand Down
2 changes: 0 additions & 2 deletions tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ pub fn run_cli(code: &str) -> String {
.output()
.unwrap();

dbg!(&output);

fs::remove_file(script_filename).unwrap();
String::from_utf8(output.stdout).unwrap()
}