Skip to content

Commit 7e0d1ac

Browse files
author
Grzegorz Rajchman
authored
PLAT-4021 allow to set logger (#28)
* Allow to set logger on clients * Use common TestBase for all tests * Retrieve request ID from query string * Bump version and sort packages * Use composer scripts, remove ant
1 parent 2b88d4f commit 7e0d1ac

22 files changed

+259
-277
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ composer.lock
33
composer.phar
44
.idea
55
build
6+
coverage
67
vendor
78
docker-compose.override.yml
89
.env

.travis.yml

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
language: php
22
dist: trusty
3-
sudo: false
4-
addons:
5-
apt:
6-
packages: ant
73
php:
84
- 7.3
95
- 7.2
@@ -14,10 +10,9 @@ php:
1410
install:
1511
- composer self-update
1612
- composer install
17-
script: |
18-
set -xe
19-
ant lint
20-
ant test
13+
script:
14+
- composer run lint
15+
- composer run test
2116
env:
2217
global:
2318
- PERSONA_TEST_HOST: https://staging-users.talis.com

Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ RUN apt-get update \
1515
php5-curl \
1616
php5-json \
1717
php-pear \
18-
ant \
1918
git \
2019
unzip \
2120
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

build.xml

-91
This file was deleted.

composer.json

+32-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "talis/talis-php",
33
"description": "This is a php client library for talis APIs",
4-
"version": "0.6.2",
4+
"version": "0.6.3",
55
"keywords": [
66
"persona",
77
"echo",
@@ -14,14 +14,17 @@
1414
"homepage": "https://github.com/talis/talis-php",
1515
"type": "library",
1616
"license": "MIT",
17+
"config": {
18+
"sort-packages": true
19+
},
1720
"require": {
1821
"php": ">=5.5.9",
19-
"monolog/monolog": ">=1.13.1",
20-
"psr/log": ">=1.0.0",
21-
"firebase/php-jwt": "^3.0",
2222
"doctrine/common": "^2.5",
23-
"predis/predis" : ">=0.8.5",
24-
"guzzlehttp/guzzle": "^6.0"
23+
"firebase/php-jwt": "^3.0",
24+
"guzzlehttp/guzzle": "^6.0",
25+
"monolog/monolog": ">=1.13.1",
26+
"predis/predis": ">=0.8.5",
27+
"psr/log": ">=1.0.0"
2528
},
2629
"require-dev": {
2730
"phpunit/phpunit": "4.8.36",
@@ -42,5 +45,28 @@
4245
"psr-4": {
4346
"test\\": "test/"
4447
}
48+
},
49+
"scripts": {
50+
"code-check": "phpmd src text codesize,unusedcode,naming",
51+
"lint": [
52+
"@phplint",
53+
"phpcs"
54+
],
55+
"phplint": "phplint --exclude=vendor --no-cache .",
56+
"test": "phpunit",
57+
"clean-build": "rm -rf build; mkdir build",
58+
"clean-coverage": "rm -rf coverage; mkdir coverage",
59+
"coverage": [
60+
"@clean-coverage",
61+
"phpunit --coverage-text --coverage-html coverage"
62+
],
63+
"unittest": [
64+
"@clean-build",
65+
"phpunit test/unit --log-junit build/unittest-report.xml"
66+
],
67+
"integrationtest": [
68+
"@clean-build",
69+
"phpunit test/integration --log-junit build/integrationtest-report.xml"
70+
]
4571
}
4672
}

docker-compose.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@ x-common-values: &common-values
1616
services:
1717
init:
1818
<<: *common-values
19-
command: "ant init"
19+
command: "bash -c 'test -f composer.phar || (curl -sS https://getcomposer.org/installer | php); php composer.phar install'"
2020

2121
lint:
2222
<<: *common-values
23-
command: "ant lint"
23+
command: "php composer.phar lint"
2424

2525
code-check:
2626
<<: *common-values
27-
command: "ant code-check"
27+
command: "php composer.phar code-check"
2828

2929
test:
3030
<<: *common-values
31-
command: "ant test"
31+
command: "php composer.phar test"
3232

3333
unittest:
3434
<<: *common-values
35-
command: "ant unittest"
35+
command: "php composer.phar unittest"
3636

3737
integrationtest:
3838
<<: *common-values
39-
command: "ant integrationtest"
39+
command: "php composer.phar integrationtest"
4040

4141
local-dev:
4242
<<: *common-values
4343
command: "/bin/bash"
4444

4545
coverage:
4646
<<: *common-values
47-
command: "ant coverage"
47+
command: "php composer.phar coverage"
4848

4949
analyse:
5050
image: phpstan/phpstan:0.12.40

phpunit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<phpunit bootstrap="test/bootstrap.php">
1+
<phpunit bootstrap="test/bootstrap.php" colors = "true">
22
<php>
33
<ini name="memory_limit" value="512M"/>
44
</php>

src/Talis/Babel/Client.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Monolog\Handler\StreamHandler;
66
use Monolog\Logger;
7+
use Psr\Log\LoggerAwareInterface;
78

89
/**
910
* Babel client.
@@ -12,7 +13,7 @@
1213
*
1314
* @package Talis\Babel
1415
*/
15-
class Client
16+
class Client implements LoggerAwareInterface
1617
{
1718
/**
1819
* @var string

src/Talis/EchoClient/Base.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract class Base
1414
/**
1515
* Get the current Logger instance.
1616
*
17-
* @return \Monolog\Logger
17+
* @return \Psr\Log\LoggerInterface
1818
*/
1919
protected function getLogger()
2020
{
@@ -36,9 +36,9 @@ protected function getLogger()
3636
/**
3737
* Allow the calling project to use its own instance of a MonoLog Logger class.
3838
*
39-
* @param \Monolog\Logger $logger logger
39+
* @param \Psr\Log\LoggerInterface $logger logger
4040
*/
41-
public static function setLogger(Logger $logger)
41+
public static function setLogger(\Psr\Log\LoggerInterface $logger)
4242
{
4343
self::$logger = $logger;
4444
}

src/Talis/Persona/Client/Base.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Talis\Persona\Client;
44

55
use Monolog\Logger;
6-
use Predis\Response\ResponseInterface;
6+
use Psr\Log\LoggerAwareInterface;
77
use Talis\Persona\Client\ClientVersionCache;
88

9-
abstract class Base
9+
abstract class Base implements LoggerAwareInterface
1010
{
1111
use ClientVersionCache;
1212

@@ -100,6 +100,11 @@ protected function checkConfig(array $config)
100100
}
101101
}
102102

103+
public function setLogger(\Psr\Log\LoggerInterface $logger)
104+
{
105+
$this->logger = $logger;
106+
}
107+
103108
/**
104109
* @return \Psr\Log\LoggerInterface
105110
*/
@@ -114,8 +119,6 @@ protected function getLogger()
114119

115120
/**
116121
* Returns a unique id for tracing this request.
117-
* If there is already a value set as a header it uses that, otherwise it
118-
* generates a new one and sets that on $_SERVER
119122
* @return string
120123
*/
121124
protected function getRequestId()
@@ -124,6 +127,9 @@ protected function getRequestId()
124127
if (array_key_exists('HTTP_X_REQUEST_ID', $_SERVER)) {
125128
$requestId = $_SERVER['HTTP_X_REQUEST_ID'];
126129
}
130+
if ($requestId === null && array_key_exists('xid', $_GET)) {
131+
$requestId = $_GET['xid'];
132+
}
127133

128134
return empty($requestId) ? uniqid() : $requestId;
129135
}

test/TestBase.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,22 @@ protected function getPersonaConfig()
4343
];
4444
}
4545

