Skip to content

Commit 5b5f24f

Browse files
authored
implement unit tests (#4)
1 parent c48fd7f commit 5b5f24f

File tree

13 files changed

+679
-3
lines changed

13 files changed

+679
-3
lines changed

.circleci/config.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: 2.1
2+
3+
workflows:
4+
workflow:
5+
jobs:
6+
- linux-test:
7+
name: PHP 7.3
8+
docker-image: cimg/php:7.3
9+
- linux-test:
10+
name: PHP 7.4
11+
docker-image: cimg/php:7.4
12+
13+
jobs:
14+
linux-test:
15+
parameters:
16+
docker-image:
17+
type: string
18+
19+
docker:
20+
- image: <<parameters.docker-image>>
21+
- image: redis
22+
23+
steps:
24+
- checkout
25+
- run:
26+
name: install phpredis
27+
command: |
28+
yes '' | sudo pecl install -f redis || true
29+
echo "extension=redis.so" | sudo tee -a $(php -r 'echo get_cfg_var("cfg_file_path");') >/dev/null
30+
- run:
31+
name: install dependencies
32+
command: composer install --no-progress
33+
- run: mkdir -p ./phpunit
34+
- run:
35+
name: run tests
36+
command: php vendor/bin/phpunit
37+
- store_test_results:
38+
path: ./phpunit
39+
- store_artifacts:
40+
path: ./phpunit

composer.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"repositories": [
3+
{
4+
"type": "path",
5+
"url": "php-server-sdk-shared-tests"
6+
},
37
{
48
"type": "git",
59
"url": "https://github.com/launchdarkly/php-server-sdk-private.git"
@@ -23,11 +27,20 @@
2327
"php": ">=7.3",
2428
"launchdarkly/server-sdk": "4.0.x-dev"
2529
},
30+
"require-dev": {
31+
"launchdarkly/server-sdk-shared-tests": "dev-master",
32+
"phpunit/phpunit": "^9"
33+
},
2634
"autoload": {
2735
"psr-4": {
2836
"LaunchDarkly\\": "src/LaunchDarkly/"
2937
}
3038
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"LaunchDarkly\\Impl\\Integrations\\Tests\\": "tests/"
42+
}
43+
},
3144
"config": {
3245
"sort-packages": true
3346
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: 2.1
2+
3+
workflows:
4+
workflow:
5+
jobs:
6+
- linux-test:
7+
name: PHP 7.3
8+
docker-image: cimg/php:7.3
9+
- linux-test:
10+
name: PHP 7.4
11+
docker-image: cimg/php:7.4
12+
13+
jobs:
14+
linux-test:
15+
parameters:
16+
docker-image:
17+
type: string
18+
19+
docker:
20+
- image: <<parameters.docker-image>>
21+
22+
steps:
23+
- checkout
24+
- run:
25+
name: install dependencies
26+
command: composer install --no-progress
27+
- run: mkdir -p ./phpunit
28+
- run:
29+
name: run tests
30+
command: php vendor/bin/phpunit
31+
- store_test_results:
32+
path: ./phpunit
33+
- store_artifacts:
34+
path: ./phpunit
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vendor/
2+
composer.lock
3+
phpunit/
4+
.phpunit.result.cache
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2021 Catamorphic, Co.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# LaunchDarkly Server-Side PHP SDK Shared Test Code
2+
3+
[![CircleCI](https://circleci.com/gh/launchdarkly/php-server-sdk-shared-tests.svg?style=svg)](https://circleci.com/gh/launchdarkly/php-server-sdk-shared-tests)
4+
5+
This project provides support code for testing LaunchDarkly PHP SDK integrations. Feature store implementations, etc., should use this code whenever possible to ensure consistent test coverage and avoid repetition. An example of a project using this code is [php-server-sdk-redis](https://github.com/launchdarkly/php-server-sdk-redis).
6+
7+
The code is not published to Packagist, since it isn't of any use in any non-test context. Instead, it's meant to be used as a Git subtree. Add the subtree to your project like this:
8+
9+
git remote add php-server-sdk-shared-tests git@github.com:launchdarkly/php-server-sdk-shared-tests.git
10+
git subtree add --squash --prefix=php-server-sdk-shared-tests/ php-server-sdk-shared-tests master
11+
12+
Then, in your project that uses the shared tests, add this to `composer.json`:
13+
14+
```json
15+
"repositories": [
16+
{
17+
"type": "path",
18+
"url": "php-server-sdk-shared-tests"
19+
},
20+
],
21+
```
22+
23+
And add this dependency:
24+
25+
```json
26+
"launchdarkly/server-sdk-shared-tests": "dev-master"
27+
```
28+
29+
To update the copy of `php-server-sdk-shared-tests` in your repository to reflect changes in this one:
30+
31+
git subtree pull --squash --prefix=php-server-sdk-shared-tests/ php-server-sdk-shared-tests master
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "launchdarkly/server-sdk-shared-tests",
3+
"description": "Shared unit test code for LaunchDarkly PHP SDK",
4+
"license": "Apache-2.0",
5+
"authors": [
6+
{
7+
"name": "LaunchDarkly <team@launchdarkly.com>",
8+
"homepage": "http://launchdarkly.com/"
9+
}
10+
],
11+
"require": {
12+
"php": ">=7.3"
13+
},
14+
"require-dev": {
15+
"launchdarkly/server-sdk": ">=3.9",
16+
"phpunit/phpunit": "^9"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"LaunchDarkly\\SharedTest\\": "src/"
21+
}
22+
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"LaunchDarkly\\SharedTest\\Tests\\": "tests/"
26+
}
27+
},
28+
"config": {
29+
"sort-packages": true
30+
},
31+
"scripts": {
32+
"cs": "vendor/bin/php-cs-fixer fix --diff --verbose"
33+
}
34+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
<testsuites>
9+
<testsuite name="Unit Tests">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
</phpunit>

0 commit comments

Comments
 (0)