Skip to content
Merged
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
26 changes: 21 additions & 5 deletions bin/test-php-watch.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#!/bin/bash
if ! which inotifywait >/dev/null 2>&1; then
echo "Error: the inotifywait command is not available. Make sure you have inotify-tools installed."
exit 1

# Check for the fswatch command
if ! command -v fswatch >/dev/null 2>&1; then
echo "Error: The fswatch command is not available."
echo "On macOS, you can install it with Homebrew: brew install fswatch"
exit 1
fi

cd "$(git rev-parse --show-toplevel)"

while true; do
echo "Waiting for a change in the plugins directory..."
output=$(inotifywait -e modify,create,delete -r ./plugins --include '.*(\.php$|/tests/.*)' 2> /dev/null)
plugin_slug=$(echo "$output" | awk -F/ '{print $3}')

file=$(fswatch -1 -r \
--event Created \
--event Updated \
--event Removed \
--include '\.php$' \
--include '/tests/' \
./plugins 2>/dev/null | head -n 1)

# Make the file path relative.
file="${file#"$PWD/"}"

plugin_slug=$(echo "$file" | awk -F/ '{print $2}')
sleep 1 # Give the user a chance to copy text from terminal before IDE auto-saves.
clear
echo "Running phpunit tests for $(tput bold)$plugin_slug$(tput sgr0):"
Expand Down