Skip to content

Commit

Permalink
Merge pull request #142 from woocommerce/24-03/xdebug-on-tests
Browse files Browse the repository at this point in the history
Xdebug on QIT tests
  • Loading branch information
Luc45 authored Mar 12, 2024
2 parents de69fc8 + 2058d14 commit 9e18d1a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ src-tmp/
./qit
_tests/**/*.zip
_tests/**/*.txt
dev/
dev/
_build/docker/php83/xdebug/*
!_build/docker/php83/xdebug/.gitkeep
!_build/docker/php83/xdebug/README.md
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# ROOT Set this to 1 to run the command as root.
##
ROOT ?= 0
DEBUG ?= 0
ARGS ?=

ifeq (1, $(ROOT))
Expand All @@ -12,17 +13,20 @@ else
DOCKER_USER ?= "$(shell id -u):$(shell id -g)"
endif

## Run a command inside an alpine PHP 7 CLI image.
## Run a command inside an alpine PHP 8 CLI image.
## 1. Command to execute, eg: "./vendor/bin/phpcs" 2. Working dir (optional)
define execPhpAlpine
@docker images -q | grep qit-cli-php || docker build -t qit-cli-php ./_build/docker/php74
docker run --rm \
--user $(DOCKER_USER) \
-v "${PWD}:/app" \
--env QIT_HOME=/tmp \
--workdir "$(2:=/)" \
qit-cli-php \
bash -c "php -d memory_limit=1G $(1)"
@docker image inspect qit-cli-php-xdebug > /dev/null 2>&1 || docker build --build-arg CI=${CI} -t qit-cli-php-xdebug ./_build/docker/php83
docker run --rm \
--user $(DOCKER_USER) \
-v "${PWD}:/app" \
-v "${PWD}/_build/docker/php83/ini:/usr/local/etc/php/conf.d/" \
--env QIT_HOME=/tmp \
--env PHP_IDE_CONFIG=serverName=qit_cli \
--workdir "$(2:=/)" \
--add-host host.docker.internal:host-gateway \
qit-cli-php-xdebug \
bash -c "php -d xdebug.start_with_request=$(if $(filter 1,$(DEBUG)),yes,no) -d memory_limit=1G $(1)"
endef

watch:
Expand Down
5 changes: 0 additions & 5 deletions _build/docker/php74/Dockerfile

This file was deleted.

12 changes: 12 additions & 0 deletions _build/docker/php83/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:8.3-cli

ARG CI

RUN apt-get update \
&& apt-get install -y libzip-dev \
&& docker-php-ext-install zip

# Install Xdebug only if not in CI environment
RUN if [ "$CI" != "true" ]; then \
pecl install xdebug && docker-php-ext-enable xdebug; \
fi
19 changes: 19 additions & 0 deletions _build/docker/php83/ini/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
zend_extension=xdebug.so
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
xdebug.output_dir = /app/_build/docker/php83/xdebug/output
xdebug.log = /app/_build/docker/php83/xdebug/xdebug.log
# Enabled at runtime with DEBUG=1
xdebug.start_with_request = no

# https://xdebug.org/docs/all_settings#trace_output_name
xdebug.profiler_output_name = cachegrind.out.%R.%s

# Having issues? Set this to 7 and check the xdebug.log
xdebug.log_level = 0

; Choose between debug or profile.
; If choosing "profile", the cachegrind files will be saved in the "www" directory.
; You can analyze them with PHPStorm, KCacheGrind, QCachegrind, WinCacheGrind, Webgrind, etc.
xdebug.mode = debug
;xdebug.mode=profile
2 changes: 2 additions & 0 deletions _build/docker/php83/ini/zip.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Enable zip extension
extension=zip.so
Empty file.
10 changes: 10 additions & 0 deletions _build/docker/php83/xdebug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Xdebug instructions

### PHPStorm

- Settings -> Servers -> + (Add)
- Name: `qit_cli`
- Host: `-` (Any value)
- [X] Use path mappings
- File/Directory: The root dir of this project
- Absolute path on the server: `/app`

0 comments on commit 9e18d1a

Please sign in to comment.