Skip to content

Commit

Permalink
Merge pull request #82 from jcchavezs/php_8_support
Browse files Browse the repository at this point in the history
chore: adds support for PHP 8.0 and 8.1.
  • Loading branch information
jcchavezs authored Nov 7, 2021
2 parents 7518deb + 8cef1d4 commit cb2a1d4
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 73 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ workflows:
all-tests:
jobs:
- e2e:
context:
- composer-auth # check https://app.circleci.com/settings/organization/github/jcchavezs/contexts
matrix:
parameters:
php-version: ["7.1", "7.2", "7.3", "7.4"]
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches:
- master
paths-ignore:
- "**/*.md"
- "LICENSE"
pull_request:
paths-ignore:
- "**/*.md"
- "LICENSE"

jobs:
run:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- php-version: "7.1"
symfony-version: "4.4"
- php-version: "7.2"
symfony-version: "4.4"
- php-version: "7.3"
symfony-version: "4.4"
- php-version: "7.2"
symfony-version: "5.0"
- php-version: "7.3"
symfony-version: "5.0"
- php-version: "7.4"
symfony-version: "5.0"
- php-version: "8.0"
symfony-version: "5.0"
- php-version: "8.1"
symfony-version: "5.0"
name: PHP ${{ matrix.php-version }} Test on Symfony ${{ matrix.symfony-version }}

steps:
- name: Checkout
uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Install dependencies
run: |
composer require symfony/config:"^${{ matrix.symfony-version }}" symfony/http-kernel:"^${{ matrix.symfony-version }}" symfony/routing:"^${{ matrix.symfony-version }}" symfony/dependency-injection:"^${{ matrix.symfony-version }}"
composer require --dev symfony/http-client:"^${{ matrix.symfony-version }}"
composer install
- name: Run coding style checking
run: composer lint

- name: Run tests
run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
composer.phar
/vendor/
.phpunit.result.cache
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"description": "A Zipkin integration for Symfony applications",
"type": "symfony-bundle",
"require": {
"symfony/config": "^4.4|^5.0",
"symfony/http-kernel": "^4.4|^5.0",
"symfony/routing": "^4.4|^5.0",
"symfony/dependency-injection": "^4.4|^5.0",
"openzipkin/zipkin": "^2.0.1"
"symfony/config": "^4.4||^5.0",
"symfony/http-kernel": "^4.4||^5.0",
"symfony/routing": "^4.4||^5.0",
"symfony/dependency-injection": "^4.4||^5.0",
"openzipkin/zipkin": "^2.0.2 || 3.0.0-rc.2"
},
"require-dev": {
"jcchavezs/httptest": "~0.2",
"phpunit/phpunit": "^6.5.14",
"phpunit/phpunit": "~7||~8",
"squizlabs/php_codesniffer": "^3.0@dev",
"symfony/http-client": "^4.4|^5.0"
"symfony/http-client": "^4.4||^5.0"
},
"license": "MIT",
"minimum-stability": "stable",
Expand All @@ -39,4 +39,4 @@
"lint": "./vendor/bin/phpcs --standard=ZEND --standard=PSR2 --ignore=*/vendor/* --ignore=*/tests/E2E/test-app/* ./",
"fix-lint": "./vendor/bin/phpcbf --standard=ZEND --standard=PSR2 --ignore=*/vendor/* --ignore=*/tests/Integration/test-app/* ./"
}
}
}
5 changes: 2 additions & 3 deletions src/ZipkinBundle/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace ZipkinBundle;

use function Zipkin\Timestamp\now;
use Zipkin\Tracing;
use Zipkin\Tracer;
use Zipkin\Tags;
Expand All @@ -16,14 +15,14 @@
use Symfony\Component\HttpFoundation\Request;
use Psr\Log\LoggerInterface;
use Exception;
use function Zipkin\Timestamp\now;

/**
* @deprecated use KernelListener instead.
*/

