Skip to content

Commit 36a8be7

Browse files
committed
improve tests coverage
1 parent 15d0f15 commit 36a8be7

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

src/CompressionEncoding.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public function isSupported(): ?string
5050

5151
$attributes = $reflector->getAttributes(EncoderAsFunction::class);
5252

53-
if (count($attributes) === 0) {
54-
return null;
55-
}
56-
5753
/** @var \OpenSoutheners\LaravelResponseCompression\EncoderAsFunction $attribute */
5854
$attribute = $attributes[0]->newInstance();
5955

tests/CompressionEncodingTest.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
<?php
22

3-
namespace OpenSoutheners\LaravelResponseCompression\Tests;
4-
5-
use OpenSoutheners\LaravelResponseCompression\CompressionEncoding;
6-
use PHPUnit\Framework\TestCase;
3+
namespace OpenSoutheners\LaravelResponseCompression
4+
{
5+
function function_exists(string $name): bool {
6+
if (getenv('FUNCTION_EXISTS_MOCK')) {
7+
return false;
8+
}
9+
10+
return \function_exists($name);
11+
}
12+
}
713

8-
class CompressionEncodingTest extends TestCase
14+
namespace OpenSoutheners\LaravelResponseCompression\Tests
915
{
10-
public function testCompressionEncodingListSupportedReturnsArray()
16+
use OpenSoutheners\LaravelResponseCompression\CompressionEncoding;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class CompressionEncodingTest extends TestCase
1120
{
12-
$supportedList = CompressionEncoding::listSupported();
21+
public function testCompressionEncodingListSupportedReturnsArray()
22+
{
23+
$supportedList = CompressionEncoding::listSupported();
24+
25+
$this->assertIsArray($supportedList);
26+
$this->assertArrayHasKey(CompressionEncoding::Deflate->value, $supportedList);
27+
$this->assertEmpty(array_diff(
28+
array_map(fn ($case) => $case->value, CompressionEncoding::cases()),
29+
array_keys($supportedList),
30+
));
31+
}
1332

14-
$this->assertIsArray($supportedList);
15-
$this->assertArrayHasKey(CompressionEncoding::Deflate->value, $supportedList);
16-
$this->assertEmpty(array_diff(
17-
array_map(fn ($case) => $case->value, CompressionEncoding::cases()),
18-
array_keys($supportedList),
19-
));
33+
public function testCompressionEncodingIsSupportedGetsNullWhenNonPresent()
34+
{
35+
putenv('FUNCTION_EXISTS_MOCK=1');
36+
37+
$supported = CompressionEncoding::Lz4->isSupported();
38+
39+
putenv('FUNCTION_EXISTS_MOCK=');
40+
41+
$this->assertNull($supported);
42+
}
2043
}
2144
}

0 commit comments

Comments
 (0)