Skip to content

Commit f9f17db

Browse files
authored
drop support for EOL php versions and update deps (#60)
1 parent b98cc50 commit f9f17db

20 files changed

+106
-194
lines changed

.circleci/config.yml

Lines changed: 14 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,24 @@ version: 2.1
33
workflows:
44
workflow:
55
jobs:
6-
- test_5_5:
7-
name: PHP 5.5
8-
- test-with-preinstalled-php:
9-
name: PHP 5.6
10-
docker-image: circleci/php:5.6
11-
use-phpredis: false
12-
- test-with-preinstalled-php:
13-
name: PHP 7.0
14-
docker-image: circleci/php:7.0
15-
- test-with-preinstalled-php:
16-
name: PHP 7.1
17-
docker-image: circleci/php:7.1
18-
- test-with-preinstalled-php:
19-
name: PHP 7.2
20-
docker-image: circleci/php:7.2
21-
include-lowest-compatible-versions-test: false
22-
# lowest "compatible" version of phpunit in 7.2 has a bug - https://github.com/sebastianbergmann/comparator/pull/30
236
- test-with-preinstalled-php:
247
name: PHP 7.3
25-
docker-image: circleci/php:7.3
26-
include-lowest-compatible-versions-test: false
8+
docker-image: cimg/php:7.3
279
- test-with-preinstalled-php:
2810
name: PHP 7.4
29-
docker-image: circleci/php:7.4
30-
include-lowest-compatible-versions-test: false
11+
docker-image: cimg/php:7.4
12+
# we currently dont support php 8.0.x due to a bug in php 8 with guzzle,
13+
# this bug is reolved in 8.1-alpha and later
14+
#- test-with-preinstalled-php:
15+
# name: PHP 8.0
16+
# docker-image: cimg/php:8.1
3117
- integration-test
3218

3319
jobs:
3420
test-with-preinstalled-php:
3521
parameters:
3622
docker-image:
3723
type: string
38-
use-phpredis:
39-
type: boolean
40-
default: true
41-
include-lowest-compatible-versions-test:
42-
type: boolean
43-
default: true
4424

4525
docker:
4626
- image: <<parameters.docker-image>>
@@ -56,91 +36,20 @@ jobs:
5636
- run:
5737
name: install dependencies
5838
command: composer install --no-progress
59-
- when:
60-
condition: <<parameters.use-phpredis>>
61-
steps:
62-
- run:
63-
name: setup phpredis
64-
command: |
65-
pecl config-set php_ini /usr/local/etc/php/php.ini
66-
yes '' | sudo pecl install -f redis || true;
67-
echo "extension=redis.so" | sudo tee -a /usr/local/etc/php/conf.d/redis.ini;
39+
- run: mkdir -p ~/phpunit
6840
- run:
6941
name: run tests with highest compatible dependency versions
70-
command: vendor/bin/phpunit --log-junit ~/phpunit/junit.xml --coverage-text tests
71-
- store_test_results:
72-
path: ~/phpunit
73-
- store_artifacts:
74-
path: ~/phpunit
75-
- when:
76-
condition: <<parameters.include-lowest-compatible-versions-test>>
77-
steps:
78-
- run:
79-
name: run tests with lowest compatible dependency versions
80-
command: composer update --prefer-lowest --no-progress && vendor/bin/phpunit tests
81-
82-
test_5_5: # CircleCI doesn't provide a Docker image for 5.5
83-
machine:
84-
image: circleci/classic:latest # Ubuntu 14.04
85-
steps:
86-
- run:
87-
name: install PHP and Composer
88-
command: |
89-
sudo apt-get update &&
90-
sudo apt-get install circleci-php-5.5.36 &&
91-
php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" &&
92-
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --version 1.10.16 --filename=composer
93-
# Composer 2.0 doesn't work with the older versions of php-cs-fixer that support PHP 5.5
94-
- run:
95-
name: install Docker
96-
command: |
97-
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" &&
98-
sudo apt-get -q update &&
99-
sudo apt-cache policy docker-ce &&
100-
sudo apt-get -qy install docker-ce
101-
- run: sudo apt-get -qy install redis-server curl
102-
- checkout
103-
- run:
104-
name: validate composer.json
105-
command: composer validate
106-
- run:
107-
name: install current dependencies
108-
command: composer install --no-progress
109-
- run:
110-
name: run php-cs-fixer
111-
command: vendor/bin/php-cs-fixer fix --diff --dry-run --verbose
112-
- run:
113-
name: start DynamoDB
114-
command: docker run -p 8000:8000 amazon/dynamodb-local
115-
background: true
116-
- run:
117-
name: download Consul
118-
command: wget https://releases.hashicorp.com/consul/0.8.0/consul_0.8.0_linux_amd64.zip
119-
- run:
120-
name: extract Consul
121-
command: unzip consul_0.8.0_linux_amd64.zip
122-
- run:
123-
name: start Consul
124-
command: ./consul agent -dev
125-
background: true
126-
- run:
127-
name: wait on Consul
128-
command: |
129-
until $(curl --output /dev/null --silent --fail --request PUT --data 'test' http://localhost:8500/v1/kv/initchecker); do
130-
echo 'still waiting on Consul...'; sleep 2;
131-
done
132-
timeout: 50
133-
- run:
134-
name: run tests
135-
command: vendor/bin/phpunit --log-junit ~/phpunit/junit.xml --coverage-text tests
42+
command: php -d xdebug.mode=coverage vendor/bin/phpunit
43+
enviroment:
44+
XDEBUG_MODE: coverage
13645
- store_test_results:
13746
path: ~/phpunit
13847
- store_artifacts:
13948
path: ~/phpunit
14049

14150
integration-test:
14251
docker:
143-
- image: circleci/php:5.6.34-cli-jessie
52+
- image: circleci/php:7.3-cli-stretch
14453
- image: redis
14554
steps:
14655
- checkout
@@ -152,7 +61,8 @@ jobs:
15261
echo "extension=apcu.so" | sudo tee -a /usr/local/etc/php/conf.d/apcu.ini;
15362
echo "apc.enable_cli = 1" | sudo tee -a /usr/local/etc/php/conf.d/apcu.ini
15463
- run: composer update --no-progress
155-
- run: vendor/bin/phpunit --log-junit ~/phpunit/junit.xml integration-tests/CachedRedisFeatureRequesterTest.php
64+
- run: mkdir -p ~/phpunit
65+
- run: vendor/bin/phpunit integration-tests/CachedRedisFeatureRequesterTest.php
15666
- store_test_results:
15767
path: ~/phpunit
15868
- store_artifacts:

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=5.5",
17+
"php": ">=7.3",
1818
"monolog/monolog": "^1.6|^2.0",
1919
"psr/log": "^1.0"
2020
},
2121
"require-dev": {
2222
"aws/aws-sdk-php": "^3.86",
2323
"friendsofphp/php-cs-fixer": ">=2.2.19 <3.0",
24-
"guzzlehttp/guzzle": "^6.2.1",
25-
"kevinrob/guzzle-cache-middleware": "^1.4.1",
26-
"phpunit/phpunit": ">=4.8.26 <5.4",
24+
"guzzlehttp/guzzle": "^7",
25+
"kevinrob/guzzle-cache-middleware": "^3",
26+
"phpunit/phpunit": "^9",
2727
"predis/predis": "^1.0",
28-
"sensiolabs/consul-php-sdk": ">=2.1 <3.0",
29-
"zendframework/zend-serializer": "^2.7"
28+
"sensiolabs/consul-php-sdk": "^4",
29+
"phpunit/php-code-coverage": "^9"
3030
},
3131
"suggest": {
32-
"guzzlehttp/guzzle": "(^6.2.1) Required when using GuzzleEventPublisher or the default FeatureRequester",
33-
"kevinrob/guzzle-cache-middleware": "(^1.4.1) Recommended for performance when using the default FeatureRequester",
32+
"guzzlehttp/guzzle": "(^7) Required when using GuzzleEventPublisher or the default FeatureRequester",
33+
"kevinrob/guzzle-cache-middleware": "(^3) Recommended for performance when using the default FeatureRequester",
3434
"predis/predis": "(^1.0) Required when using LDDFeatureRequester",
3535
"aws/aws-sdk-php": "(^3.86) Required when using DynamoDbFeatureRequester",
3636
"sensiolabs/consul-php-sdk": "(>=2.1 <3.0) Required when using ConsulFeatureRequester"

integration-tests/CachedRedisFeatureRequesterTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
use LaunchDarkly\ApcLDDFeatureRequester;
1010
use Predis\Client;
1111
use LaunchDarkly\ApcuLDDFeatureRequester;
12+
use PHPUnit\Framework\TestCase;
1213

1314
/**
1415
* These tests use the LaunchDarkly Redis integration along with the optional caching behavior.
1516
* They are meant to be run in a PHP environment that has APCu installed. They will also test the
1617
* deprecated APC caching mode.
1718
*/
18-
class CachedRedisFeatureRequesterTest extends \PHPUnit_Framework_TestCase
19+
class CachedRedisFeatureRequesterTest extends \PHPUnit\Framework\TestCase
1920
{
2021
const CACHE_SECONDS = 60;
2122

@@ -122,7 +123,7 @@ public function testGetAllUncached()
122123

123124
$allFlags = $client->allFlags($user);
124125

125-
$this->assertInternalType('array', $allFlags);
126+
$this->assertIsArray($allFlags);
126127
$this->assertArrayHasKey($featureKey, $allFlags);
127128
$this->assertEquals($featureValue, $allFlags[$featureKey]);
128129
}
@@ -173,7 +174,7 @@ private function doCachedGetAllTest($options, $clearFn)
173174
$clearFn('launchdarkly:features:$all');
174175

175176
$allFlags = $client->allFlags($user);
176-
$this->assertInternalType('array', $allFlags);
177+
$this->assertIsArray($allFlags);
177178
$this->assertArrayHasKey($featureKey, $allFlags);
178179
$this->assertEquals($firstValue, $allFlags[$featureKey]);
179180

phpunit.xml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
<phpunit
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
beStrictAboutChangesToGlobalState="true"
7-
beStrictAboutOutputDuringTests="true"
8-
beStrictAboutResourceUsageDuringSmallTests="true"
9-
beStrictAboutTestsThatDoNotTestAnything="true"
10-
beStrictAboutTodoAnnotatedTests="true"
11-
verbose="true"
12-
>
13-
<testsuites>
14-
<testsuite name="Unit Tests">
15-
<directory>tests</directory>
16-
</testsuite>
17-
</testsuites>
18-
<filter>
19-
<whitelist>
20-
<directory suffix=".php">src</directory>
21-
</whitelist>
22-
</filter>
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" beStrictAboutResourceUsageDuringSmallTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" verbose="true">
3+
4+
<logging>
5+
<junit outputFile="~/phpunit/junit.xml"/>
6+
</logging>
7+
8+
<coverage>
9+
<include>
10+
<directory suffix=".php">src</directory>
11+
</include>
12+
<report>
13+
<html outputDirectory="~/phpunit/html-coverage"/>
14+
<xml outputDirectory="~/phpunit/xml-coverage"/>
15+
</report>
16+
</coverage>
17+
18+
<testsuites>
19+
<testsuite name="Unit Tests">
20+
<directory>tests</directory>
21+
</testsuite>
22+
</testsuites>
2323
</phpunit>

src/LaunchDarkly/Impl/Integrations/GuzzleFeatureRequester.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,41 @@ class GuzzleFeatureRequester implements FeatureRequester
2020
const SDK_SEGMENTS = "/sdk/segments";
2121
/** @var Client */
2222
private $_client;
23-
/** @var string */
24-
private $_baseUri;
25-
/** @var array */
26-
private $_defaults;
2723
/** @var LoggerInterface */
2824
private $_logger;
2925
/** @var boolean */
3026
private $_loggedCacheNotice = false;
3127

3228
public function __construct($baseUri, $sdkKey, $options)
3329
{
34-
$this->_baseUri = $baseUri;
3530
$this->_logger = $options['logger'];
3631
$stack = HandlerStack::create();
37-
if (class_exists('Kevinrob\GuzzleCache\CacheMiddleware')) {
38-
$stack->push(new CacheMiddleware(new PublicCacheStrategy(isset($options['cache']) ? $options['cache'] : null)), 'cache');
32+
if (class_exists('\Kevinrob\GuzzleCache\CacheMiddleware')) {
33+
$stack->push(
34+
new CacheMiddleware(
35+
new PublicCacheStrategy($options['cache'] ?? null)
36+
),
37+
'cache'
38+
);
3939
} elseif (!$this->_loggedCacheNotice) {
4040
$this->_logger->info("GuzzleFeatureRequester is not using an HTTP cache because Kevinrob\GuzzleCache\CacheMiddleware was not installed");
4141
$this->_loggedCacheNotice = true;
4242
}
4343

44-
$this->_defaults = array(
45-
'headers' => array(
44+
$defaults = [
45+
'headers' => [
4646
'Authorization' => $sdkKey,
4747
'Content-Type' => 'application/json',
4848
'User-Agent' => 'PHPClient/' . LDClient::VERSION
49-
),
49+
],
5050
'timeout' => $options['timeout'],
51-
'connect_timeout' => $options['connect_timeout']
52-
);
53-
$this->_client = new Client(['handler' => $stack, 'debug' => false]);
51+
'connect_timeout' => $options['connect_timeout'],
52+
'handler' => $stack,
53+
'debug' => $options['debug'] ?? false,
54+
'base_uri' => $baseUri
55+
];
56+
57+
$this->_client = new Client($defaults);
5458
}
5559

5660
/**
@@ -62,8 +66,7 @@ public function __construct($baseUri, $sdkKey, $options)
6266
public function getFeature($key)
6367
{
6468
try {
65-
$uri = $this->_baseUri . self::SDK_FLAGS . "/" . $key;
66-
$response = $this->_client->get($uri, $this->_defaults);
69+
$response = $this->_client->get(self::SDK_FLAGS . "/" . $key);
6770
$body = $response->getBody();
6871
return FeatureFlag::decode(json_decode($body, true));
6972
} catch (BadResponseException $e) {
@@ -86,8 +89,7 @@ public function getFeature($key)
8689
public function getSegment($key)
8790
{
8891
try {
89-
$uri = $this->_baseUri . self::SDK_SEGMENTS . "/" . $key;
90-
$response = $this->_client->get($uri, $this->_defaults);
92+
$response = $this->_client->get(self::SDK_SEGMENTS . "/" . $key);
9193
$body = $response->getBody();
9294
return Segment::decode(json_decode($body, true));
9395
} catch (BadResponseException $e) {
@@ -109,8 +111,7 @@ public function getSegment($key)
109111
public function getAllFeatures()
110112
{
111113
try {
112-
$uri = $this->_baseUri . self::SDK_FLAGS;
113-
$response = $this->_client->get($uri, $this->_defaults);
114+
$response = $this->_client->get(self::SDK_FLAGS);
114115
$body = $response->getBody();
115116
return array_map(FeatureFlag::getDecoder(), json_decode($body, true));
116117
} catch (BadResponseException $e) {

tests/ConsulFeatureRequesterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ConsulFeatureRequesterTest extends FeatureRequesterTestBase
1313

1414
private static $kvClient;
1515

16-
public static function setUpBeforeClass()
16+
public static function setUpBeforeClass(): void
1717
{
1818
if (!static::isSkipDatabaseTests()) {
1919
$sf = new ServiceFactory();

tests/DynamoDbFeatureRequesterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DynamoDbFeatureRequesterTest extends FeatureRequesterTestBase
1313

1414
private static $dynamoDbClient;
1515

16-
public static function setUpBeforeClass()
16+
public static function setUpBeforeClass(): void
1717
{
1818
if (!static::isSkipDatabaseTests()) {
1919
self::$dynamoDbClient = new DynamoDbClient(self::makeDynamoDbOptions());

tests/EvaluationReasonTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
namespace LaunchDarkly\Tests;
33

44
use LaunchDarkly\EvaluationReason;
5+
use PHPUnit\Framework\TestCase;
56

6-
class EvaluationReasonTest extends \PHPUnit_Framework_TestCase
7+
class EvaluationReasonTest extends \PHPUnit\Framework\TestCase
78
{
89
public function testOffReasonSerialization()
910
{

tests/EventSerializerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
use LaunchDarkly\EventSerializer;
55
use LaunchDarkly\LDUserBuilder;
6+
use PHPUnit\Framework\TestCase;
67

7-
class EventSerializerTest extends \PHPUnit_Framework_TestCase
8+
class EventSerializerTest extends \PHPUnit\Framework\TestCase
89
{
910
private function getUser()
1011
{

0 commit comments

Comments
 (0)