Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate away from PHPUnit's expectedException annotations #86

Merged
merged 1 commit into from Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions tests/Jaeger/Codec/TextCodecTest.php
Expand Up @@ -2,6 +2,7 @@

namespace Jaeger\Tests\Codec;

use Exception;
use const Jaeger\BAGGAGE_HEADER_PREFIX;
use Jaeger\Codec\TextCodec;
use const Jaeger\DEBUG_ID_HEADER_KEY;
Expand Down Expand Up @@ -127,25 +128,23 @@ public function carrierDataProvider()
];
}

/**
* @expectedException \Exception
* @expectedExceptionMessage baggage without trace ctx
*/
public function testBaggageWithoutTraceContext()
{
$carrier = [BAGGAGE_HEADER_PREFIX.'test' => 'some data'];

$this->expectException(Exception::class);
$this->expectExceptionMessage('baggage without trace ctx');

$this->textCodec->extract($carrier);
}

/**
* @expectedException \Exception
* @expectedExceptionMessage Malformed tracer state string.
*/
public function testInvalidSpanContextParsingFromHeader()
{
$carrier = [TRACE_ID_HEADER => 'invalid_data'];

$this->expectException(Exception::class);
$this->expectExceptionMessage('Malformed tracer state string.');

$this->textCodec->extract($carrier);
}

Expand Down
29 changes: 13 additions & 16 deletions tests/Jaeger/ConfigTest.php
Expand Up @@ -47,12 +47,11 @@ function testCreateTracer()
$this->assertEquals($this->serviceName, $tracer->getServiceName());
}

/**
* @expectedException Exception
* @expectedExceptionMessage service_name required in the config or param.
*/
function testThrowExceptionWhenServiceNameIsNotDefined()
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('service_name required in the config or param.');

new Config([]);
}

Expand Down Expand Up @@ -81,29 +80,27 @@ public function shouldSetGlobalTracerAfterInitialize()
$this->assertInstanceOf(Tracer::class, $tracer);
}

/**
* @test
* @expectedException Exception
* @expectedExceptionMessage Unknown sampler type unsupportedSampler
*/
/** @test */
public function shouldThrowExceptionWhenCreatingNotSupportedSampler()
{
$config = new Config(['service_name' => 'test-service-name', 'sampler' => ['type' => 'unsupportedSampler']]);

$this->expectException(Exception::class);
$this->expectExceptionMessage('Unknown sampler type unsupportedSampler');

$config->initializeTracer();
}

/**
* @test
* @expectedException Exception
* @expectedExceptionMessage You cannot use RateLimitingSampler without cache component
*/
/** @test */
public function shouldThrowExceptionWhenCreatingRateLimitingSamplerWithoutCacheComponent()
{
$config = new Config([
'service_name' => 'test-service-name',
'sampler' => ['type' => \Jaeger\SAMPLER_TYPE_RATE_LIMITING]]
);
'sampler' => ['type' => \Jaeger\SAMPLER_TYPE_RATE_LIMITING]
]);

$this->expectException(Exception::class);
$this->expectExceptionMessage('You cannot use RateLimitingSampler without cache component');

$config->initializeTracer();
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Jaeger/Sampler/ProbablisticSamplerTest.php
Expand Up @@ -3,6 +3,7 @@
namespace Jaeger\Tests\Sampler;

use Jaeger\Sampler\ProbabilisticSampler;
use OutOfBoundsException;
use PHPUnit\Framework\TestCase;
use const Jaeger\SAMPLER_PARAM_TAG_KEY;
use const Jaeger\SAMPLER_TYPE_PROBABILISTIC;
Expand Down Expand Up @@ -46,11 +47,12 @@ public function samplerProvider()
* @test
* @dataProvider rateProvider
* @param mixed $rate
* @expectedException \OutOfBoundsException
* @expectedExceptionMessage Sampling rate must be between 0.0 and 1.0.
*/
public function shouldThrowOutOfBoundsExceptionInCaseOfInvalidRate($rate)
{
$this->expectException(OutOfBoundsException::class);
$this->expectExceptionMessage('Sampling rate must be between 0.0 and 1.0.');

new ProbabilisticSampler($rate);
}

Expand Down
21 changes: 10 additions & 11 deletions tests/Jaeger/TracerTest.php
Expand Up @@ -9,6 +9,7 @@
use Jaeger\Span;
use Jaeger\SpanContext;
use Jaeger\Tracer;
use OpenTracing\Exceptions\UnsupportedFormat;
use OpenTracing\NoopSpanContext;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -151,16 +152,15 @@ public function shouldAddNoConfiguredTagsToStartedSpanWhenNotSampled()
$this->assertEquals([], $span->getTags(), 'No tags should be set when not sampled');
}

/**
* @test
* @expectedException \OpenTracing\Exceptions\UnsupportedFormat
* @expectedExceptionMessage The format 'bad-format' is not supported.
*/
/** @test */
public function shouldThrowExceptionOnInvalidFormat()
{
$spanContext = new SpanContext(0, 0, 0, 0);
$carrier = [];

$this->expectException(UnsupportedFormat::class);
$this->expectExceptionMessage("The format 'bad-format' is not supported.");

$this->tracer->inject($spanContext, 'bad-format', $carrier);
$this->assertSame([], $carrier);
}
Expand All @@ -187,14 +187,13 @@ public function shouldInjectSpanContextToCarrier()
$this->assertEquals('0:0:0:0', $carrier[TRACE_ID_HEADER]);
}

/**
* @test
* @expectedException \OpenTracing\Exceptions\UnsupportedFormat
* @expectedExceptionMessage The format 'bad-format' is not supported.
*/
/** @test */
public function shouldThrowExceptionOnExtractInvalidFormat()
{
$this->assertNull($this->tracer->extract('bad-format', []));
$this->expectException(UnsupportedFormat::class);
$this->expectExceptionMessage("The format 'bad-format' is not supported.");

$this->tracer->extract('bad-format', []);
}

/** @test */
Expand Down