Skip to content

Commit 9719f29

Browse files
authored
feat: add functional tests (#5)
contributors: @cHeeSaW
1 parent c27d358 commit 9719f29

File tree

8 files changed

+177
-2
lines changed

8 files changed

+177
-2
lines changed

.travis.yml

+39
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,45 @@ jobs:
1616
env: SYMFONY_VERSION="5.0.*"
1717
- php: '7.4'
1818
env: SYMFONY_VERSION="5.0.*"
19+
- stage: test-functional
20+
php: '7.4'
21+
env:
22+
- SYMFONY_VERSION="3.4.*"
23+
- BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
24+
services: docker
25+
before_script:
26+
- wget https://get.symfony.com/cli/installer -O - | bash
27+
- sudo mv /home/travis/.symfony/bin/symfony /usr/local/bin/symfony
28+
script:
29+
- composer run-script phpunit-functional
30+
after_success:
31+
- docker ps
32+
- stage: test-functional
33+
php: '7.4'
34+
env:
35+
- SYMFONY_VERSION="4.4.*"
36+
- BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
37+
services: docker
38+
before_script:
39+
- wget https://get.symfony.com/cli/installer -O - | bash
40+
- sudo mv /home/travis/.symfony/bin/symfony /usr/local/bin/symfony
41+
script:
42+
- composer run-script phpunit-functional
43+
after_success:
44+
- docker ps
45+
- stage: test-functional
46+
php: '7.4'
47+
env:
48+
- SYMFONY_VERSION="5.0.*"
49+
- BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
50+
services: docker
51+
before_script:
52+
- wget https://get.symfony.com/cli/installer -O - | bash
53+
- sudo mv /home/travis/.symfony/bin/symfony /usr/local/bin/symfony
54+
script:
55+
- composer run-script phpunit-functional
56+
after_success:
57+
- docker ps
1958

2059
before_install:
2160
- composer global require hirak/prestissimo

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# auxmoney OpentracingBundle - Zipkin
22

3+
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/auxmoney/OpentracingBundle-Zipkin)
4+
![Travis (.org)](https://img.shields.io/travis/auxmoney/OpentracingBundle-Zipkin)
5+
![Coveralls github](https://img.shields.io/coveralls/github/auxmoney/OpentracingBundle-Zipkin)
6+
![Codacy Badge](https://api.codacy.com/project/badge/Grade/626c5a0a955b4318bb9a4f82bd2ee7a2)
7+
![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/auxmoney/OpentracingBundle-Zipkin)
8+
![Scrutinizer code quality (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/quality/g/auxmoney/OpentracingBundle-Zipkin)
9+
![GitHub](https://img.shields.io/github/license/auxmoney/OpentracingBundle-Zipkin)
10+
311
This symfony bundle provides a tracer implementation for [Zipkin](https://zipkin.io/) for the [auxmoney OpentracingBundle](https://github.com/auxmoney/OpentracingBundle-core).
412

513
Please have a look at [the central documentation](https://github.com/auxmoney/OpentracingBundle-core) for installation and usage instructions.

Tests/Functional/FunctionalTest.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Auxmoney\OpentracingBundle\Tests\Functional;
6+
7+
use GuzzleHttp\Client;
8+
use PHPUnit\Framework\TestCase;
9+
use Symfony\Component\Filesystem\Filesystem;
10+
use Symfony\Component\Process\Process;
11+
12+
class FunctionalTest extends TestCase
13+
{
14+
public function testSuccessfulTracing(): void
15+
{
16+
$this->setupTestProject();
17+
18+
$p = new Process(['symfony', 'console', 'test:zipkin'], 'build/testproject');
19+
$p->mustRun();
20+
$traceId = trim($p->getOutput());
21+
self::assertNotEmpty($traceId);
22+
23+
$spans = $this->getTraceFromZipkinAPI($traceId);
24+
self::assertCount(1, $spans);
25+
self::assertSame('test:zipkin', $spans[0]['name']);
26+
}
27+
28+
public function setUp()
29+
{
30+
parent::setUp();
31+
32+
$p = new Process(['docker', 'start', 'zipkin']);
33+
$p->mustRun();
34+
35+
sleep(10);
36+
}
37+
38+
protected function tearDown()
39+
{
40+
$p = new Process(['git', 'reset', '--hard', 'reset'], 'build/testproject');
41+
$p->mustRun();
42+
$p = new Process(['docker', 'stop', 'zipkin']);
43+
$p->mustRun();
44+
45+
parent::tearDown();
46+
}
47+
48+
private function getTraceFromZipkinAPI(string $traceId): array
49+
{
50+
$client = new Client();
51+
$response = $client->get(sprintf('http://localhost:9411/zipkin/api/v2/trace/%s', $traceId));
52+
return json_decode($response->getBody()->getContents(), true);
53+
}
54+
55+
private function setupTestProject(): void
56+
{
57+
$filesystem = new Filesystem();
58+
$filesystem->mirror(sprintf('Tests/Functional/TestProjectFiles/default/'), 'build/testproject/');
59+
60+
$p = new Process(['composer', 'dump-autoload'], 'build/testproject');
61+
$p->mustRun();
62+
$p = new Process(['symfony', 'console', 'cache:clear'], 'build/testproject');
63+
$p->mustRun();
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
docker rm zipkin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
cd build/testproject/
4+
composer remove auxmoney/opentracing-bundle-jaeger
5+
composer require auxmoney/opentracing-bundle-zipkin:dev-${BRANCH}
6+
cd ../../
7+
8+
docker run -d -p 9411:9411 --name zipkin openzipkin/zipkin:2.19
9+
sleep 5
10+
docker stop zipkin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Command;
6+
7+
use Auxmoney\OpentracingBundle\Internal\Opentracing;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use const OpenTracing\Formats\TEXT_MAP;
12+
13+
class TestCommand extends Command
14+
{
15+
private $opentracing;
16+
17+
public function __construct(Opentracing $opentracing)
18+
{
19+
parent::__construct('test:zipkin');
20+
$this->setDescription('some fancy command description');
21+
$this->opentracing = $opentracing;
22+
}
23+
24+
protected function execute(InputInterface $input, OutputInterface $output)
25+
{
26+
$carrier = [];
27+
$this->opentracing->getTracerInstance()->inject($this->opentracing->getTracerInstance()->getActiveSpan()->getContext(), TEXT_MAP, $carrier);
28+
$output->writeln(current($carrier));
29+
return 0;
30+
}
31+
}

composer.json

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
"phpstan/phpstan": "^0.12",
2929
"squizlabs/php_codesniffer": "^3.5",
3030
"phpmd/phpmd": "^2.7",
31-
"php-coveralls/php-coveralls": "^2.2"
31+
"php-coveralls/php-coveralls": "^2.2",
32+
"symfony/filesystem": "*",
33+
"symfony/process": "*",
34+
"symfony/yaml": "*",
35+
"mtdowling/jmespath.php": "^2.5"
3236
},
3337
"autoload": {
3438
"psr-4": {
@@ -49,7 +53,16 @@
4953
],
5054
"phpmd": "vendor/bin/phpmd . text cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor,Tests",
5155
"phpcs": "vendor/bin/phpcs",
52-
"phpunit": "phpdbg -qrr vendor/bin/phpunit --colors=never",
56+
"phpunit": "phpdbg -qrr vendor/bin/phpunit --colors=never --testsuite=unit",
57+
"phpunit-functional": [
58+
"vendor/auxmoney/opentracing-bundle-core/Tests/Functional/Scripts/checkEnvironment.sh",
59+
"vendor/auxmoney/opentracing-bundle-core/Tests/Functional/Scripts/setup.sh",
60+
"Tests/Functional/Scripts/requireAdditionalVendors.sh",
61+
"vendor/auxmoney/opentracing-bundle-core/Tests/Functional/Scripts/createResetPoint.sh",
62+
"vendor/bin/phpunit --colors=never --testsuite=functional --no-coverage",
63+
"Tests/Functional/Scripts/additionalTeardown.sh",
64+
"vendor/auxmoney/opentracing-bundle-core/Tests/Functional/Scripts/teardown.sh"
65+
],
5366
"phpstan": "vendor/bin/phpstan analyse --no-progress"
5467
}
5568
}

phpunit.xml.dist

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
<testsuites>
2121
<testsuite name="unit">
2222
<directory>./Tests/</directory>
23+
<exclude>./Tests/Functional</exclude>
24+
</testsuite>
25+
<testsuite name="functional">
26+
<directory>./Tests/Functional/</directory>
27+
<exclude>./Tests/Functional/Scripts</exclude>
28+
<exclude>./Tests/Functional/TestProjectFiles</exclude>
2329
</testsuite>
2430
</testsuites>
2531

0 commit comments

Comments
 (0)