1717use PHPUnit \Framework \Attributes \CoversClass ;
1818use PHPUnit \Framework \TestCase ;
1919use Psr \Http \Message \RequestInterface ;
20- use Zalas \PHPUnit \Globals \Attribute \Env ;
20+ use Zalas \PHPUnit \Globals \Attribute \Server ;
2121
2222function file_get_contents (string $ filename )
2323{
24- if (($ _ENV ['FAIL_IO ' ] ?? 'false ' ) === 'true ' ) {
24+ if (($ _SERVER ['FAIL_IO ' ] ?? 'false ' ) === 'true ' ) {
2525 return false ;
2626 }
2727 if (str_starts_with ($ filename , '/sys/devices/virtual/dmi/id ' )) {
2828 return match (substr ($ filename , 28 )) {
29- 'sys_vendor ' => (($ _ENV ['WRONG_VENDOR ' ] ?? 'false ' ) === 'true ' ) ? 'AWS ' : 'DigitalOcean ' ,
29+ 'sys_vendor ' => (($ _SERVER ['WRONG_VENDOR ' ] ?? 'false ' ) === 'true ' ) ? 'AWS ' : 'DigitalOcean ' ,
3030 'product_family ' => 'DigitalOcean_Droplet ' ,
3131 'board_asset_tag ' => '10000000 ' ,
3232 default => 'unknown '
@@ -56,8 +56,8 @@ public function setUp(): void
5656 $ client = $ this ->createStub (Psr18Client::class);
5757 $ client ->method ('sendRequest ' )->willReturnCallback (function (RequestInterface $ request ) use ($ responseFactory ) {
5858 if ((string ) $ request ->getUri () === 'http://169.254.169.254/metadata/v1.json ' ) {
59- if (($ _ENV ['FAIL_METADATA ' ] ?? 'false ' ) === 'true ' ) {
60- throw new Exception ( );
59+ if (($ _SERVER ['FAIL_METADATA ' ] ?? 'false ' ) === 'true ' ) {
60+ return $ responseFactory -> createResponse ( 500 );
6161 }
6262
6363 /** @psalm-suppress PossiblyFalseArgument */
@@ -107,7 +107,7 @@ public function test_droplet_attributes_with_no_authz()
107107 );
108108 }
109109
110- #[Env ('DIGITALOCEAN_ACCESS_TOKEN ' , 'scoped-for-account ' )]
110+ #[Server ('DIGITALOCEAN_ACCESS_TOKEN ' , 'scoped-for-account ' )]
111111 public function test_droplet_attributes_with_account_only_authz ()
112112 {
113113 $ this ->assertEquals (
@@ -126,12 +126,12 @@ public function test_droplet_attributes_with_account_only_authz()
126126 );
127127 /** @psalm-suppress PossiblyFalseArgument */
128128 $ this ->assertStringContainsString (
129- 'DigitalOcean Access Token found, but unable to get Droplet info ' ,
129+ 'DigitalOcean Access Token found; setting DigitalOcean account ID in resource attributes ' ,
130130 stream_get_contents ($ this ->errorLog )
131131 );
132132 }
133133
134- #[Env ('DIGITALOCEAN_ACCESS_TOKEN ' , 'scoped-for-droplet ' )]
134+ #[Server ('DIGITALOCEAN_ACCESS_TOKEN ' , 'scoped-for-droplet ' )]
135135 public function test_droplet_attributes_with_droplet_only_authz ()
136136 {
137137 $ this ->assertEquals (
@@ -153,12 +153,12 @@ public function test_droplet_attributes_with_droplet_only_authz()
153153 );
154154 /** @psalm-suppress PossiblyFalseArgument */
155155 $ this ->assertStringContainsString (
156- 'DigitalOcean Access Token found, but unable to get account info ' ,
156+ 'DigitalOcean Access Token found; setting additional Droplet info in resource attributes ' ,
157157 stream_get_contents ($ this ->errorLog )
158158 );
159159 }
160160
161- #[Env ('FAIL_METADATA ' , 'true ' )]
161+ #[Server ('FAIL_METADATA ' , 'true ' )]
162162 public function test_no_droplet_attributes ()
163163 {
164164 $ this ->assertEquals (
@@ -172,7 +172,7 @@ public function test_no_droplet_attributes()
172172 );
173173 }
174174
175- #[Env ('WRONG_VENDOR ' , 'true ' )]
175+ #[Server ('WRONG_VENDOR ' , 'true ' )]
176176 public function test_not_digitalocean_environment ()
177177 {
178178 $ this ->assertEquals (
@@ -186,7 +186,7 @@ public function test_not_digitalocean_environment()
186186 );
187187 }
188188
189- #[Env ('FAIL_IO ' , 'true ' )]
189+ #[Server ('FAIL_IO ' , 'true ' )]
190190 public function test_not_linux ()
191191 {
192192 $ this ->assertEquals (
0 commit comments