Skip to content

Commit a15da66

Browse files
committed
PHPUnit integration fully functional
1 parent a60dcef commit a15da66

File tree

10 files changed

+58
-48
lines changed

10 files changed

+58
-48
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git
2+
doc
3+
docker
4+
test
5+

Makefile

+31-30
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1-
.PHONY: debug run full-test-phpunit regression-test-phpunit
2-
31
XDEBUG_OPTIONS=-dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 -dxdebug.remote_host="host.docker.internal" -dxdebug.idekey=IDEKEY -dxdebug.remote_port=9008
4-
5-
debug:
6-
docker-compose run php php $(XDEBUG_OPTIONS) bin/regrest $(command)
7-
8-
run:
9-
@docker-compose run php php bin/regrest $(command)
10-
2+
PHP=docker-compose run php php
113
PHPUNIT_ROOT=test/Fixtures/PhpProjectUsingPhpunit
124

13-
# generates coverage report
14-
full-test-phpunit:
15-
docker-compose run php php $(PHPUNIT_ROOT)/vendor/bin/phpunit --debug --colors=always --bootstrap $(PHPUNIT_ROOT)/vendor/autoload.php --coverage-filter=$(PHPUNIT_ROOT)/src --coverage-php=$(PHPUNIT_ROOT)/test/output/coverage.php --coverage-html=$(PHPUNIT_ROOT)/test/output/coverage.html $(PHPUNIT_ROOT)/test
16-
17-
# does not generate coverage
18-
regression-test-phpunit: # one needs to pass output of regrest command to `options` argument
19-
docker-compose run php php $(PHPUNIT_ROOT)/vendor/bin/phpunit --debug --colors=always --bootstrap $(PHPUNIT_ROOT)/vendor/autoload.php --coverage-filter=$(PHPUNIT_ROOT)/src $(options) $(PHPUNIT_ROOT)/test
20-
21-
full-regrest-demo:
22-
$(eval FILTER := $(shell make run command="regrest --changed-since=master --coverage-file=test/Fixtures/PhpProjectUsingPhpunit/test/output/coverage.php --framework=phpunit"))
23-
@echo '.'
24-
make inception-echo argument="--filter option for PHPUnit: '$(FILTER)'"
25-
@echo '.'
26-
make regression-test-phpunit options="--filter '$(FILTER)'";
27-
28-
29-
.PHONY: inseption-echo
30-
inception-echo:
31-
echo $(argument)
5+
.PHONY: run
6+
run:
7+
@${PHP} bin/regrest $(command)
328

33-
#FILTER=`make run command="regrest --changed-since=master --coverage-file=test/Fixtures/PhpProjectUsingPhpunit/test/output/coverage.php --framework=phpunit"`;
34-
#make regression-test-phpunit options="--filter '$FILTER'";
9+
.PHONY: debug
10+
debug:
11+
${PHP} $(XDEBUG_OPTIONS) bin/regrest $(command)
12+
13+
# test regrest <-> PHPUnit, step 1: generate coverage report in .php format
14+
.PHONY: generate-coverage-report-phpunit
15+
generate-coverage-report-phpunit:
16+
${PHP} $(PHPUNIT_ROOT)/vendor/bin/phpunit --debug --colors=always --bootstrap $(PHPUNIT_ROOT)/vendor/autoload.php --coverage-filter=$(PHPUNIT_ROOT)/src --coverage-php=$(PHPUNIT_ROOT)/test/output/coverage.php --coverage-html=$(PHPUNIT_ROOT)/test/output/coverage.html $(PHPUNIT_ROOT)/test
17+
18+
# change .php code under test/Fixtures/PhpProjectUsingPhpunit/src, otherwise regrest will report NOTHING_TO_RUN
19+
20+
# test regrest <-> PHPUnit, step 2: let regrest generate PHPUnit's `--filter` option to run "meaningful" tests only
21+
.PHONY: run-regrest-phpunit
22+
run-regrest-phpunit:
23+
@${MAKE} run command="regrest --changed-since=master --coverage-file=test/Fixtures/PhpProjectUsingPhpunit/test/output/coverage.php --framework=phpunit"
24+
25+
# test regrest <-> PHPUnit, step 3: run PHPUnit test suite with populated `--filter` option, so only the tiny portion of all tests is executed.
26+
.PHONY: run-test-suite-with-regrest-phpunit
27+
run-test-suite-with-regrest-phpunit:
28+
@echo "Run the following command:"
29+
# fish shell
30+
@echo make regression-test-phpunit options=--filter=\"\(make run-regrest-phpunit\)\"
31+
32+
# Regular PHPUnit test suite run <-- this command relates to one from userland Makefile
33+
.PHONY: regression-test-phpunit
34+
regression-test-phpunit:
35+
${PHP} $(PHPUNIT_ROOT)/vendor/bin/phpunit --debug --colors=always --bootstrap $(PHPUNIT_ROOT)/vendor/autoload.php --coverage-filter=$(PHPUNIT_ROOT)/src $(options) $(PHPUNIT_ROOT)/test

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,32 @@ Because there is an infinite amount of edge cases when this approach can lead to
2727
In short, **Regrest detects all software defects introduced by changes of "green" code from test coverage report**.
2828
If the defect is introduced by some other changes (e.g. you messed up Dockerfile of some dependency), this tool cannot detect that.
2929

