From 9c9eba41dcd72bff6ba36402a54c6297c5a426bc Mon Sep 17 00:00:00 2001 From: piotrooo Date: Wed, 3 Apr 2019 21:58:17 +0200 Subject: [PATCH 1/3] Travis configuration for PHP 7.1, 7.2 and 7.3. Bumped phpunit and fixed tests. --- .travis.yml | 3 +- composer.json | 76 +++++++++---------- .../OpenTracing/Mock/MockScopeManagerTest.php | 11 ++- .../OpenTracing/Mock/MockSpanContextTest.php | 15 ++-- tests/OpenTracing/Mock/MockSpanTest.php | 34 +++------ tests/OpenTracing/Mock/MockTracerTest.php | 21 +++-- tests/OpenTracing/ReferenceTest.php | 7 +- tests/OpenTracing/StartSpanOptionsTest.php | 10 ++- 8 files changed, 94 insertions(+), 83 deletions(-) diff --git a/.travis.yml b/.travis.yml index ad23de6..fefd713 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,9 @@ language: php php: - - '5.6' - - '7.0' - '7.1' - '7.2' + - '7.3' cache: directories: diff --git a/composer.json b/composer.json index 4257b26..ad9c842 100644 --- a/composer.json +++ b/composer.json @@ -1,42 +1,42 @@ { - "name": "opentracing/opentracing", - "type": "library", - "description": "OpenTracing API for PHP", - "license": "Apache-2.0", - "authors": [ - { - "name": "José Carlos Chávez", - "email": "jcchavezs@gmail.com" - } - ], - "require": { - "php": "^5.6 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "~5.7.19", - "squizlabs/php_codesniffer": "3.*" - }, - "config": { - "sort-packages": true - }, - "autoload": { - "psr-4": { - "OpenTracing\\": "./src/OpenTracing/" - }, - "files": [ - "./src/OpenTracing/Tags.php", - "./src/OpenTracing/Formats.php" - ] - }, - "autoload-dev": { - "psr-4": { - "OpenTracing\\Tests\\": "./tests/OpenTracing" - } + "name": "opentracing/opentracing", + "type": "library", + "description": "OpenTracing API for PHP", + "license": "Apache-2.0", + "minimum-stability": "stable", + "authors": [ + { + "name": "José Carlos Chávez", + "email": "jcchavezs@gmail.com" + } + ], + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "~7.5.8", + "squizlabs/php_codesniffer": "3.*" + }, + "config": { + "sort-packages": true + }, + "autoload": { + "psr-4": { + "OpenTracing\\": "src/OpenTracing/" }, - "minimum-stability": "stable", - "scripts": { - "fix-lint": "phpcbf --standard=ZEND --standard=PSR2 --ignore=*/vendor/* ./", - "lint": "phpcs --standard=ZEND --standard=PSR2 --ignore=*/vendor/* ./", - "test": "phpunit tests" + "files": [ + "src/OpenTracing/Tags.php", + "src/OpenTracing/Formats.php" + ] + }, + "autoload-dev": { + "psr-4": { + "OpenTracing\\Tests\\": "tests/OpenTracing" } + }, + "scripts": { + "fix-lint": "phpcbf --standard=ZEND --standard=PSR2 --ignore=*/vendor/* ./", + "lint": "phpcs --standard=ZEND --standard=PSR2 --ignore=*/vendor/* ./", + "test": "phpunit tests" + } } diff --git a/tests/OpenTracing/Mock/MockScopeManagerTest.php b/tests/OpenTracing/Mock/MockScopeManagerTest.php index a119243..1e45384 100644 --- a/tests/OpenTracing/Mock/MockScopeManagerTest.php +++ b/tests/OpenTracing/Mock/MockScopeManagerTest.php @@ -4,15 +4,16 @@ use OpenTracing\Mock\MockScopeManager; use OpenTracing\Mock\MockTracer; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; -final class MockScopeManagerTest extends PHPUnit_Framework_TestCase +final class MockScopeManagerTest extends TestCase { - const OPERATION_NAME = 'test_name'; + private const OPERATION_NAME = 'test_name'; public function testGetActiveFailsWithNoActiveSpans() { $scopeManager = new MockScopeManager(); + $this->assertNull($scopeManager->getActive()); } @@ -22,6 +23,7 @@ public function testActivateSuccess() $span = $tracer->startSpan(self::OPERATION_NAME); $scopeManager = new MockScopeManager(); $scopeManager->activate($span); + $this->assertSame($span, $scopeManager->getActive()->getSpan()); } @@ -30,6 +32,7 @@ public function testGetScopeReturnsNull() $tracer = new MockTracer(); $tracer->startSpan(self::OPERATION_NAME); $scopeManager = new MockScopeManager(); + $this->assertNull($scopeManager->getActive()); } @@ -40,6 +43,7 @@ public function testGetScopeSuccess() $scopeManager = new MockScopeManager(); $scopeManager->activate($span); $scope = $scopeManager->getActive(); + $this->assertSame($span, $scope->getSpan()); } @@ -51,6 +55,7 @@ public function testDeactivateSuccess() $scopeManager->activate($span); $scope = $scopeManager->getActive(); $scopeManager->deactivate($scope); + $this->assertNull($scopeManager->getActive()); } } diff --git a/tests/OpenTracing/Mock/MockSpanContextTest.php b/tests/OpenTracing/Mock/MockSpanContextTest.php index 348b868..2368b87 100644 --- a/tests/OpenTracing/Mock/MockSpanContextTest.php +++ b/tests/OpenTracing/Mock/MockSpanContextTest.php @@ -3,20 +3,21 @@ namespace OpenTracing\Mock\Tests; use OpenTracing\Mock\MockSpanContext; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; -final class MockSpanContextTest extends PHPUnit_Framework_TestCase +final class MockSpanContextTest extends TestCase { - const TRACE_ID = 'test_trace_id'; - const SPAN_ID = 'test_span_id'; - const IS_SAMPLED = true; - const BAGGAGE_ITEM_KEY = 'test_key'; - const BAGGAGE_ITEM_VALUE = 'test_value'; + private const TRACE_ID = 'test_trace_id'; + private const SPAN_ID = 'test_span_id'; + private const IS_SAMPLED = true; + private const BAGGAGE_ITEM_KEY = 'test_key'; + private const BAGGAGE_ITEM_VALUE = 'test_value'; public function testCreateAsRootSuccess() { $parentContext = MockSpanContext::createAsRoot(); $childContext = MockSpanContext::createAsChildOf($parentContext); + $this->assertEquals($parentContext->getTraceId(), $childContext->getTraceId()); } diff --git a/tests/OpenTracing/Mock/MockSpanTest.php b/tests/OpenTracing/Mock/MockSpanTest.php index f50367f..cb2f557 100644 --- a/tests/OpenTracing/Mock/MockSpanTest.php +++ b/tests/OpenTracing/Mock/MockSpanTest.php @@ -2,30 +2,26 @@ namespace OpenTracing\Mock\Tests; -use OpenTracing\NoopScopeManager; use OpenTracing\Mock\MockSpan; use OpenTracing\Mock\MockSpanContext; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; /** * @covers MockSpan */ -final class MockSpanTest extends PHPUnit_Framework_TestCase +final class MockSpanTest extends TestCase { - const OPERATION_NAME = 'test'; - const DURATION = 10; - const TAG_KEY = 'test_key'; - const TAG_VALUE = 'test_value'; - const LOG_FIELD = 'test_log'; + private const OPERATION_NAME = 'test'; + private const DURATION = 10; + private const TAG_KEY = 'test_key'; + private const TAG_VALUE = 'test_value'; + private const LOG_FIELD = 'test_log'; public function testCreateSpanSuccess() { $startTime = time(); - $span = new MockSpan( - self::OPERATION_NAME, - MockSpanContext::createAsRoot(), - $startTime - ); + $span = new MockSpan(self::OPERATION_NAME, MockSpanContext::createAsRoot(), $startTime); + $this->assertEquals($startTime, $span->getStartTime()); $this->assertEmpty($span->getTags()); $this->assertEmpty($span->getLogs()); @@ -33,10 +29,7 @@ public function testCreateSpanSuccess() public function testAddTagsAndLogsToSpanSuccess() { - $span = new MockSpan( - self::OPERATION_NAME, - MockSpanContext::createAsRoot() - ); + $span = new MockSpan(self::OPERATION_NAME, MockSpanContext::createAsRoot()); $span->setTag(self::TAG_KEY, self::TAG_VALUE); $span->log([self::LOG_FIELD]); @@ -48,12 +41,9 @@ public function testAddTagsAndLogsToSpanSuccess() public function testSpanIsFinished() { $startTime = time(); - $span = new MockSpan( - self::OPERATION_NAME, - MockSpanContext::createAsRoot(), - $startTime - ); + $span = new MockSpan(self::OPERATION_NAME, MockSpanContext::createAsRoot(), $startTime); $span->finish($startTime + self::DURATION); + $this->assertTrue($span->isFinished()); $this->assertEquals(self::DURATION, $span->getDuration()); } diff --git a/tests/OpenTracing/Mock/MockTracerTest.php b/tests/OpenTracing/Mock/MockTracerTest.php index c401b76..54a4979 100644 --- a/tests/OpenTracing/Mock/MockTracerTest.php +++ b/tests/OpenTracing/Mock/MockTracerTest.php @@ -5,21 +5,23 @@ use OpenTracing\Exceptions\UnsupportedFormat; use OpenTracing\Mock\MockTracer; use OpenTracing\NoopSpan; -use PHPUnit_Framework_TestCase; +use OpenTracing\Span; +use PHPUnit\Framework\TestCase; /** * @covers MockTracer */ -final class MockTracerTest extends PHPUnit_Framework_TestCase +final class MockTracerTest extends TestCase { - const OPERATION_NAME = 'test_name'; - const FORMAT = 'test_format'; + private const OPERATION_NAME = 'test_name'; + private const FORMAT = 'test_format'; public function testStartActiveSpanSuccess() { $tracer = new MockTracer(); $scope = $tracer->startActiveSpan(self::OPERATION_NAME); $activeSpan = $tracer->getActiveSpan(); + $this->assertEquals($scope->getSpan(), $activeSpan); } @@ -28,6 +30,7 @@ public function testStartSpanSuccess() $tracer = new MockTracer(); $tracer->startSpan(self::OPERATION_NAME); $activeSpan = $tracer->getActiveSpan(); + $this->assertNull($activeSpan); } @@ -36,6 +39,7 @@ public function testInjectWithNoInjectorsFails() $tracer = new MockTracer(); $span = $tracer->startSpan(self::OPERATION_NAME); $carrier = []; + $this->expectException(UnsupportedFormat::class); $tracer->inject($span->getContext(), self::FORMAT, $carrier); } @@ -63,6 +67,7 @@ public function testExtractWithNoExtractorsFails() { $tracer = new MockTracer(); $carrier = []; + $this->expectException(UnsupportedFormat::class); $tracer->extract(self::FORMAT, $carrier); } @@ -73,6 +78,7 @@ public function testExtractSuccess() $actualCarrier = null; $extractor = function ($carrier) use (&$actualCarrier) { + var_dump($actualCarrier); $actualCarrier = $carrier; return NoopSpan::create(); }; @@ -82,15 +88,20 @@ public function testExtractSuccess() 'TRACE_ID' => 'trace_id' ]; - $tracer->extract(self::FORMAT, $carrier); + $spanContext = $tracer->extract(self::FORMAT, $carrier); + + $this->assertInstanceOf(Span::class, $spanContext); } public function testFlushSuccess() { $tracer = new MockTracer(); $tracer->startSpan(self::OPERATION_NAME); + $this->assertCount(1, $tracer->getSpans()); + $tracer->flush(); + $this->assertCount(0, $tracer->getSpans()); } } diff --git a/tests/OpenTracing/ReferenceTest.php b/tests/OpenTracing/ReferenceTest.php index 1421fe5..2b270b2 100644 --- a/tests/OpenTracing/ReferenceTest.php +++ b/tests/OpenTracing/ReferenceTest.php @@ -5,18 +5,19 @@ use OpenTracing\Exceptions\InvalidReferenceArgument; use OpenTracing\NoopSpanContext; use OpenTracing\Reference; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; /** * @covers Reference */ -final class ReferenceTest extends PHPUnit_Framework_TestCase +final class ReferenceTest extends TestCase { const REFERENCE_TYPE = 'ref_type'; public function testCreateAReferenceFailsOnInvalidContext() { $context = 'invalid_context'; + $this->expectException(InvalidReferenceArgument::class); $this->expectExceptionMessage( 'Reference expects \OpenTracing\Span or \OpenTracing\SpanContext as context, got string' @@ -27,6 +28,7 @@ public function testCreateAReferenceFailsOnInvalidContext() public function testCreateAReferenceFailsOnEmptyType() { $context = new NoopSpanContext(); + $this->expectException(InvalidReferenceArgument::class); $this->expectExceptionMessage('Reference type can not be an empty string'); Reference::create('', $context); @@ -36,6 +38,7 @@ public function testAReferenceCanBeCreatedAsACustomType() { $context = new NoopSpanContext(); $reference = Reference::create(self::REFERENCE_TYPE, $context); + $this->assertSame($context, $reference->getContext()); $this->assertTrue($reference->isType(self::REFERENCE_TYPE)); } diff --git a/tests/OpenTracing/StartSpanOptionsTest.php b/tests/OpenTracing/StartSpanOptionsTest.php index 4050870..7566040 100644 --- a/tests/OpenTracing/StartSpanOptionsTest.php +++ b/tests/OpenTracing/StartSpanOptionsTest.php @@ -2,16 +2,17 @@ namespace OpenTracing\Tests; +use DateTime; use OpenTracing\Exceptions\InvalidSpanOption; use OpenTracing\NoopSpanContext; -use OpenTracing\StartSpanOptions; use OpenTracing\Reference; -use PHPUnit_Framework_TestCase; +use OpenTracing\StartSpanOptions; +use PHPUnit\Framework\TestCase; /** * @covers StartSpanOptions */ -final class StartSpanOptionsTest extends PHPUnit_Framework_TestCase +final class StartSpanOptionsTest extends TestCase { const REFERENCE_TYPE = 'a_reference_type'; @@ -55,7 +56,7 @@ public function testSpanOptionsCanBeCreatedBecauseWithValidStartTime($startTime) public function validStartTime() { return [ - [new \DateTime()], + [new DateTime()], ['1499355363'], [1499355363], [1499355363.123456] @@ -103,6 +104,7 @@ public function testSpanOptionsAddsANewReference() $context2 = NoopSpanContext::create(); $spanOptions = $spanOptions->withParent($context2); + $this->assertCount(1, $spanOptions->getReferences()); $this->assertSame($context2, $spanOptions->getReferences()[0]->getContext()); } From 43a9b5dc5edb65c864dc6cd75b428d912f54d494 Mon Sep 17 00:00:00 2001 From: piotrooo Date: Wed, 3 Apr 2019 22:08:02 +0200 Subject: [PATCH 2/3] Fixed phpunit.xml. --- phpunit.xml | 6 +++--- tests/OpenTracing/Mock/MockTracerTest.php | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 16563d9..d2515b0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,16 +11,16 @@ convertWarningsToExceptions="true" forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" - printerClass="PHPUnit_TextUI_ResultPrinter" + printerClass="PHPUnit\TextUI\ResultPrinter" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false" - testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader" + testSuiteLoaderClass="PHPUnit\Runner\StandardTestSuiteLoader" timeoutForSmallTests="1" timeoutForMediumTests="10" timeoutForLargeTests="60" verbose="false"> - \ No newline at end of file + diff --git a/tests/OpenTracing/Mock/MockTracerTest.php b/tests/OpenTracing/Mock/MockTracerTest.php index 54a4979..55b5077 100644 --- a/tests/OpenTracing/Mock/MockTracerTest.php +++ b/tests/OpenTracing/Mock/MockTracerTest.php @@ -78,7 +78,6 @@ public function testExtractSuccess() $actualCarrier = null; $extractor = function ($carrier) use (&$actualCarrier) { - var_dump($actualCarrier); $actualCarrier = $carrier; return NoopSpan::create(); }; From e90cb0373c14f61fcd3df9b3877387d4b23556df Mon Sep 17 00:00:00 2001 From: piotrooo Date: Thu, 4 Apr 2019 06:03:38 +0200 Subject: [PATCH 3/3] Fixed phpunit.xml. --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index d2515b0..cfecb39 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@