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

Add Integration tests #181

Merged
merged 10 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,81 @@ jobs:
RUN_EXTENSION_TESTS: 1
SUDO_CMD: ""

integration:
docker:
- image: circleci/php:7.2-node
- image: memcached
- image: mysql:5.7
environment:
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_DATABASE: mysqldb
MYSQL_RANDOM_ROOT_PASSWORD: yes
steps:
- checkout
- run:
name: Install build tools
command: |
sudo apt-get update -y
sudo apt-get install -y -q --no-install-recommends \
build-essential \
g++ \
gcc \
libc-dev \
make \
autoconf \
git \
unzip
- run:
name: Install opencensus extension
command: |
cd ext
phpize
./configure --enable-opencensus
sudo make install
sudo docker-php-ext-enable opencensus
- run:
name: Install memcached extension
command: |
sudo apt-get install -y -q --no-install-recommends \
libmemcached11 libmemcached-dev zlib1g-dev zlib1g
sudo pecl install memcached <<<''
sudo docker-php-ext-enable memcached
- run:
name: Install pdo_mysql extension
command: sudo docker-php-ext-install pdo_mysql
- run:
name: Install mysqli extension
command: sudo docker-php-ext-install mysqli
- run:
name: Curl test
command: tests/integration/curl/test.sh
- run:
name: Guzzle 5 test
command: tests/integration/guzzle5/test.sh
- run:
name: Guzzle 6 test
command: tests/integration/guzzle6/test.sh
- run:
name: Laravel test
command: tests/integration/laravel/test.sh
- run:
name: Memcached test
command: tests/integration/memcached/test.sh
- run:
name: Symfony 4 test
command: tests/integration/symfony4/test.sh
environment:
DATABASE_URL: mysql://mysql:[email protected]:3306/mysqldb
- run:
name: Wordpress test
command: tests/integration/wordpress/test.sh
environment:
DB_HOST: 127.0.0.1
DB_USERNAME: mysql
DB_PASSWORD: mysql
DB_DATABASE: mysqldb

workflows:
version: 2
units:
Expand All @@ -168,3 +243,4 @@ workflows:
- php70-32bit
- php71-32bit
- php71-debug
- integration
5 changes: 1 addition & 4 deletions src/Trace/Integrations/Eloquent.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ public static function load()
});

// public function delete()
opencensus_trace_method(Model::class, 'delete', function ($model, $query) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was broken and caught by integration tests - there is no parameter for query.

opencensus_trace_method(Model::class, 'delete', function ($model) {
return [
'name' => 'eloquent/delete',
'attributes' => [
'query' => $query->toBase()->toSql()
],
'kind' => Span::KIND_CLIENT
];
});
Expand Down
2 changes: 1 addition & 1 deletion src/Trace/Integrations/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function load()
opencensus_trace_method('Memcached', 'add', [self::class, 'handleAttributes']);

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

// bool Memcached::append ( string $key , string $value )
opencensus_trace_method('Memcached', 'append', [self::class, 'handleAttributes']);
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/curl/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"require": {
"php": "^7.2",
"opencensus/opencensus": "dev-master",
"ext-opencensus": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/census-instrumentation/opencensus-php"
}
]
}
13 changes: 13 additions & 0 deletions tests/integration/curl/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php" colors="true">
<testsuites>
<testsuite>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
22 changes: 22 additions & 0 deletions tests/integration/curl/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

if [ -z "${CIRCLE_PR_NUMBER}" ]; then
BRANCH="master"
REPO="https://github.com/census-instrumentation/opencensus-php"
else
PR_INFO=$(curl "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}")
BRANCH=$(echo $PR_INFO | jq -r .head.ref)
REPO=$(echo $PR_INFO | jq -r .head.repo.html_url)
fi

pushd $(dirname ${BASH_SOURCE[0]})

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

vendor/bin/phpunit

popd
65 changes: 65 additions & 0 deletions tests/integration/curl/tests/CurlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright 2018 OpenCensus Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace OpenCensus\Tests\Integration\Trace;

use OpenCensus\Trace\Tracer;
use OpenCensus\Trace\Exporter\ExporterInterface;
use OpenCensus\Trace\Integrations\Curl;
use PHPUnit\Framework\TestCase;

