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

Commit 2e3e731

Browse files
authored
Add Integration tests (#181)
* Add Curl integration test Add wordpress example/integration test run integration test in circle ci specify mysql:5.7 and only run integrations for now Skip batcache for wordpress Add memcached test Move wordpress test to integration, run memcached test Fix memcached extension loading. Wait for mysql container Fix php version for memcached test Parameterize memcache composer url Fix sed Fix composer branch Fix mysql start Put wp-config in correct location Add laravel integration test Fix laravel network, run migrations Fix database migration command Install pdo/pdo_mysql extensions Pass db credentials as env vars Fix docker run argument order Add eloquent database tests Try memcached test without docker Install memcached extension without prompts Fix test script name Combine laravel and wordpress tests into single integration test Ignore return code for file copy. Fix wordpress db config Cleanup missing vars Run curl tests in integrations Add guzzle5/6 tests Re-enable unit tests * Fix copyright headers for laravel test files * Fix a few test names * separate bootstrap file unnecessary if only autoloading * Add symfony/doctrine integration test * Run symfony test * Configure database for symfony tests * Skip creating database - already created * Run doctrine migrations without interaction * curl and memcached do not need a bootstrap test file
1 parent 9b05ea8 commit 2e3e731

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2277
-5
lines changed

.circleci/config.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,81 @@ jobs:
153153
RUN_EXTENSION_TESTS: 1
154154
SUDO_CMD: ""
155155

156+
integration:
157+
docker:
158+
- image: circleci/php:7.2-node
159+
- image: memcached
160+
- image: mysql:5.7
161+
environment:
162+
MYSQL_USER: mysql
163+
MYSQL_PASSWORD: mysql
164+
MYSQL_DATABASE: mysqldb
165+
MYSQL_RANDOM_ROOT_PASSWORD: yes
166+
steps:
167+
- checkout
168+
- run:
169+
name: Install build tools
170+
command: |
171+
sudo apt-get update -y
172+
sudo apt-get install -y -q --no-install-recommends \
173+
build-essential \
174+
g++ \
175+
gcc \
176+
libc-dev \
177+
make \
178+
autoconf \
179+
git \
180+
unzip
181+
- run:
182+
name: Install opencensus extension
183+
command: |
184+
cd ext
185+
phpize
186+
./configure --enable-opencensus
187+
sudo make install
188+
sudo docker-php-ext-enable opencensus
189+
- run:
190+
name: Install memcached extension
191+
command: |
192+
sudo apt-get install -y -q --no-install-recommends \
193+
libmemcached11 libmemcached-dev zlib1g-dev zlib1g
194+
sudo pecl install memcached <<<''
195+
sudo docker-php-ext-enable memcached
196+
- run:
197+
name: Install pdo_mysql extension
198+
command: sudo docker-php-ext-install pdo_mysql
199+
- run:
200+
name: Install mysqli extension
201+
command: sudo docker-php-ext-install mysqli
202+
- run:
203+
name: Curl test
204+
command: tests/integration/curl/test.sh
205+
- run:
206+
name: Guzzle 5 test
207+
command: tests/integration/guzzle5/test.sh
208+
- run:
209+
name: Guzzle 6 test
210+
command: tests/integration/guzzle6/test.sh
211+
- run:
212+
name: Laravel test
213+
command: tests/integration/laravel/test.sh
214+
- run:
215+
name: Memcached test
216+
command: tests/integration/memcached/test.sh
217+
- run:
218+
name: Symfony 4 test
219+
command: tests/integration/symfony4/test.sh
220+
environment:
221+
DATABASE_URL: mysql://mysql:mysql@127.0.0.1:3306/mysqldb
222+
- run:
223+
name: Wordpress test
224+
command: tests/integration/wordpress/test.sh
225+
environment:
226+
DB_HOST: 127.0.0.1
227+
DB_USERNAME: mysql
228+
DB_PASSWORD: mysql
229+
DB_DATABASE: mysqldb
230+
156231
workflows:
157232
version: 2
158233
units:
@@ -168,3 +243,4 @@ workflows:
168243
- php70-32bit
169244
- php71-32bit
170245
- php71-debug
246+
- integration

src/Trace/Integrations/Eloquent.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ public static function load()
7777
});
7878

