Skip to content

Commit 37f3822

Browse files
committed
Create integration tests
Signed-off-by: Cy Rossignol <[email protected]>
1 parent f8dce34 commit 37f3822

25 files changed

+1830
-94
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
/.gitignore export-ignore
44
/.scrutinizer.yml export-ignore
55
/.travis.yml export-ignore
6+
/docker-compose.yml export-ignore
7+
/phpcs.xml.dist export-ignore
68
/phpspec.yml.dist export-ignore
79
/phpunit.xml.dist export-ignore
10+
/start-cluster.sh export-ignore
811
/tests export-ignore

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
build/
2+
cluster/
23
docs/
34
vendor/
45
composer.phar
56
composer.lock
7+
docker-compose.override.yml
8+
phpcs.xml
69
phpspec.yml
710
phpunit.xml

.travis.yml

+43-41
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,52 @@ language: php
22
dist: trusty
33

44
php:
5-
- 5.6
6-
- 7.0
7-
- 7.1
8-
- 7.2
9-
- hhvm
5+
- 5.6
6+
- 7.0
7+
- 7.1
8+
- 7.2
9+
- hhvm
1010

1111
env:
12-
- LARAVEL_VERSION=">=5.4.0 <5.4.20"
13-
- LARAVEL_VERSION=">=5.4.20 <5.5.0"
14-
- LARAVEL_VERSION="5.5.*"
15-
- LARAVEL_VERSION="5.6.*"
16-
- LUMEN_VERSION="5.4.*"
17-
- LUMEN_VERSION="5.5.*"
18-
- LUMEN_VERSION="5.6.*"
12+
- LARAVEL_VERSION=">=5.4.0 <5.4.20"
13+
- LARAVEL_VERSION=">=5.4.20 <5.5.0"
14+
- LARAVEL_VERSION="5.5.*"
15+
- LARAVEL_VERSION="5.6.*"
16+
- LUMEN_VERSION="5.4.*"
17+
- LUMEN_VERSION="5.5.*"
18+
- LUMEN_VERSION="5.6.*"
1919

2020
matrix:
21-
exclude:
22-
- php: 5.6
23-
env: LARAVEL_VERSION="5.5.*"
24-
- php: 5.6
25-
env: LUMEN_VERSION="5.5.*"
26-
- php: 5.6
27-
env: LARAVEL_VERSION="5.6.*"
28-
- php: 5.6
29-
env: LUMEN_VERSION="5.6.*"
30-
- php: 7.0
31-
env: LARAVEL_VERSION="5.6.*"
32-
- php: 7.0
33-
env: LUMEN_VERSION="5.6.*"
34-
- php: hhvm
35-
env: LARAVEL_VERSION="5.5.*"
36-
- php: hhvm
37-
env: LUMEN_VERSION="5.5.*"
38-
- php: hhvm
39-
env: LARAVEL_VERSION="5.6.*"
40-
- php: hhvm
41-
env: LUMEN_VERSION="5.6.*"
21+
exclude:
22+
- php: 5.6
23+
env: LARAVEL_VERSION="5.5.*"
24+
- php: 5.6
25+
env: LUMEN_VERSION="5.5.*"
26+
- php: 5.6
27+
env: LARAVEL_VERSION="5.6.*"
28+
- php: 5.6
29+
env: LUMEN_VERSION="5.6.*"
30+
- php: 7.0
31+
env: LARAVEL_VERSION="5.6.*"
32+
- php: 7.0
33+
env: LUMEN_VERSION="5.6.*"
34+
- php: hhvm
35+
env: LARAVEL_VERSION="5.5.*"
36+
- php: hhvm
37+
env: LUMEN_VERSION="5.5.*"
38+
- php: hhvm
39+
env: LARAVEL_VERSION="5.6.*"
40+
- php: hhvm
41+
env: LUMEN_VERSION="5.6.*"
4242

