Skip to content

Commit

Permalink
chore: accept null for the first parameter in the HTTP reporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs committed May 13, 2020
1 parent ad492ab commit bb41872
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Zipkin/Reporters/Http.php
Expand Up @@ -76,12 +76,15 @@ public function __construct(
// means the intention of the first argument is the `ClientFactory`
$parsedOptions = $requesterFactory ?? [];
$requesterFactory = $options;
} elseif ($options === null) {
$parsedOptions = $requesterFactory ?? [];
$requesterFactory = null;
} else {
throw new TypeError(
\sprintf(
'Argument 1 passed to %s::__construct must be of type array, %s given',
self::class,
$options === null ? 'null' : \gettype($options)
\gettype($options)
)
);
}
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Reporters/HttpTest.php
Expand Up @@ -22,10 +22,14 @@ public function testConstructorIsRetrocompatible()
$this->assertInstanceOf(Http::class, new Http());

// old constructor
$this->assertInstanceOf(Http::class, new Http(
null,
['endpoint_url' => 'http://myzipkin:9411/api/v2/spans']
));
$this->assertInstanceOf(Http::class, new Http(CurlFactory::create()));
$this->assertInstanceOf(Http::class, new Http(
CurlFactory::create(),
['endpoint_url' => 'http://myzipkin:9411/api/v2/spans',]
['endpoint_url' => 'http://myzipkin:9411/api/v2/spans']
));

// new constructor
Expand All @@ -38,11 +42,11 @@ public function testConstructorIsRetrocompatible()
));

try {
new Http(null);
new Http(1);
$this->fail('Expected the constructor to fail.');
} catch (TypeError $e) {
$this->assertEquals(
'Argument 1 passed to Zipkin\Reporters\Http::__construct must be of type array, null given',
'Argument 1 passed to Zipkin\Reporters\Http::__construct must be of type array, integer given',
$e->getMessage()
);
}
Expand Down

0 comments on commit bb41872

Please sign in to comment.