Skip to content

Commit 48708dc

Browse files
committed
fix: set redis extension as optional dependency
Signed-off-by: Emilien Escalle <[email protected]>
1 parent 513e9d8 commit 48708dc

File tree

7 files changed

+54
-32
lines changed

7 files changed

+54
-32
lines changed

.github/workflows/tests.yaml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
version:
13-
- php: '8.3'
14-
symfony: '5.4'
15-
- php: '8.3'
16-
symfony: '6.4'
17-
- php: '8.3'
18-
symfony: '7.0'
19-
name: PHP ${{ matrix.version.php }} Symfony ${{ matrix.version.symfony }}
12+
php: ["8.3"]
13+
symfony: ["5.4", "6.4", "7.0"]
14+
enable-redis: [true, false]
15+
name: PHP ${{ matrix.php }} Symfony ${{ matrix.symfony }} Redis ${{ matrix.enable-redis && 'enabled' || 'disabled' }}
2016
steps:
2117
- uses: actions/checkout@v4
2218
- uses: shivammathur/setup-php@v2
2319
with:
24-
php-version: ${{ matrix.version.php }}
20+
php-version: ${{ matrix.php }}
2521
tools: phpunit-bridge, flex
26-
extensions: pdo_sqlite, redis
22+
extensions: "pdo_sqlite ${{ matrix.enable-redis && ', redis' || '' }}"
2723
coverage: none
2824
- run: |
29-
composer config extra.symfony.require ${{ matrix.version.symfony }}
25+
composer config extra.symfony.require ${{ matrix.symfony }}
3026
composer update
3127
- run: vendor/bin/php-cs-fixer fix --dry-run --diff
32-
- run: vendor/bin/phpunit --exclude-group not-${{ matrix.version.symfony }}
28+
- run: vendor/bin/phpunit --exclude-group not-${{ matrix.symfony }} ${{ !matrix.enable-redis && '--exclude-group redis' || '' }}
3329
env:
34-
SYMFONY_DEPRECATIONS_HELPER: 'disabled=1'
30+
SYMFONY_DEPRECATIONS_HELPER: "disabled=1"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ doctrine:
9999
The bundle can also check that redis connections are working. You should add a list of
100100
service names to check
101101

102+
This will require the PHP Redis extension enabled.
103+
102104
```yaml
103105
ekreative_health_check:
104106
redis:

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
},
2020
"require": {
2121
"php": ">=8.0",
22-
"ext-redis": "*",
2322
"symfony/framework-bundle": "^5.0|^6.0|^7.0"
2423
},
24+
"suggest": {
25+
"ext-redis": "To use the Redis health check"
26+
},
2527
"require-dev": {
2628
"symfony/phpunit-bridge": "^5.0|^6.0|^7.0",
2729
"doctrine/doctrine-bundle": "^2",

composer.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Ekreative/HealthCheckBundle/Controller/HealthCheckControllerTest.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,40 @@ public function testAction()
1818
// This env connects to real redis and mysql servers
1919
$client = static::createClient(['environment' => 'test_travis']);
2020
} else {
21-
// This env uses a sqlite connection and fakes the redis server
21+
// This env uses a sqlite connection
2222
$client = static::createClient();
23+
}
24+
25+
$client->request('GET', '/healthcheck');
26+
27+
$this->assertEquals(200, $client->getResponse()->getStatusCode());
28+
$this->assertEquals('application/json', $client->getResponse()->headers->get('content-type'));
29+
30+
$data = json_decode($client->getResponse()->getContent(), true);
31+
32+
$this->assertIsArray($data);
33+
$this->assertCount(2, $data);
34+
35+
$this->assertIsBool($data['app']);
36+
$this->assertTrue($data['app']);
37+
38+
$this->assertIsBool($data['database']);
39+
$this->assertTrue($data['database']);
40+
}
41+
42+
#[Group('redis')]
43+
public function testActionWithRedis()
44+
{
45+
if (isset($_ENV['travis'])) {
46+
// This env connects to real redis and mysql servers
47+
$client = static::createClient(['environment' => 'test_travis']);
48+
} else {
49+
// This env uses a sqlite connection and fakes the redis server
50+
$client = static::createClient(['environment' => 'test_with_redis']);
2351

2452
$redis = $this->getMockBuilder(\Redis::class)
2553
->onlyMethods(['ping'])
26-
->getMock()
27-
;
54+
->getMock();
2855
$redis->method('ping')->willReturn(true);
2956

3057
$client->getKernel()->getContainer()->set('redis', $redis);
@@ -86,6 +113,7 @@ public function testOptionalMySQLFailAction()
86113
$this->assertFalse($data['database']);
87114
}
88115

116+
#[Group('redis')]
89117
public function testRedisFailAction()
90118
{
91119
$client = static::createClient(['environment' => 'test_with_redis']);
@@ -104,6 +132,7 @@ public function testRedisFailAction()
104132
$this->assertFalse($data['redis']);
105133
}
106134

135+
#[Group('redis')]
107136
public function testOptionalRedisFailAction()
108137
{
109138
$client = static::createClient(['environment' => 'test_with_redis_optional']);
@@ -134,16 +163,15 @@ public static function getLazyRedis()
134163
throw new \Exception('Should not be called');
135164
}
136165

137-
#[Group('not-5.4')]
166+
#[Group('not-5.4', 'redis')]
138167
public function testAnnoRoutes()
139168
{
140169
// This env uses a sqlite connection and fakes the redis server
141170
$client = static::createClient(['environment' => 'test_anno']);
142171

143172
$redis = $this->getMockBuilder(\Redis::class)
144173
->onlyMethods(['ping'])
145-
->getMock()
146-
;
174+
->getMock();
147175
$redis->method('ping')->willReturn(true);
148176

149177
$client->getKernel()->getContainer()->set('redis', $redis);

tests/config_test.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,3 @@ doctrine:
2020
default:
2121
driver: pdo_sqlite
2222
path: '%kernel.cache_dir%/db.sqlite'
23-
24-
ekreative_health_check:
25-
redis:
26-
- 'redis'
27-
28-
services:
29-
redis:
30-
class: Redis
31-
public: true

tests/config_test_with_redis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ framework:
55
strict_requirements: ~
66
utf8: true
77
secret: 'fake_secret'
8+
http_method_override: true
9+
php_errors:
10+
log: true
811

912
monolog:
1013
handlers:
@@ -25,6 +28,7 @@ ekreative_health_check:
2528
services:
2629
redis:
2730
class: Redis
31+
public: true
2832
factory: Ekreative\HealthCheckBundle\DependencyInjection\RedisFactory::get
2933
arguments:
3034
$host: 'example.com'

0 commit comments

Comments
 (0)