Skip to content

Commit 1d39b77

Browse files
authored
Merge pull request #4 from php-http/patch-3
Using constants instead of environments variables
2 parents 5f4466f + b392e20 commit 1d39b77

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</filter>
3737

3838
<php>
39-
<env name="URI_FACTORY" value=""/>
40-
<env name="STREAM_FACTORY" value=""/>
39+
<const name="URI_FACTORY" value=""/>
40+
<const name="STREAM_FACTORY" value=""/>
4141
</php>
4242
</phpunit>

src/BaseTest.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ protected function assertNotSameObject($a, $b)
2020

2121
protected function buildUri($uri)
2222
{
23-
$factory = getenv('URI_FACTORY');
24-
25-
if (!empty($factory)) {
26-
$factoryClass = new $factory();
27-
if (!$factoryClass instanceof \Http\Message\UriFactory) {
28-
throw new \RuntimeException('Environment variable "URI_FACTORY" must be a reference to a Http\Message\UriFactory');
23+
if (!defined('URI_FACTORY')) {
24+
$factoryClass = URI_FACTORY;
25+
$factory = new $factoryClass();
26+
if (!$factory instanceof \Http\Message\UriFactory) {
27+
throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a Http\Message\UriFactory');
2928
}
3029

31-
return $factoryClass->createUri($uri);
30+
return $factory->createUri($uri);
3231
}
3332

3433
if (class_exists(GuzzleUri::class)) {
@@ -48,15 +47,14 @@ protected function buildUri($uri)
4847

4948
protected function buildStream($data)
5049
{
51-
$factory = getenv('STREAM_FACTORY');
52-
53-
if (!empty($factory)) {
54-
$factoryClass = new $factory();
55-
if (!$factoryClass instanceof \Http\Message\StreamFactory) {
56-
throw new \RuntimeException('Environment variable "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory');
50+
if (!defined('STREAM_FACTORY')) {
51+
$factoryClass = STREAM_FACTORY;
52+
$factory = new $factoryClass();
53+
if (!$factory instanceof \Http\Message\StreamFactory) {
54+
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory');
5755
}
5856

59-
return $factoryClass->createStream($data);
57+
return $factory->createStream($data);
6058
}
6159

6260
if (class_exists(GuzzleStream::class)) {

0 commit comments

Comments
 (0)