1212namespace Continuous \Tests \Sdk ;
1313
1414use Continuous \Sdk \Service ;
15+ use phpmock \phpunit \PHPMock ;
1516
1617/**
1718 * ServiceTest
2223 */
2324class ServiceTest extends \PHPUnit_Framework_TestCase
2425{
26+ use PHPMock;
27+
2528 protected $ httpClientMock ;
2629 protected $ originalHttpClientClass ;
2730 protected $ descriptionMock ;
@@ -70,6 +73,23 @@ public function testGetHttpClientSetCorrectlyAccessToken()
7073 $ this ->assertEquals ("Bearer " . $ token , $ client ->getDefaultOption ('headers ' )['Authorization ' ]);
7174 }
7275
76+ public function testGetHttpClientSetCorrectlyAccessTokenIfSetAsEnvVar ()
77+ {
78+ $ token = 'my-awesome-token ' ;
79+ $ getenv = $ this ->getFunctionMock ('Continuous\Sdk ' , 'getenv ' );
80+ $ getenv ->expects ($ this ->once ())
81+ ->with ('CPHP_TOKEN ' )
82+ ->willReturn ($ token );
83+
84+ Service::setHttpClientClass ('GuzzleHttp\Client ' );
85+
86+ $ client = Service::getHttpClient ();
87+ $ this ->assertInstanceOf ('GuzzleHttp\Client ' , $ client );
88+
89+ $ this ->assertArrayHasKey ('Authorization ' , $ client ->getDefaultOption ('headers ' ));
90+ $ this ->assertEquals ("Bearer " . $ token , $ client ->getDefaultOption ('headers ' )['Authorization ' ]);
91+ }
92+
7393 public function testGetHttpClientHasNoTokenIfNotProvided ()
7494 {
7595 Service::setHttpClientClass ('GuzzleHttp\Client ' );
@@ -100,5 +120,4 @@ public function testGetDescriptionUsesTheRightClassname()
100120 {
101121 $ this ->assertInstanceOf (Service::getDescriptionClass (), Service::getDescription ());
102122 }
103-
104- }
123+ }
0 commit comments