7979
// public function delete()
80-
opencensus_trace_method(Model::class, 'delete', function ($model, $query) {
80+
opencensus_trace_method(Model::class, 'delete', function ($model) {
8181
return [
8282
'name' => 'eloquent/delete',
83-
'attributes' => [
84-
'query' => $query->toBase()->toSql()
85-
],
8683
'kind' => Span::KIND_CLIENT
8784
];
8885
});

src/Trace/Integrations/Memcached.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static function load()
4545
opencensus_trace_method('Memcached', 'add', [self::class, 'handleAttributes']);
4646

4747
// bool Memcached::addByKey ( string $server_key , string $key , mixed $value [, int $expiration ] )
48-
opencensus_trace_method('Memcached', 'add', [self::class, 'handleAttributesByKey']);
48+
opencensus_trace_method('Memcached', 'addByKey', [self::class, 'handleAttributesByKey']);
4949

5050
// bool Memcached::append ( string $key , string $value )
5151
opencensus_trace_method('Memcached', 'append', [self::class, 'handleAttributes']);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"require": {
3+
"php": "^7.2",
4+
"opencensus/opencensus": "dev-master",
5+
"ext-opencensus": "*"
6+
},
7+
"require-dev": {
8+
"phpunit/phpunit": "^7.0"
9+
},
10+
"repositories": [
11+
{
12+
"type": "git",
13+
"url": "https://github.com/census-instrumentation/opencensus-php"
14+
}
15+
]
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
</whitelist>
12+
</filter>
13+
</phpunit>

tests/integration/curl/test.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -e
4+
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+
14+
pushd $(dirname ${BASH_SOURCE[0]})
15+
16+
sed -i "s|dev-master|dev-${BRANCH}|" composer.json
17+
sed -i "s|https://github.com/census-instrumentation/opencensus-php|${REPO}|" composer.json
18+
composer install -n --prefer-dist
19+
20+
vendor/bin/phpunit
21+
22+
popd
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright 2018 OpenCensus Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace OpenCensus\Tests\Integration\Trace;
19+
20+
use OpenCensus\Trace\Tracer;
21+
use OpenCensus\Trace\Exporter\ExporterInterface;
22+
use OpenCensus\Trace\Integrations\Curl;
23+
use PHPUnit\Framework\TestCase;
24+
25+
/**
26+
* @group trace
27+
*/
28+
class CurlTest extends TestCase
29+
{
30+
public static function setUpBeforeClass()
31+
{
32+
Curl::load();
33+
}
34+
35+
public function setUp()
36+
{
37+
if (!extension_loaded('opencensus')) {
38+
$this->markTestSkipped('Please enable the opencensus extension.');
39+
}
40+
opencensus_trace_clear();
41+
}
42+
43+
public function testCurlExec()
44+
{
45+
$url = 'https://www.google.com/';
46+
47+
$exporter = $this->prophesize(ExporterInterface::class);
48+
$tracer = Tracer::start($exporter->reveal(), [
49+
'skipReporting' => true
50+
]);
51+
$ch = curl_init($url);
52+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
53+
$output = curl_exec($ch);
54+
curl_close($ch);
55+
$this->assertNotEmpty($output);
56+
$tracer->onExit();
57+
58+
$spans = $tracer->tracer()->spans();
59+
$this->assertCount(2, $spans);
60+
61+
$curlSpan = $spans[1];
62+
$this->assertEquals('curl_exec', $curlSpan->name());
63+
$this->assertEquals($url, $curlSpan->attributes()['uri']);
64+
}
65+
}
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+
"guzzlehttp/guzzle": "^5.0",
6+
"ext-opencensus": "*"
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
</whitelist>
12+
</filter>
13+
</phpunit>

tests/integration/guzzle5/test.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -e
4+
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+
14+
pushd $(dirname ${BASH_SOURCE[0]})
15+
16+
sed -i "s|dev-master|dev-${BRANCH}|" composer.json
17+
sed -i "s|https://github.com/census-instrumentation/opencensus-php|${REPO}|" composer.json
18+
composer install -n --prefer-dist
19+
20+
vendor/bin/phpunit
21+
22+
popd

0 commit comments

Comments
 (0)