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

Commit

Permalink
bootstrap a testing worthy nginx-fpm-php setup
Browse files Browse the repository at this point in the history
  • Loading branch information
schnipseljagd committed Jun 23, 2016
1 parent 3aa8615 commit 31e40f0
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 16 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -31,3 +31,11 @@ composer install
# export REDIS_HOST=192.168.59.100
./vendor/bin/phpunit
```

## Black box testing

Just start the nginx, fpm & redis setup with docker-compose:
```
docker-compose up
vendor/bin/phpunit tests/Test/BlackBoxTest.php
```
15 changes: 13 additions & 2 deletions docker-compose.yml
@@ -1,9 +1,20 @@
client_php:
nginx:
build: nginx/
links:
- php-fpm
ports:
- 8080:80

php-fpm:
build: .
volumes:
- .:/prometheus_client_php
- .:/var/www/html
links:
- redis
environment:
- REDIS_HOST=redis

redis:
image: redis
ports:
- 6379:6379
4 changes: 3 additions & 1 deletion examples/flush_redis.php
@@ -1,5 +1,7 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

$redisAdapter = new \Prometheus\RedisAdapter('localhost');
define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1');

$redisAdapter = new \Prometheus\RedisAdapter(REDIS_HOST);
$redisAdapter->flushRedis();
4 changes: 3 additions & 1 deletion examples/metrics.php
Expand Up @@ -4,7 +4,9 @@
use Prometheus\RedisAdapter;
use Prometheus\Registry;

$redisAdapter = new RedisAdapter('localhost');
define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1');

$redisAdapter = new RedisAdapter(REDIS_HOST);
$registry = new Registry($redisAdapter);
$result = $registry->toText();

Expand Down
6 changes: 5 additions & 1 deletion examples/some_request_uri.php
@@ -1,7 +1,11 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

$redisAdapter = new \Prometheus\RedisAdapter('localhost');
define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1');

error_log('c='. $_GET['c']);

$redisAdapter = new \Prometheus\RedisAdapter(REDIS_HOST);
$registry = new \Prometheus\Registry($redisAdapter);
$counter = $registry->registerGauge('test', 'some_gauge', 'it sets', ['type']);
$counter->set(234, ['blue']);
Expand Down
4 changes: 4 additions & 0 deletions nginx/Dockerfile
@@ -0,0 +1,4 @@
FROM nginx

RUN rm /etc/nginx/conf.d/default.conf
ADD default.conf /etc/nginx/conf.d/
16 changes: 16 additions & 0 deletions nginx/default.conf
@@ -0,0 +1,16 @@
server {
listen 80;

root /var/www/html;

error_log /var/log/nginx/localhost.error.log;
access_log /var/log/nginx/localhost.access.log;

location ~ ^/.+\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
@@ -1,7 +1,7 @@
<phpunit colors="true" bootstrap="./tests/bootstrap.php">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/Test/</directory>
<directory>./tests/Test/Prometheus</directory>
</testsuite>
</testsuites>
</phpunit>
20 changes: 10 additions & 10 deletions tests/Test/BlackBoxTest.php
Expand Up @@ -17,16 +17,16 @@ public function countersShouldIncrementAtomically()

$start = microtime(true);
$promises = [
$client->getAsync('/examples/some_request_uri.php?0'),
$client->getAsync('/examples/some_request_uri.php?1'),
$client->getAsync('/examples/some_request_uri.php?2'),
$client->getAsync('/examples/some_request_uri.php?3'),
$client->getAsync('/examples/some_request_uri.php?4'),
$client->getAsync('/examples/some_request_uri.php?5'),
$client->getAsync('/examples/some_request_uri.php?6'),
$client->getAsync('/examples/some_request_uri.php?7'),
$client->getAsync('/examples/some_request_uri.php?8'),
$client->getAsync('/examples/some_request_uri.php?9'),
$client->getAsync('/examples/some_request_uri.php?c=0'),
$client->getAsync('/examples/some_request_uri.php?c=1'),
$client->getAsync('/examples/some_request_uri.php?c=2'),
$client->getAsync('/examples/some_request_uri.php?c=3'),
$client->getAsync('/examples/some_request_uri.php?c=4'),
$client->getAsync('/examples/some_request_uri.php?c=5'),
$client->getAsync('/examples/some_request_uri.php?c=6'),
$client->getAsync('/examples/some_request_uri.php?c=7'),
$client->getAsync('/examples/some_request_uri.php?c=8'),
$client->getAsync('/examples/some_request_uri.php?c=9'),
];

Promise\settle($promises)->wait();
Expand Down

0 comments on commit 31e40f0

Please sign in to comment.