final class Middleware
{
const SCOPE_CLOSER_KEY = 'zipkin_bundle_scope_closer';
public const SCOPE_CLOSER_KEY = 'zipkin_bundle_scope_closer';

/**
* @var Tracer
Expand Down
2 changes: 1 addition & 1 deletion tests/E2E/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COMPOSER_RUNNER=${COMPOSER_RUNNER:-${DEFAULT_COMPOSER_RUNNER}}
# Deletes old executions of the build
rm -rf ${APP_FOLDER}

${COMPOSER_RUNNER} create-project symfony/website-skeleton:^${SYMFONY_VERSION} ${APP_FOLDER} || exit 1
${COMPOSER_RUNNER} create-project --prefer-dist --no-interaction symfony/website-skeleton:^${SYMFONY_VERSION} ${APP_FOLDER} || exit 1
cd ${APP_FOLDER}

# Includes zipkin-instrumentation-symfony to the composer.json of the app
Expand Down
38 changes: 24 additions & 14 deletions tests/Integration/Components/HttpClientTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php

namespace ZipkinTests\Integration\Reporters\Http;
namespace ZipkinBundle\Integration\Reporters\Http;

use Zipkin\TracingBuilder;
use HttpTest\HttpTestServer;
use Zipkin\Samplers\BinarySampler;
use Zipkin\Reporters\InMemory;
use PHPUnit\Framework\TestCase;
use Zipkin\Recording\ReadbackSpan;
use ZipkinBundle\Components\HttpClient\HttpClient;
use Symfony\Component\HttpClient\NativeHttpClient;
use Symfony\Component\HttpClient\CurlHttpClient;
use RingCentral\Psr7\BufferStream;
use Zipkin\Samplers\BinarySampler;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpClient\CurlHttpClient;
use Symfony\Component\HttpClient\NativeHttpClient;
use ZipkinBundle\Components\HttpClient\HttpClient;
use Psr\Http\Message\RequestInterface;
use PHPUnit\Framework\TestCase;
use HttpTest\HttpTestServer;

final class HttpClientTest extends TestCase
{
Expand Down Expand Up @@ -56,8 +57,11 @@ function (RequestInterface $request, ResponseInterface &$response) use ($t) {
$spans = $inMemory->flush();
$this->assertCount(1, $spans);

$span = $spans[0]->toArray();
$this->assertEquals('http/get', $span['name']);
/**
* @var ReadbackSpan $span
*/
$span = $spans[0];
$this->assertEquals('http/get', $span->getName());
} finally {
$server->stop();
}
Expand Down Expand Up @@ -86,9 +90,12 @@ function (RequestInterface $request, ResponseInterface &$response) use ($t) {
$tracing->getTracer()->flush();
$spans = $inMemory->flush();
$this->assertCount(1, $spans);
$span = $spans[0]->toArray();
$this->assertEquals('http/get', $span['name']);
$this->assertEquals('Response has been canceled.', $span['tags']['error']);
/**
* @var ReadbackSpan $span
*/
$span = $spans[0];
$this->assertEquals('http/get', $span->getName());
$this->assertEquals('Response has been canceled.', $span->getTags()['error']);
} finally {
$server->stop();
}
Expand Down Expand Up @@ -127,8 +134,11 @@ function (RequestInterface $request, ResponseInterface &$response) use ($t) {
$tracing->getTracer()->flush();
$spans = $inMemory->flush();
$this->assertCount(1, $spans);
/**
* @var ReadbackSpan $span
*/
$span = $spans[0]->toArray();
$this->assertEquals('http/get', $span['name']);
$this->assertEquals('http/get', $span->getName());
} finally {
$server->stop();
}
Expand Down
20 changes: 14 additions & 6 deletions tests/Unit/Components/HttpClient/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Zipkin\Samplers\BinarySampler;
use Zipkin\Sampler;
use Zipkin\Reporters\InMemory;
use Zipkin\Recording\ReadbackSpan;
use Zipkin\Instrumentation\Http\Client\HttpClientTracing;
use ZipkinBundle\Components\HttpClient\HttpClient;
use Symfony\Component\HttpClient\TraceableHttpClient;
Expand All @@ -16,7 +17,7 @@

