Skip to content
This repository was archived by the owner on Oct 22, 2019. It is now read-only.

Commit 31e40f0

Browse files
committed
bootstrap a testing worthy nginx-fpm-php setup
1 parent 3aa8615 commit 31e40f0

9 files changed

+63
-16
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ composer install
3131
# export REDIS_HOST=192.168.59.100
3232
./vendor/bin/phpunit
3333
```
34+
35+
## Black box testing
36+
37+
Just start the nginx, fpm & redis setup with docker-compose:
38+
```
39+
docker-compose up
40+
vendor/bin/phpunit tests/Test/BlackBoxTest.php
41+
```

docker-compose.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
client_php:
1+
nginx:
2+
build: nginx/
3+
links:
4+
- php-fpm
5+
ports:
6+
- 8080:80
7+
8+
php-fpm:
29
build: .
310
volumes:
4-
- .:/prometheus_client_php
11+
- .:/var/www/html
512
links:
613
- redis
14+
environment:
15+
- REDIS_HOST=redis
716

817
redis:
918
image: redis
19+
ports:
20+
- 6379:6379

examples/flush_redis.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
require __DIR__ . '/../vendor/autoload.php';
33

4-
$redisAdapter = new \Prometheus\RedisAdapter('localhost');
4+
define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1');
5+
6+
$redisAdapter = new \Prometheus\RedisAdapter(REDIS_HOST);
57
$redisAdapter->flushRedis();

examples/metrics.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
use Prometheus\RedisAdapter;
55
use Prometheus\Registry;
66

7-
$redisAdapter = new RedisAdapter('localhost');
7+
define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1');
8+
9+
$redisAdapter = new RedisAdapter(REDIS_HOST);
810
$registry = new Registry($redisAdapter);
911
$result = $registry->toText();
1012

examples/some_request_uri.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
22
require __DIR__ . '/../vendor/autoload.php';
33

4-
$redisAdapter = new \Prometheus\RedisAdapter('localhost');
4+
define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1');
5+
6+
error_log('c='. $_GET['c']);
7+
8+
$redisAdapter = new \Prometheus\RedisAdapter(REDIS_HOST);
59
$registry = new \Prometheus\Registry($redisAdapter);
610
$counter = $registry->registerGauge('test', 'some_gauge', 'it sets', ['type']);
711
$counter->set(234, ['blue']);

nginx/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM nginx
2+
3+
RUN rm /etc/nginx/conf.d/default.conf
4+
ADD default.conf /etc/nginx/conf.d/

nginx/default.conf

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
server {
2+
listen 80;
3+
4+
root /var/www/html;
5+
6+
error_log /var/log/nginx/localhost.error.log;
7+
access_log /var/log/nginx/localhost.access.log;
8+
9+
location ~ ^/.+\.php(/|$) {
10+
fastcgi_pass php-fpm:9000;
11+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
12+
include fastcgi_params;
13+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
14+
fastcgi_param HTTPS off;
15+
}
16+
}

phpunit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<phpunit colors="true" bootstrap="./tests/bootstrap.php">
22
<testsuites>
33
<testsuite name="Test Suite">
4-
<directory>./tests/Test/</directory>
4+
<directory>./tests/Test/Prometheus</directory>
55
</testsuite>
66
</testsuites>
77
</phpunit>

tests/Test/BlackBoxTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public function countersShouldIncrementAtomically()
1717

1818
$start = microtime(true);
1919
$promises = [
20-
$client->getAsync('/examples/some_request_uri.php?0'),
21-
$client->getAsync('/examples/some_request_uri.php?1'),
22-
$client->getAsync('/examples/some_request_uri.php?2'),
23-
$client->getAsync('/examples/some_request_uri.php?3'),
24-
$client->getAsync('/examples/some_request_uri.php?4'),
25-
$client->getAsync('/examples/some_request_uri.php?5'),
26-
$client->getAsync('/examples/some_request_uri.php?6'),
27-
$client->getAsync('/examples/some_request_uri.php?7'),
28-
$client->getAsync('/examples/some_request_uri.php?8'),
29-
$client->getAsync('/examples/some_request_uri.php?9'),
20+
$client->getAsync('/examples/some_request_uri.php?c=0'),
21+
$client->getAsync('/examples/some_request_uri.php?c=1'),
22+
$client->getAsync('/examples/some_request_uri.php?c=2'),
23+
$client->getAsync('/examples/some_request_uri.php?c=3'),
24+
$client->getAsync('/examples/some_request_uri.php?c=4'),
25+
$client->getAsync('/examples/some_request_uri.php?c=5'),
26+
$client->getAsync('/examples/some_request_uri.php?c=6'),
27+
$client->getAsync('/examples/some_request_uri.php?c=7'),
28+
$client->getAsync('/examples/some_request_uri.php?c=8'),
29+
$client->getAsync('/examples/some_request_uri.php?c=9'),
3030
];
3131

3232
Promise\settle($promises)->wait();

0 commit comments

Comments
 (0)