/**
* @group trace
*/
class CurlTest extends TestCase
{
public static function setUpBeforeClass()
{
Curl::load();
}

public function setUp()
{
if (!extension_loaded('opencensus')) {
$this->markTestSkipped('Please enable the opencensus extension.');
}
opencensus_trace_clear();
}

public function testCurlExec()
{
$url = 'https://www.google.com/';

$exporter = $this->prophesize(ExporterInterface::class);
$tracer = Tracer::start($exporter->reveal(), [
'skipReporting' => true
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$this->assertNotEmpty($output);
$tracer->onExit();

$spans = $tracer->tracer()->spans();
$this->assertCount(2, $spans);

$curlSpan = $spans[1];
$this->assertEquals('curl_exec', $curlSpan->name());
$this->assertEquals($url, $curlSpan->attributes()['uri']);
}
}
17 changes: 17 additions & 0 deletions tests/integration/guzzle5/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"require": {
"php": "^7.2",
"opencensus/opencensus": "dev-master",
"guzzlehttp/guzzle": "^5.0",
"ext-opencensus": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/census-instrumentation/opencensus-php"
}
]
}
13 changes: 13 additions & 0 deletions tests/integration/guzzle5/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php" colors="true">
<testsuites>
<testsuite>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
22 changes: 22 additions & 0 deletions tests/integration/guzzle5/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

if [ -z "${CIRCLE_PR_NUMBER}" ]; then
BRANCH="master"
REPO="https://github.com/census-instrumentation/opencensus-php"
else
PR_INFO=$(curl "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}")
BRANCH=$(echo $PR_INFO | jq -r .head.ref)
REPO=$(echo $PR_INFO | jq -r .head.repo.html_url)
fi

pushd $(dirname ${BASH_SOURCE[0]})

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

vendor/bin/phpunit

popd
55 changes: 55 additions & 0 deletions tests/integration/guzzle5/tests/Guzzle5Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright 2018 OpenCensus Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace OpenCensus\Tests\Integration\Trace;

use GuzzleHttp\Client;
use OpenCensus\Trace\Tracer;
use OpenCensus\Trace\Exporter\ExporterInterface;
use OpenCensus\Trace\Integrations\Guzzle\EventSubscriber;
use PHPUnit\Framework\TestCase;

/**
* @group trace
*/
class Guzzle5Test extends TestCase
{
public function testGuzzleRequest()
{
$client = new Client();
$subscriber = new EventSubscriber();
$client->getEmitter()->attach($subscriber);

$url = 'http://www.google.com/';
$exporter = $this->prophesize(ExporterInterface::class);
$tracer = Tracer::start($exporter->reveal(), [
'skipReporting' => true
]);
$response = $client->get($url);
$this->assertEquals(200, $response->getStatusCode());

$tracer->onExit();

$spans = $tracer->tracer()->spans();
$this->assertCount(2, $spans);

$curlSpan = $spans[1];
$this->assertEquals('GuzzleHttp::request', $curlSpan->name());
$this->assertEquals('GET', $curlSpan->attributes()['method']);
$this->assertEquals($url, $curlSpan->attributes()['uri']);
}
}
17 changes: 17 additions & 0 deletions tests/integration/guzzle6/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"require": {
"php": "^7.2",
"opencensus/opencensus": "dev-master",
"guzzlehttp/guzzle": "^6.0",
"ext-opencensus": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/census-instrumentation/opencensus-php"
}
]
}
13 changes: 13 additions & 0 deletions tests/integration/guzzle6/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php" colors="true">
<testsuites>
<testsuite>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
22 changes: 22 additions & 0 deletions tests/integration/guzzle6/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

if [ -z "${CIRCLE_PR_NUMBER}" ]; then
BRANCH="master"
REPO="https://github.com/census-instrumentation/opencensus-php"
else
PR_INFO=$(curl "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}")
BRANCH=$(echo $PR_INFO | jq -r .head.ref)
REPO=$(echo $PR_INFO | jq -r .head.repo.html_url)
fi

pushd $(dirname ${BASH_SOURCE[0]})

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

vendor/bin/phpunit

popd
Loading