final class HttpClientTest extends TestCase
{
public static function createTracing(Sampler $sampler = null): array
private static function createTracing(Sampler $sampler = null): array
{
$inMemory = new InMemory();
$tracing = TracingBuilder::create()
Expand Down Expand Up @@ -91,8 +92,11 @@ public function testHttpCallSuccess()
$response = $tracedClient->request('GET', 'http://test.com');
$spans = $flusher();
$this->assertCount(1, $spans);
$span = $spans[0]->toArray();
$this->assertEquals('GET', $span['name']);
/**
* @var ReadbackSpan $span
*/
$span = $spans[0];
$this->assertEquals('GET', $span->getName());
$this->assertEquals(200, $response->getStatusCode());
}

Expand All @@ -111,8 +115,12 @@ public function testHttpCallFails()

$spans = $flusher();
$this->assertCount(1, $spans);
$span = $spans[0]->toArray();
$this->assertEquals('GET', $span['name']);
$this->assertEquals('403', $span['tags']['error']);

/**
* @var ReadbackSpan $span
*/
$span = $spans[0];
$this->assertEquals('GET', $span->getName());
$this->assertEquals('403', $span->getTags()['http.status_code']);
}
}
1 change: 0 additions & 1 deletion tests/Unit/Components/HttpClient/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use ZipkinTests\Unit\Instrumentation\Http\Client\BaseResponseTest;
use ZipkinBundle\Components\HttpClient\Response;
use ZipkinBundle\Components\HttpClient\Request;
use Symfony\Component\HttpFoundation\Request as HttpFoundationRequest;

final class ResponseTest extends BaseResponseTest
{
Expand Down
39 changes: 25 additions & 14 deletions tests/Unit/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Zipkin\TracingBuilder;
use Zipkin\Samplers\BinarySampler;
use Zipkin\Reporters\InMemory as InMemoryReporter;
use Zipkin\Recording\ReadbackSpan;
use ZipkinBundle\Middleware;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
Expand All @@ -18,13 +19,16 @@
use PHPUnit\Framework\TestCase;
use Exception;

/**
* @deprecated
*/
final class MiddlewareTest extends TestCase
{
const HTTP_METHOD = 'OPTIONS';
const HTTP_PATH = '/foo';
const TAG_KEY = 'key';
const TAG_VALUE = 'value';
const EXCEPTION_MESSAGE = 'message';
private const HTTP_METHOD = 'OPTIONS';
private const HTTP_PATH = '/foo';
private const TAG_KEY = 'key';
private const TAG_VALUE = 'value';
private const EXCEPTION_MESSAGE = 'message';

public function testSpanIsNotCreatedOnNonMasterRequest()
{
Expand Down Expand Up @@ -66,13 +70,10 @@ public function testSpanIsCreatedOnKernelRequest()
$tracing->getTracer()->flush();
$spans = $reporter->flush();
$this->assertCount(1, $spans);
$this->assertArraySubset([
'tags' => [
'http.method' => self::HTTP_METHOD,
'http.path' => self::HTTP_PATH,
self::TAG_KEY => self::TAG_VALUE,
]
], $spans[0]->toArray());
$tags = $spans[0]->getTags();
$this->assertEquals(self::HTTP_METHOD, $tags['http.method']);
$this->assertEquals(self::HTTP_PATH, $tags['http.path']);
$this->assertEquals(self::TAG_VALUE, $tags[self::TAG_KEY]);
}

private function mockKernel()
Expand Down Expand Up @@ -227,7 +228,12 @@ public function testSpanIsTaggedOnKernelResponse($responseStatusCode)
$tracing->getTracer()->flush();
$spans = $reporter->flush();
$this->assertCount(1, $spans);
$this->assertArraySubset(['tags' => $assertTags], $spans[0]->toArray());

/**
* @var ReadbackSpan $span
*/
$span = $spans[0];
$this->assertEquals($assertTags, $span->getTags());
}

public function testSpanScopeIsClosedOnResponse()
Expand Down Expand Up @@ -308,7 +314,12 @@ public function testSpanIsTaggedOnKernelTerminate($responseStatusCode)
// it already.
$spans = $reporter->flush();
$this->assertCount(1, $spans);
$this->assertArraySubset(['tags' => $assertTags], $spans[0]->toArray());

/**
* @var ReadbackSpan $span
*/
$span = $spans[0];
$this->assertEquals($assertTags, $span->getTags());
}

public function testSpanScopeIsClosedOnTerminate()
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function createResponse(
): array {
$delegateResponse = new HttpFoundationResponse($body, $statusCode, $headers);
$response = new Response($delegateResponse, $request, $route);
return [$response, $delegateResponse, $request];
return [$response, $delegateResponse, $request, $route];
}

/**
Expand Down

0 comments on commit cb2a1d4

Please sign in to comment.