43-
before_script:
44-
- if [ -n "$LARAVEL_VERSION" ]; then composer remove --dev --no-update "laravel/lumen-framework"; fi
45-
- if [ -n "$LARAVEL_VERSION" ]; then composer require --no-update "laravel/framework:$LARAVEL_VERSION"; fi
46-
- if [ -n "$LUMEN_VERSION" ]; then composer remove --dev --no-update "laravel/framework"; fi
47-
- if [ -n "$LUMEN_VERSION" ]; then composer require --no-update "laravel/lumen-framework:$LUMEN_VERSION"; fi
48-
- composer install --prefer-source --no-interaction
43+
before_install:
44+
- if [ -n "$LARAVEL_VERSION" ]; then composer remove --dev --no-update "laravel/lumen-framework"; fi
45+
- if [ -n "$LARAVEL_VERSION" ]; then composer require --no-update "laravel/framework:$LARAVEL_VERSION"; fi
46+
- if [ -n "$LUMEN_VERSION" ]; then composer remove --dev --no-update "laravel/framework"; fi
47+
- if [ -n "$LUMEN_VERSION" ]; then composer require --no-update "laravel/lumen-framework:$LUMEN_VERSION"; fi
4948

50-
script:
51-
- vendor/bin/phpunit
49+
install: composer install --prefer-dist --no-interaction --no-suggest
50+
51+
before_script: SUPERVISE=no ./start-cluster.sh || { cat ./cluster/*.log; false; }
52+
53+
script: vendor/bin/phpunit ${LUMEN_VERSION:+--exclude-group laravel-only}

README.md

+69-5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ This example configures the package [through the environment][s-env-config]. It
144144
the configurable environment variables. Optionally, enable the [`RedisSentinel`
145145
facade][s-facade].
146146

147+
For those that need a quick development Sentinel server cluster, try the
148+
[*start-cluster.sh*][s-integration-tests] script included with the package's
149+
testing files.
150+
147151
Configuration
148152
-------------
149153

@@ -661,15 +665,74 @@ Testing
661665
-------
662666

663667
This package includes a PHPUnit test suite with unit tests for the package's
664-
classes. This package does not perform functional/integration tests against
665-
running Redis or Sentinel servers because Predis and Laravel both contain full
666-
test suites, and because the package code simply wraps these libraries. We may
667-
add these types of tests in the future if needed.
668+
classes and an integration test suite for Sentinel-specific functionality and
669+
known issues. These tests do not verify every Redis command because Predis and
670+
Laravel both contain full test suites themselves, and because the package code
671+
simply wraps these libraries.
668672

673+
```shell
674+
$ phpunit --testsuite unit
675+
$ phpunit --testsuite integration
669676
```
670-
$ phpunit
677+
678+
The unit tests do not require live Redis servers. Read the next section for
679+
integration testing environment suggestions.
680+
681+
**Note:** Composer does not download this package's testing files with a normal
682+
installation. We need to clone the package repository directly or install it
683+
with the `--prefer-source` option.
684+
685+
### Integration Tests
686+
687+
This package's integration test suite validates Sentinel- and Redis-specific
688+
functionality against real servers. These tests require at least one Sentinel
689+
server that monitors a Redis master. Additionally, at least one replica should
690+
synchronize with the master for optimal test coverage. Developers may supply
691+
their own servers or start an environment using the package's tools described
692+
below.
693+
694+
To customize the Sentinel connection settings used by the integration tests,
695+
copy *phpunit.xml.dist* to *phpunit.xml* and change the constants defined in
696+
the `<php>...</php>` block.
697+
698+
We can run the [*start-cluster.sh*](start-cluster.sh) script provided in the
699+
project's root directory to spin up Redis and Sentinel servers for a testing
700+
environment. Read the script help page for usage information.
701+
702+
```shell
703+
$ ./start-cluster.sh help
671704
```
672705

706+
Docker users may wish to use the script to start testing servers in a container:
707+
708+
```shell
709+
$ docker run --name redis-sentinel \
710+
-v "$(pwd):/project" \
711+
-w /project \
712+
-u "$(id -u):$(id -g)" \
713+
-e BIND_ADDRESS=0.0.0.0 \
714+
-e SENTINEL_PORTS='26379-26381' \
715+
-e REDIS_GROUP_1='service1 6379-6381' \
716+
-e REDIS_GROUP_2='service2 6382-6384' \
717+
-e LOGGING=yes \
718+
-p 6379-6384:6379-6384 \
719+
-p 26379-26381:26379-26381 \
720+
--entrypoint start-cluster.sh \
721+
redis:alpine
722+
```
723+
724+
The package provides a [Compose file](docker-compose.yml) with the same options
725+
for running tests:
726+
727+
```shell
728+
$ export CONTAINER_USER_ID="$(id -u):$(id -g)"
729+
$ docker-compose up -d cluster
730+
$ docker-compose run --rm tests [--testsuite ...]
731+
```
732+
733+
Developers can also customize the Compose file by copying *docker-compose.yml*
734+
to *docker-compose.override.yml*.
735+
673736
License
674737
-------
675738

@@ -986,6 +1049,7 @@ Sentinel Documentation][sentinel].
9861049
[s-env-config-examples]: #environment-based-configuration-examples
9871050
[s-facade]: #executing-redis-commands-redissentinel-facade
9881051
[s-hybrid-config]: #hybrid-configuration
1052+
[s-integration-tests]: #integration-tests
9891053
[s-multi-sentinel-example]: #multi-sentinel-connection-configuration
9901054
[s-multi-service-example]: #multi-service-connection-configuration
9911055
[s-multiple-hosts]: #specifying-multiple-hosts

docker-compose.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "3"
2+
3+
services:
4+
5+
cluster:
6+
image: redis:alpine
7+
entrypoint: ./start-cluster.sh
8+
working_dir: /project
9+
user: "${CONTAINER_USER_ID:-root:root}"
10+
environment:
11+
BIND_ADDRESS: "0.0.0.0"
12+
SENTINEL_PORTS: "26379-26381"
13+
REDIS_GROUP_1: "service1 6379-6381"
14+
REDIS_GROUP_2: "service2 6382-6384"
15+
LOGGING: "yes"
16+
ports:
17+
- "6379-6384:6379-6384"
18+
- "26379-26381:26379-26381"
19+
volumes:
20+
- ./:/project
21+
22+
tests:
23+
image: phpunit/phpunit:latest
24+
entrypoint: vendor/bin/phpunit --colors=always
25+
network_mode: host
26+
user: "${CONTAINER_USER_ID:-root:root}"
27+
volumes:
28+
- ./:/app

phpunit.xml.dist

+17-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
stopOnFailure="false">
1313

1414
<testsuites>
15-
<testsuite name="Example">
16-
<directory>tests</directory>
15+
<testsuite name="unit">
16+
<directory>tests/Unit</directory>
17+
</testsuite>
18+
<testsuite name="integration">
19+
<directory>tests/Integration</directory>
1720
</testsuite>
1821
</testsuites>
1922

@@ -23,11 +26,23 @@
2326
</whitelist>
2427
</filter>
2528

29+
<php>
30+
<!-- Integration test configuration: -->
31+
<const name="TEST_REDIS_SENTINEL_HOST"
32+
value="127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381"/>
33+
<const name="TEST_REDIS_SENTINEL_SERVICE" value="service1"/>
34+
<const name="TEST_REDIS_DATABASE" value="15"/>
35+
<const name="TEST_MAX_CONNECTION_TIMEOUT" value="5.0"/>
36+
<const name="TEST_MIN_CONNECTION_TIMEOUT" value="0.1"/>
37+
</php>
38+
39+
<!--
2640
<logging>
2741
<log type="tap" target="build/report.tap"/>
2842
<log type="junit" target="build/report.junit.xml"/>
2943
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
3044
<log type="coverage-text" target="build/coverage.txt"/>
3145
<log type="coverage-clover" target="build/clover.xml"/>
3246
</logging>
47+
-->
3348
</phpunit>

0 commit comments

Comments
 (0)