46+
/**
47+
* @before
48+
*/
49+
protected function printName()
50+
{
51+
$className = get_class($this);
52+
$testName = $this->getName();
53+
echo " Test: {$className}->{$testName}\n";
54+
}
55+
4656
protected function setUp()
4757
{
4858
$this->removeCacheFolder();
4959
$this->cacheBackend = new FilesystemCache(
5060
sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'personaCache'
5161
);
52-
$className = get_class($this);
53-
$testName = $this->getName();
54-
echo " Test: {$className}->{$testName}\n";
5562
}
5663

5764
/**

test/integration/Persona/TokensIntegrationTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function setUp()
3131
'cacheBackend' => $this->personaCache,
3232
]
3333
);
34+
$this->personaClient->setLogger(new \Psr\Log\NullLogger());
3435
}
3536

3637
public function testObtainNewToken()

test/integration/Persona/UsersIntegrationTest.php test/integration/Persona/UsersIntegerationTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function setUp()
3434
'cacheBackend' => $this->cacheBackend,
3535
]
3636
);
37+
$this->personaClientUser->setLogger(new \Psr\Log\NullLogger());
3738

3839
$this->personaClientTokens = new Tokens(
3940
[
@@ -42,6 +43,7 @@ public function setUp()
4243
'cacheBackend' => $this->cacheBackend,
4344
]
4445
);
46+
$this->personaClientTokens->setLogger(new \Psr\Log\NullLogger());
4547
}
4648

4749
public function testCreateUserThenGetUserByGupid()

test/unit/Babel/ClientTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace test\unit\Babel;
44

5+
use test\TestBase;
6+
57
/**
68
* Travis-CI runs against the unit tests but can only test certain things.
79
*
810
* You should run the integration tests locally, with a running local Babel server setup, as the
911
* integration tests actually prove that this client library can read/write to Babel correctly.
1012
*/
11-
class ClientTest extends \PHPUnit_Framework_TestCase
13+
class ClientTest extends TestBase
1214
{
1315
private $babelClient;
1416
private $baseCreateAnnotationData;

0 commit comments

Comments
 (0)