30-
## Installation.
31-
```bash
32-
git clone https://github.com/ivastly/regrest
33-
ln -s $(pwd)/regrest/bin/regrest /usr/bin/regrest
34-
```
3530

3631
### Prerequisites.
3732
* git as VCS
3833
* fresh coverage report in a machine-readable format
3934

4035

4136
## Usage.
37+
38+
## PHPUnit.
39+
* Make sure coverage report in PHP format `/path/to/coverage.php` is up-to-date.
40+
* Apply your changes to .php files in your project, as usual...
41+
* Pass `regrest` output to PHPUnit's `--filter` option, so only **covering current changes** tests will be run, not all of them.
42+
4243
```bash
43-
# PHPUnit
44-
# In case of PHPUnit, @tests placeholder will be replaced with `--filter 'Path\To\Test1|...|Path\To\TestN'`
44+
phpunit test ..your own phpunit options.. --filter=`docker run ivastly/regrest --changes-since=origin/master --coverage-file=/path/to/coverage.php --framework="phpunit"`
45+
```
4546

46-
regrest --changes-since=origin/master --coverage-file=/path/to/coverage.php --command="vendor/bin/phpunit @tests test" --framework="phpunit"
47+
## Codeception.
48+
```bash
49+
# TODO
4750
```
4851

4952
## How it works in action.
5053
*TODO gif here*
5154

52-
## Supported frameworks.
55+
## Supported test frameworks and coverage formats
5356
Framework | Coverage Format | Language | Support
5457
--- | --- | ---
5558
PHPUnit | PHPUnit .php | PHP | 🟢

ROADMAP.md

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
* `--test-dir` option. If passed, it compares modification time of tests and coverage report.
44
if coverage report is stale, then execution halts with an error:
55
"Tests were changed, please regenerate coverage report.".
6-
* tests

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: '3.8'
33
services:
44
php:
55
build:
6-
context: docker/php
6+
context: docker/php/dev
77
working_dir: /app
88
environment:
99
- PHP_IDE_CONFIG=serverName=docker

docker/php/config/custom-php.ini

-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Error handling
21
log_errors = 1
32
error_log = /logs/php_errors.log
43
error_reporting = E_ALL
@@ -9,7 +8,3 @@ xdebug.remote_host = host.docker.internal
98
xdebug.idekey = IDEKEY
109
xdebug.remote_cookie_expire_time = 1
1110

12-
# with these it will connect whatever it takes
13-
#xdebug.remote_autostart = On
14-
#xdebug.remote_connect_back = 1
15-
File renamed without changes.

docker/php/dockerhub/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ivastly/regrest
2+
FROM php:7.4-cli
3+
RUN apt update \
4+
&& apt install -y git
5+
COPY . /app
6+
WORKDIR /app
7+
ENTRYPOINT ["/app/bin/regrest"]

src/Presentation/Runner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function run(
2929
$testsToRun = $regrest->getListOfTestsToRun();
3030

3131
if ($testsToRun) {
32-
$phpUnitFilterOption = implode('|', $testsToRun);
32+
$phpUnitFilterOption = '"' . implode('|', $testsToRun) . '"';
3333
} else {
3434
$phpUnitFilterOption = 'NOTHING_TO_RUN';
3535
}

test/Fixtures/PhpProjectUsingPhpunit/src/ClassTwo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public function f(): int
1010
{
1111
// This function is fast (see ClassOne::f), unit test will be same fast.
1212

13-
return 1 * 1;
13+
return 1 * 1 * 1;
1414
}
1515
}

0 commit comments

Comments
 (0)