Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 5107e51

Browse files
authored
Add pgsql integration tests (#187)
1 parent 1cc9895 commit 5107e51

File tree

15 files changed

+473
-63
lines changed

15 files changed

+473
-63
lines changed

.circleci/config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ jobs:
163163
MYSQL_PASSWORD: mysql
164164
MYSQL_DATABASE: mysqldb
165165
MYSQL_RANDOM_ROOT_PASSWORD: yes
166+
- image: postgres:9.6
167+
environment:
168+
POSTGRES_PASSWORD: pgsql
169+
POSTGRES_USER: postgres
166170
steps:
167171
- checkout
168172
- run:
@@ -174,6 +178,7 @@ jobs:
174178
g++ \
175179
gcc \
176180
libc-dev \
181+
libpqxx-dev \
177182
make \
178183
autoconf \
179184
git \
@@ -199,6 +204,9 @@ jobs:
199204
- run:
200205
name: Install mysqli extension
201206
command: sudo docker-php-ext-install mysqli
207+
- run:
208+
name: Install pgsql extension
209+
command: sudo docker-php-ext-install pgsql
202210
- run:
203211
name: Curl test
204212
command: tests/integration/curl/test.sh
@@ -214,6 +222,9 @@ jobs:
214222
- run:
215223
name: Memcached test
216224
command: tests/integration/memcached/test.sh
225+
- run:
226+
name: Pgsql test
227+
command: tests/integration/pgsql/test.sh
217228
- run:
218229
name: Symfony 4 test
219230
command: tests/integration/symfony4/test.sh

src/Trace/Integrations/Memcached.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public static function load()
127127
* @param \Memcached $memcached
128128
* @param array|string $keyOrKeys The key or keys to operate on
129129
* @return array
130+
*
131+
* @access private
130132
*/
131133
public static function handleAttributes($memcached, $keyOrKeys)
132134
{
@@ -145,6 +147,8 @@ public static function handleAttributes($memcached, $keyOrKeys)
145147
* @param string $serverKey The key identifying the server to store the value on or retrieve it from.
146148
* @param array|string $keyOrKeys The key or keys to operate on
147149
* @return array
150+
*
151+
* @access private
148152
*/
149153
public static function handleAttributesByKey($memcached, $serverKey, $keyOrKeys)
150154
{
@@ -167,6 +171,8 @@ public static function handleAttributesByKey($memcached, $serverKey, $keyOrKeys)
167171
* memcache.
168172
* @param string $key The key or keys to operate on
169173
* @return array
174+
*
175+
* @access private
170176
*/
171177
public static function handleCas($memcached, $casToken, $key)
172178
{
@@ -189,6 +195,8 @@ public static function handleCas($memcached, $casToken, $key)
189195
* @param string $serverKey The key identifying the server to store the value on or retrieve it from.
190196
* @param string $key The key or keys to operate on
191197
* @return array
198+
*
199+
* @access private
192200
*/
193201
public static function handleCasByKey($memcached, $casToken, $serverKey, $key)
194202
{
@@ -209,6 +217,8 @@ public static function handleCasByKey($memcached, $casToken, $serverKey, $key)
209217
* @param \Memcached $memcached
210218
* @param array $items The items being set in memcached.
211219
* @return array
220+
*
221+
* @access private
212222
*/
213223
public static function handleSetMulti($memcached, $items)
214224
{
@@ -226,6 +236,8 @@ public static function handleSetMulti($memcached, $items)
226236
* @param string $serverKey The key identifying the server to store the value on or retrieve it from.
227237
* @param array $items The items being set in memcached.
228238
* @return array
239+
*
240+
* @access private
229241
*/
230242
public static function handleSetMultiByKey($memcached, $serverKey, $items)
231243
{

src/Trace/Integrations/Postgres.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public static function load()
4141
return;
4242
}
4343

44+
// resource pg_connect ( string $connection_string [, int $connect_type ] )
45+
// resource pg_pconnect ( string $connection_string [, int $connect_type ] )
46+
opencensus_trace_function('pg_connect');
47+
opencensus_trace_function('pg_pconnect');
48+
4449
// resource pg_query([resource $connection], string $query)
4550
opencensus_trace_function('pg_query', function () {
4651
$query = func_num_args() > 1
@@ -63,6 +68,23 @@ public static function load()
6368
];
6469
});
6570

71+
// resource pg_prepare ([ resource $connection ], string $stmtname , string $query )
72+
opencensus_trace_function('pg_prepare', function () {
73+
$statementName = func_num_args() > 2
74+
? func_get_arg(1)
75+
: func_get_arg(0);
76+
$query = func_num_args() > 2
77+
? func_get_arg(2)
78+
: func_get_arg(1);
79+
return [
80+
'attributes' => [
81+
'statement' => $statementName,
82+
'query' => $query
83+
],
84+
'kind' => Span::KIND_CLIENT
85+
];
86+
});
87+
6688
// resource pg_execute([resource $connection], string $stmtname, array $params)
6789
opencensus_trace_function('pg_execute', function () {
6890
$statementName = func_num_args() > 2

tests/integration/curl/test.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/bin/bash
2+
# Copyright 2018 OpenCensus Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
215

316
set -e
417

5-
if [ -z "${CIRCLE_PR_NUMBER}" ]; then
6-
BRANCH="master"
7-
REPO="https://github.com/census-instrumentation/opencensus-php"
8-
else
9-
PR_INFO=$(curl "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}")
10-
BRANCH=$(echo $PR_INFO | jq -r .head.ref)
11-
REPO=$(echo $PR_INFO | jq -r .head.repo.html_url)
12-
fi
13-
1418
pushd $(dirname ${BASH_SOURCE[0]})
19+
source ../setup_test_repo.sh
1520

1621
sed -i "s|dev-master|dev-${BRANCH}|" composer.json
1722
sed -i "s|https://github.com/census-instrumentation/opencensus-php|${REPO}|" composer.json

tests/integration/guzzle5/test.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/bin/bash
2+
# Copyright 2018 OpenCensus Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
215

316
set -e
417

5-
if [ -z "${CIRCLE_PR_NUMBER}" ]; then
6-
BRANCH="master"
7-
REPO="https://github.com/census-instrumentation/opencensus-php"
8-
else
9-
PR_INFO=$(curl "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}")
10-
BRANCH=$(echo $PR_INFO | jq -r .head.ref)
11-
REPO=$(echo $PR_INFO | jq -r .head.repo.html_url)
12-
fi
13-
1418
pushd $(dirname ${BASH_SOURCE[0]})
19+
source ../setup_test_repo.sh
1520

1621
sed -i "s|dev-master|dev-${BRANCH}|" composer.json
1722
sed -i "s|https://github.com/census-instrumentation/opencensus-php|${REPO}|" composer.json

tests/integration/guzzle6/test.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/bin/bash
2+
# Copyright 2018 OpenCensus Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
215

316
set -e
417

5-
if [ -z "${CIRCLE_PR_NUMBER}" ]; then
6-
BRANCH="master"
7-
REPO="https://github.com/census-instrumentation/opencensus-php"
8-
else
9-
PR_INFO=$(curl "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}")
10-
BRANCH=$(echo $PR_INFO | jq -r .head.ref)
11-
REPO=$(echo $PR_INFO | jq -r .head.repo.html_url)
12-
fi
13-
1418
pushd $(dirname ${BASH_SOURCE[0]})
19+
source ../setup_test_repo.sh
1520

1621
sed -i "s|dev-master|dev-${BRANCH}|" composer.json
1722
sed -i "s|https://github.com/census-instrumentation/opencensus-php|${REPO}|" composer.json

tests/integration/laravel/test.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/bin/bash
2+
# Copyright 2018 OpenCensus Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
215

316
set -e
417

5-
if [ -z "${CIRCLE_PR_NUMBER}" ]; then
6-
BRANCH="master"
7-
REPO="https://github.com/census-instrumentation/opencensus-php"
8-
else
9-
PR_INFO=$(curl "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}")
10-
BRANCH=$(echo $PR_INFO | jq -r .head.ref)
11-
REPO=$(echo $PR_INFO | jq -r .head.repo.html_url)
12-
fi
13-
1418
pushd $(dirname ${BASH_SOURCE[0]})
19+
source ../setup_test_repo.sh
1520

1621
composer create-project --prefer-dist laravel/laravel laravel
1722
cp -R . laravel || true

tests/integration/memcached/test.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/bin/bash
2+
# Copyright 2018 OpenCensus Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
215

316
set -e
417

5-
if [ -z "${CIRCLE_PR_NUMBER}" ]; then
6-
BRANCH="master"
7-
REPO="https://github.com/census-instrumentation/opencensus-php"
8-
else
9-
PR_INFO=$(curl "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}")
10-
BRANCH=$(echo $PR_INFO | jq -r .head.ref)
11-
REPO=$(echo $PR_INFO | jq -r .head.repo.html_url)
12-
fi
13-
1418
pushd $(dirname ${BASH_SOURCE[0]})
19+
source ../setup_test_repo.sh
1520

1621
sed -i "s|dev-master|dev-${BRANCH}|" composer.json
1722
sed -i "s|https://github.com/census-instrumentation/opencensus-php|${REPO}|" composer.json
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"require": {
3+
"php": "^7.2",
4+
"opencensus/opencensus": "dev-master",
5+
"ext-opencensus": "*",
6+
"ext-pgsql": "*"
7+
},
8+
"require-dev": {
9+
"phpunit/phpunit": "^7.0"
10+
},
11+
"repositories": [
12+
{
13+
"type": "git",
14+
"url": "https://github.com/census-instrumentation/opencensus-php"
15+
}
16+
]
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="./vendor/autoload.php" colors="true">
3+
<testsuites>
4+
<testsuite>
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<filter>
9+
<whitelist>
10+
<directory suffix=".php">src</directory>
11+
<exclude>
12+
<directory suffix=".php">src/*/V[!a-zA-Z]*</directory>
13+
<directory suffix=".php">src/*/*/V[!a-zA-Z]*</directory>
14+
<directory suffix=".php">src/*/*/*/V[!a-zA-Z]*</directory>
15+
</exclude>
16+
</whitelist>
17+
</filter>
18+
<logging>
19+
<log type="coverage-clover" target="build/clover.xml"/>
20+
</logging>
21+
</phpunit>

0 commit comments

Comments
 (0)