Skip to content

Commit 5ff97ed

Browse files
authored
fix: stderr in phpunit output tests (#10)
1 parent 31ec06f commit 5ff97ed

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

phpmd-ruleset.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
</properties>
4242
</rule>
4343
<rule ref="rulesets/controversial.xml">
44-
<exclude name="CamelCasePropertyName"/>
45-
<exclude name="CamelCaseMethodName"/>
44+
<exclude name="Superglobals"/>
4645
</rule>
4746
<rule ref="rulesets/design.xml">
4847
<exclude name="CouplingBetweenObjects"/>

phpunit.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
failOnRisky="true"
1414
failOnWarning="true"
1515
>
16+
<php>
17+
<server name="LOG_STREAM" value="/tmp/cdn-php.log" force="true" />
18+
</php>
19+
1620
<testsuites>
1721
<testsuite name="default">
1822
<directory>tests</directory>

public/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Component\HttpFoundation\Response;
2121

2222
$dotenv = new Dotenv();
23-
$dotenv->usePutenv();
2423
$dotenv->loadEnv(__DIR__ . '/../.env');
2524

2625
if (true === filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOLEAN)) {

src/ContainerConfig.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct()
3535
{
3636
parent::__construct();
3737

38-
$this['storage_driver'] = getenv('STORAGE_DRIVER');
39-
$this['storage_path'] = getenv('STORAGE_PATH');
40-
$this['cache_ttl'] = (int) getenv('CACHE_TTL');
41-
$this['allowed_domains'] = explode(',', (string) getenv('ALLOWED_DOMAINS'));
42-
$this['image_compression'] = (int) getenv('IMAGE_COMPRESSION');
43-
44-
$this[LoggerInterface::class] = static fn () => new BrefLogger(
45-
(string) getenv('LOG_LEVEL'),
46-
(string) getenv('LOG_STREAM')
38+
$this['storage_driver'] = $this->getEnv('STORAGE_DRIVER');
39+
$this['storage_path'] = $this->getEnv('STORAGE_PATH');
40+
$this['cache_ttl'] = (int) $this->getEnv('CACHE_TTL');
41+
$this['allowed_domains'] = explode(',', $this->getEnv('ALLOWED_DOMAINS'));
42+
$this['image_compression'] = (int) $this->getEnv('IMAGE_COMPRESSION');
43+
44+
$this[LoggerInterface::class] = fn () => new BrefLogger(
45+
$this->getEnv('LOG_LEVEL'),
46+
$this->getEnv('LOG_STREAM')
4747
);
4848

4949
$this[SymfonyFilesystem::class] = static fn() => new SymfonyFilesystem();
@@ -52,20 +52,20 @@ public function __construct()
5252
case 's3':
5353
$awsClient = new S3Client(
5454
[
55-
'version' => 'latest',
56-
'region' => getenv('S3_REGION'),
57-
'endpoint' => getenv('S3_ENDPOINT'),
58-
'use_path_style_endpoint' => 1 === ((int) getenv('S3_PATH_STYLE_ENDPOINT')),
55+
'version' => $this->getEnv('S3_VERSION', 'latest'),
56+
'region' => $this->getEnv('S3_REGION'),
57+
'endpoint' => $this->getEnv('S3_ENDPOINT'),
58+
'use_path_style_endpoint' => 1 === ((int) $this->getEnv('S3_PATH_STYLE_ENDPOINT', 1)),
5959
'credentials' => [
60-
'key' => getenv('S3_ACCESS_KEY'),
61-
'secret' => getenv('S3_SECRET_KEY'),
60+
'key' => $this->getEnv('S3_ACCESS_KEY'),
61+
'secret' => $this->getEnv('S3_SECRET_KEY'),
6262
],
6363
]
6464
);
6565

6666
$this[FilesystemAdapter::class] = new AwsS3V3Adapter(
6767
client: $awsClient,
68-
bucket: (string) getenv('S3_BUCKET'),
68+
bucket: $this->getEnv('S3_BUCKET'),
6969
visibility: new PortableVisibilityConverter(Visibility::PRIVATE),
7070
);
7171
break;
@@ -79,7 +79,7 @@ public function __construct()
7979
}
8080

8181
$this[UrlFilesystemAdapter::class] = static fn(self $c) => new UrlFilesystemAdapter(
82-
$c[SymfonyFilesystem::class]
82+
$c[SymfonyFilesystem::class],
8383
);
8484
$this[LeagueFilesystem::class] = static fn(self $c) => new LeagueFilesystem($c[FilesystemAdapter::class]);
8585
$this[Storage::class] = static fn (self $c) => new Storage(
@@ -105,4 +105,15 @@ public function __construct()
105105
$c[LoggerInterface::class],
106106
);
107107
}
108+
109+
private function getEnv(string $key, mixed $default = null): string
110+
{
111+
// phpcs:ignore
112+
if (false === \array_key_exists($key, $_ENV)) {
113+
return $default;
114+
}
115+
116+
// phpcs:ignore
117+
return (string) $_ENV[$key];
118+
}
108119
}

tests/bootstrap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
require __DIR__ . '/../vendor/autoload.php';
1717

1818
$dotenv = new Dotenv();
19-
$dotenv->usePutenv();
2019
$dotenv->load(__DIR__ . '/../.env');

0 commit comments

Comments
 (0)