Skip to content

Commit d9af33f

Browse files
authored
change test service to not require Docker, enable tests in CI (#100)
1 parent 113969e commit d9af33f

File tree

10 files changed

+59
-169
lines changed

10 files changed

+59
-169
lines changed

.circleci/config.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353

5454
environment:
5555
LD_INCLUDE_INTEGRATION_TESTS: 1
56+
TEST_HARNESS_PARAMS: -junit build/contract-tests-output/junit-results.xml
5657

5758
docker:
5859
- image: cimg/php:<<parameters.php-version>>
@@ -90,10 +91,23 @@ jobs:
9091
- run:
9192
name: run tests
9293
command: php -d xdebug.mode=coverage vendor/bin/phpunit
93-
enviroment:
94+
environment:
9495
XDEBUG_MODE: coverage
9596

97+
- run:
98+
name: build contract test service
99+
command: make build-contract-tests
100+
- run:
101+
name: start contract test service
102+
command: make start-contract-test-service
103+
background: true
104+
- run:
105+
name: run contract tests
106+
command: mkdir -p build/contract-tests-output && make run-contract-tests
107+
96108
- store_test_results:
97109
path: build/phpunit
110+
- store_test_results:
111+
path: build/contract-tests-output
98112
- store_artifacts:
99113
path: build/phpunit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/vendor/
2+
/test-service/vendor/
23
/doc/
34
*.iml
45
composer.phar

Dockerfile.testservice

Lines changed: 0 additions & 41 deletions
This file was deleted.

Makefile

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
TEMP_TEST_OUTPUT=/tmp/sse-contract-test-service.log
33

44
# TEST_HARNESS_PARAMS can be set to add -skip parameters for any contract tests that cannot yet pass
5-
TEST_HARNESS_PARAMS=
5+
# Explanation of current skips:
6+
# - "secondary": In the PHP SDK this is not an addressable attribute for clauses; in other
7+
# SDKs, it is. This was underspecified in the past; in future major versions, the other
8+
# SDKs and the contract tests will be in line with the PHP behavior.
9+
# - "date - bad syntax", "semver - bad type": The PHP SDK has insufficiently strict
10+
# validation for these types. We will definitely fix this in 5.0 but may or may not
11+
# address it in 4.x, since it does not prevent any valid values from working.
12+
TEST_HARNESS_PARAMS := $(TEST_HARNESS_PARAMS) \
13+
-skip 'evaluation/parameterized/secondary' \
14+
-skip 'evaluation/parameterized/operators - date - bad syntax' \
15+
-skip 'evaluation/parameterized/operators - semver - bad type'
616

717
build-contract-tests:
8-
@docker build -f Dockerfile.testservice -t php-test-service .
18+
@cd test-service && composer install --no-progress
919

1020
start-contract-test-service: build-contract-tests
11-
@docker run -it --rm \
12-
--name php-test-service \
13-
--publish 8000:8000 \
14-
--add-host=host.docker.internal:host-gateway \
15-
php-test-service
21+
@cd test-service && php -S localhost:8000 index.php
1622

1723
start-contract-test-service-bg:
1824
@echo "Test service output will be captured in $(TEMP_TEST_OUTPUT)"

test-service/.htaccess

Lines changed: 0 additions & 4 deletions
This file was deleted.

test-service/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ This directory contains an implementation of the cross-platform SDK testing prot
55
To run these tests locally, run `make contract-tests` from the SDK project root directory. This downloads the correct version of the test harness tool automatically.
66

77
Or, to test against an in-progress local version of the test harness, run `make start-contract-test-service` from the SDK project root directory; then, in the root directory of the `sdk-test-harness` project, build the test harness and run it from the command line.
8+
9+
The test service is designed to be run by any web server; PHP's built-in development server is adequate. The server must be configured to run `index.php` for all requests. The environment variable `LD_TEST_SERVICE_DATA_DIR` can be set, if desired, to point to a specific file path where the test service can store data; otherwise it will create a directory under `/tmp`.

test-service/SdkClientEntity.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public static function createSdkClient($params, $logger)
3131
];
3232

3333
$pollingConfig = $config['polling'] ?? [];
34-
$options['base_uri'] = self::adjustBaseUri($pollingConfig['baseUri'] ?? null);
34+
$options['base_uri'] = $pollingConfig['baseUri'] ?? null;
3535

3636
$options['send_events'] = ($config['events'] ?? null) !== null;
3737
$eventsConfig = $config['events'] ?? [];
38-
$options['events_uri'] = self::adjustBaseUri($eventsConfig['baseUri'] ?? null);
38+
$options['events_uri'] = $eventsConfig['baseUri'] ?? null;
3939
$options['all_attributes_private'] = $eventsConfig['allAttributesPrivate'] ?? false;
4040
$options['private_attribute_names'] = $eventsConfig['globalPrivateAttributes'] ?? null;
4141

@@ -53,6 +53,10 @@ public function doCommand($reqParams)
5353
$command = $reqParams['command'];
5454
$commandParams = $reqParams[$command] ?? null;
5555
switch ($command) {
56+
case 'aliasEvent':
57+
$this->doAliasEvent($commandParams);
58+
return null;
59+
5660
case 'customEvent':
5761
$this->doCustomEvent($commandParams);
5862
return null;
@@ -79,11 +83,12 @@ public function doCommand($reqParams)
7983
}
8084
}
8185

82-
private static function adjustBaseUri($baseUri)
86+
private function doAliasEvent($params)
8387
{
84-
return $baseUri ?
85-
preg_replace('@^http://localhost:@', 'http://host.docker.internal:', $baseUri)
86-
: null;
88+
$this->_client->alias(
89+
$this->makeUser($params['user']),
90+
$this->makeUser($params['previousUser'])
91+
);
8792
}
8893

8994
private function doCustomEvent($params)

test-service/apache2.conf

Lines changed: 0 additions & 106 deletions
This file was deleted.

test-service/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
],
88
"require": {
99
"doctrine/cache": "^1.0",
10-
"guzzlehttp/guzzle": "^7",
11-
"kevinrob/guzzle-cache-middleware": "^3",
10+
"guzzlehttp/guzzle": "^6.3 | ^7",
11+
"kevinrob/guzzle-cache-middleware": "^4.0",
1212
"launchdarkly/server-sdk": "*",
13-
"mikecao/flight": "1.*",
13+
"mikecao/flight": "1.* | 2.*",
1414
"monolog/monolog": "1.*",
1515
"php": ">=7.3",
1616
"psr/log": "1.*"

test-service/index.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
// This script is executed by the webserver for every request, regardless of the
4+
// request path. We use Flight to route requests.
5+
36
require_once 'vendor/autoload.php';
47

58
require_once 'SdkClientEntity.php';
@@ -12,6 +15,16 @@
1215
$logger = new Monolog\Logger('testservice');
1316
$logger->pushHandler(new Monolog\Handler\StreamHandler('php://stderr', Monolog\Logger::DEBUG));
1417

15-
$store = new TestDataStore('/app/test-service/data-store');
18+
$dataStorePath = getenv("LD_TEST_SERVICE_DATA_DIR");
19+
if (!$dataStorePath) {
20+
$dataStorePath = '/tmp/php-server-sdk-test-service';
21+
}
22+
if (!is_dir($dataStorePath)) {
23+
if (!mkdir($dataStorePath, 0700, true)) {
24+
return false;
25+
}
26+
}
27+
28+
$store = new TestDataStore($dataStorePath);
1629
$service = new TestService($store, $logger);
1730
$service->start();

0 commit comments

Comments
 (0)