Skip to content

Commit 34a6a9c

Browse files
alexkartzhuravljov
authored andcommitted
Add documentation for running tests. (yiisoft#331, yiisoft#328)
1 parent c5e75f9 commit 34a6a9c

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
COMPOSE_PROJECT_NAME=yii2-queue
22
COMPOSE_FILE=tests/docker-compose.yml
3+
4+
AWS_SQS_ENABLED=
5+
AWS_SQS_URL=
6+
AWS_KEY=
7+
AWS_SECRET=
8+
AWS_REGION=

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ composer.lock
1818
.php_cs.cache
1919

2020
# Env variables
21-
.env
21+
.env
22+
php.env

docs/guide/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ Developer tools
2828

2929
* [Debugging](debug.md)
3030
* [Code generator Gii](gii.md)
31+
32+
Contributing
33+
------------
34+
* [Tests](tests.md)

docs/guide/tests.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Tests
2+
=====
3+
4+
Environment
5+
-----------
6+
7+
In order to run tests, you need to install Docker, Docker Compose and the `make` utility. Docker configuration files are
8+
in `tests/docker` and Docker Compose file is `tests/docker-compose.yml`. There are configurations for different versions
9+
of PHP (5.6, 7.0, 7.1, 7.2, 7.3). You need to create `.env` file to specify where the `docker-compose.yml` file is. You
10+
can create `.env` file from `.env.example` in the root directory of the project.
11+
12+
Running Tests
13+
-------------
14+
15+
To run tests execute the following command:
16+
17+
```bash
18+
# for all PHP versions
19+
make test
20+
21+
# for PHP 7.3 only
22+
make test73
23+
```
24+
25+
If you need to pass options to `phpunit` use the following commands (for example, to run only one test file):
26+
```bash
27+
docker-compose build --pull php73
28+
docker-compose run php73 vendor/bin/phpunit tests\\drivers\\sqs\\QueueTest /vagrant/yii2-queue/tests/drivers/sqs/QueueTest.php
29+
docker-compose down
30+
```
31+
32+
Some tests can be disabled by default for various reasons (for example, the AWS SQS test require a queue set up in AWS).
33+
The test checks `AWS_SQS_ENABLED` environment variable (see `\tests\drivers\sqs\QueueTest::setUp`). If you want to
34+
run that test you need to set this variable to `1`. You can specify environment variables that you need to pass to
35+
the container in the `.env` file in the base directory (see `.env.example`). AWS SQS test requires queue credentials that you also
36+
need to pass to the container via `.env` file (see `tests/app/config/main.php`).
37+
38+
```bash
39+
# .env
40+
41+
AWS_SQS_ENABLED=1
42+
AWS_KEY=KEY
43+
AWS_SECRET=SECRET
44+
AWS_REGION=us-east-1
45+
AWS_SQS_URL=https://sqs.us-east-1.amazonaws.com/234888945020/queue1
46+
```
47+
48+
```bash
49+
# AWS SQS test will not be skipped now
50+
make test73
51+
```

tests/docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ services:
2929
BEANSTALK_HOST: beanstalk
3030
GEARMAN_HOST: gearmand
3131
COMPOSER_ALLOW_SUPERUSER: 1
32+
AWS_SQS_ENABLED: ${AWS_SQS_ENABLED}
33+
AWS_KEY: ${AWS_KEY}
34+
AWS_SECRET: ${AWS_SECRET}
35+
AWS_REGION: ${AWS_REGION}
36+
AWS_SQS_URL: ${AWS_SQS_URL}
3237
depends_on: &php_depends_on
3338
- mysql
3439
- postgres

0 commit comments

Comments
 (0)