Skip to content

Commit

Permalink
feat: add functional tests (#5)
Browse files Browse the repository at this point in the history
contributors: @cHeeSaW
  • Loading branch information
cawolf authored Feb 20, 2020
1 parent c27d358 commit 9719f29
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 2 deletions.
39 changes: 39 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,45 @@ jobs:
env: SYMFONY_VERSION="5.0.*"
- php: '7.4'
env: SYMFONY_VERSION="5.0.*"
- stage: test-functional
php: '7.4'
env:
- SYMFONY_VERSION="3.4.*"
- BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
services: docker
before_script:
- wget https://get.symfony.com/cli/installer -O - | bash
- sudo mv /home/travis/.symfony/bin/symfony /usr/local/bin/symfony
script:
- composer run-script phpunit-functional
after_success:
- docker ps
- stage: test-functional
php: '7.4'
env:
- SYMFONY_VERSION="4.4.*"
- BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
services: docker
before_script:
- wget https://get.symfony.com/cli/installer -O - | bash
- sudo mv /home/travis/.symfony/bin/symfony /usr/local/bin/symfony
script:
- composer run-script phpunit-functional
after_success:
- docker ps
- stage: test-functional
php: '7.4'
env:
- SYMFONY_VERSION="5.0.*"
- BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
services: docker
before_script:
- wget https://get.symfony.com/cli/installer -O - | bash
- sudo mv /home/travis/.symfony/bin/symfony /usr/local/bin/symfony
script:
- composer run-script phpunit-functional
after_success:
- docker ps

before_install:
- composer global require hirak/prestissimo
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# auxmoney OpentracingBundle - Zipkin

![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/auxmoney/OpentracingBundle-Zipkin)
![Travis (.org)](https://img.shields.io/travis/auxmoney/OpentracingBundle-Zipkin)
![Coveralls github](https://img.shields.io/coveralls/github/auxmoney/OpentracingBundle-Zipkin)
![Codacy Badge](https://api.codacy.com/project/badge/Grade/626c5a0a955b4318bb9a4f82bd2ee7a2)
![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/auxmoney/OpentracingBundle-Zipkin)
![Scrutinizer code quality (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/quality/g/auxmoney/OpentracingBundle-Zipkin)
![GitHub](https://img.shields.io/github/license/auxmoney/OpentracingBundle-Zipkin)

This symfony bundle provides a tracer implementation for [Zipkin](https://zipkin.io/) for the [auxmoney OpentracingBundle](https://github.com/auxmoney/OpentracingBundle-core).

Please have a look at [the central documentation](https://github.com/auxmoney/OpentracingBundle-core) for installation and usage instructions.
65 changes: 65 additions & 0 deletions Tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace Auxmoney\OpentracingBundle\Tests\Functional;

use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;

class FunctionalTest extends TestCase
{
public function testSuccessfulTracing(): void
{
$this->setupTestProject();

$p = new Process(['symfony', 'console', 'test:zipkin'], 'build/testproject');
$p->mustRun();
$traceId = trim($p->getOutput());
self::assertNotEmpty($traceId);

$spans = $this->getTraceFromZipkinAPI($traceId);
self::assertCount(1, $spans);
self::assertSame('test:zipkin', $spans[0]['name']);
}

public function setUp()
{
parent::setUp();

$p = new Process(['docker', 'start', 'zipkin']);
$p->mustRun();

sleep(10);
}

protected function tearDown()
{
$p = new Process(['git', 'reset', '--hard', 'reset'], 'build/testproject');
$p->mustRun();
$p = new Process(['docker', 'stop', 'zipkin']);
$p->mustRun();

parent::tearDown();
}

private function getTraceFromZipkinAPI(string $traceId): array
{
$client = new Client();
$response = $client->get(sprintf('http://localhost:9411/zipkin/api/v2/trace/%s', $traceId));
return json_decode($response->getBody()->getContents(), true);
}

private function setupTestProject(): void
{
$filesystem = new Filesystem();
$filesystem->mirror(sprintf('Tests/Functional/TestProjectFiles/default/'), 'build/testproject/');

$p = new Process(['composer', 'dump-autoload'], 'build/testproject');
$p->mustRun();
$p = new Process(['symfony', 'console', 'cache:clear'], 'build/testproject');
$p->mustRun();
}
}
3 changes: 3 additions & 0 deletions Tests/Functional/Scripts/additionalTeardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker rm zipkin
10 changes: 10 additions & 0 deletions Tests/Functional/Scripts/requireAdditionalVendors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

cd build/testproject/
composer remove auxmoney/opentracing-bundle-jaeger
composer require auxmoney/opentracing-bundle-zipkin:dev-${BRANCH}
cd ../../

docker run -d -p 9411:9411 --name zipkin openzipkin/zipkin:2.19
sleep 5
docker stop zipkin
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Command;

use Auxmoney\OpentracingBundle\Internal\Opentracing;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use const OpenTracing\Formats\TEXT_MAP;

class TestCommand extends Command
{
private $opentracing;

public function __construct(Opentracing $opentracing)
{
parent::__construct('test:zipkin');
$this->setDescription('some fancy command description');
$this->opentracing = $opentracing;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$carrier = [];
$this->opentracing->getTracerInstance()->inject($this->opentracing->getTracerInstance()->getActiveSpan()->getContext(), TEXT_MAP, $carrier);
$output->writeln(current($carrier));
return 0;
}
}
17 changes: 15 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
"phpstan/phpstan": "^0.12",
"squizlabs/php_codesniffer": "^3.5",
"phpmd/phpmd": "^2.7",
"php-coveralls/php-coveralls": "^2.2"
"php-coveralls/php-coveralls": "^2.2",
"symfony/filesystem": "*",
"symfony/process": "*",
"symfony/yaml": "*",
"mtdowling/jmespath.php": "^2.5"
},
"autoload": {
"psr-4": {
Expand All @@ -49,7 +53,16 @@
],
"phpmd": "vendor/bin/phpmd . text cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor,Tests",
"phpcs": "vendor/bin/phpcs",
"phpunit": "phpdbg -qrr vendor/bin/phpunit --colors=never",
"phpunit": "phpdbg -qrr vendor/bin/phpunit --colors=never --testsuite=unit",
"phpunit-functional": [
"vendor/auxmoney/opentracing-bundle-core/Tests/Functional/Scripts/checkEnvironment.sh",
"vendor/auxmoney/opentracing-bundle-core/Tests/Functional/Scripts/setup.sh",
"Tests/Functional/Scripts/requireAdditionalVendors.sh",
"vendor/auxmoney/opentracing-bundle-core/Tests/Functional/Scripts/createResetPoint.sh",
"vendor/bin/phpunit --colors=never --testsuite=functional --no-coverage",
"Tests/Functional/Scripts/additionalTeardown.sh",
"vendor/auxmoney/opentracing-bundle-core/Tests/Functional/Scripts/teardown.sh"
],
"phpstan": "vendor/bin/phpstan analyse --no-progress"
}
}
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<testsuites>
<testsuite name="unit">
<directory>./Tests/</directory>
<exclude>./Tests/Functional</exclude>
</testsuite>
<testsuite name="functional">
<directory>./Tests/Functional/</directory>
<exclude>./Tests/Functional/Scripts</exclude>
<exclude>./Tests/Functional/TestProjectFiles</exclude>
</testsuite>
</testsuites>

Expand Down

0 comments on commit 9719f29

Please sign in to comment.