Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on Guzzle and restore PHP 5.4 support #15

Merged
merged 1 commit into from
May 19, 2016
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# `dev-master` (2.x-dev)

* [#15](https://github.com/atoum/reports-extension/pull/15) Remove dependency on Guzzle and restore PHP 5.4 support ([@jubianchi])
* [#14](https://github.com/atoum/reports-extension/pull/14) Add Atom, PHPStorm and Vim to telemetry environments ([@jubianchi])

# 2.2.0 - 2015-05-12
Expand Down
21 changes: 0 additions & 21 deletions autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,8 @@
->addNamespaceAlias('atoum\reports', __NAMESPACE__)
->addDirectory(__NAMESPACE__, __DIR__ . DIRECTORY_SEPARATOR . 'classes')
->addDirectory('Symfony\Component\Filesystem', $filesystemDir)
->addDirectory('GuzzleHttp', $vendorDir . DIRECTORY_SEPARATOR . 'guzzlehttp' . DIRECTORY_SEPARATOR . 'guzzle' . DIRECTORY_SEPARATOR . 'src')
->addDirectory('GuzzleHttp\Promise', $vendorDir . DIRECTORY_SEPARATOR . 'guzzlehttp' . DIRECTORY_SEPARATOR . 'promises' . DIRECTORY_SEPARATOR . 'src')
->addDirectory('GuzzleHttp\Psr7', $vendorDir . DIRECTORY_SEPARATOR . 'guzzlehttp' . DIRECTORY_SEPARATOR . 'psr7' . DIRECTORY_SEPARATOR . 'src')
->addDirectory('Psr\Http\Message', $vendorDir . DIRECTORY_SEPARATOR . 'psr' . DIRECTORY_SEPARATOR . 'http-message' . DIRECTORY_SEPARATOR . 'src')
;

require_once $vendorDir . DIRECTORY_SEPARATOR . 'guzzlehttp' . DIRECTORY_SEPARATOR . 'guzzle' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'functions_include.php';

$promisesAutoloader = $vendorDir . DIRECTORY_SEPARATOR . 'guzzlehttp' . DIRECTORY_SEPARATOR . 'promises' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'functions_include.php';
if (is_file($promisesAutoloader) === false)
{
$promisesAutoloader = $vendorDir . DIRECTORY_SEPARATOR . 'guzzlehttp' . DIRECTORY_SEPARATOR . 'promises' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'functions.php';
}

$psr7Autoloader = $vendorDir . DIRECTORY_SEPARATOR . 'guzzlehttp' . DIRECTORY_SEPARATOR . 'psr7' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'functions_include.php';
if (is_file($psr7Autoloader) === false)
{
$psr7Autoloader = $vendorDir . DIRECTORY_SEPARATOR . 'guzzlehttp' . DIRECTORY_SEPARATOR . 'psr7' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'functions.php';
}

require_once $promisesAutoloader;
require_once $psr7Autoloader;

require_once $vendorDir . DIRECTORY_SEPARATOR . 'twig' . DIRECTORY_SEPARATOR . 'twig' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'Twig' . DIRECTORY_SEPARATOR . 'Autoloader.php';

$twigAutoloader = new \Twig_Autoloader();
Expand Down
16 changes: 10 additions & 6 deletions classes/telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class telemetry extends asynchronous
{
const defaultUrl = 'https://telemetry.atoum.org';

protected $client;
protected $http;
protected $score;
protected $testClassNumber = 0;
protected $testMethodNumber = 0;
Expand All @@ -23,12 +23,12 @@ class telemetry extends asynchronous
protected $telemetryUrl;
protected $reportIsDisabled;

public function __construct(Client $client = null)
public function __construct(atoum\writers\http $http = null)
{
parent::__construct();

$this->setTelemetryUrl();
$this->client = $client ?: new Client();
$this->http = $http ?: new atoum\writers\http();
}

public function setTelemetryUrl($url = null)
Expand Down Expand Up @@ -186,13 +186,17 @@ public function build($event)

try
{
$this->client->request('POST', $this->telemetryUrl, ['body' => json_encode($report)]);
$this->http
->setUrl($this->telemetryUrl)
->setMethod('POST')
->write(json_encode($report))
;

$this->string = 'Your report has been sent to the telemetry. Thanks for sharing it with us!';
}
catch(RequestException $exception)
catch(atoum\writers\http\exception $exception)
{
$this->string = 'Unable to send your report to the telemetry: HTTP ' . $exception->getCode();
$this->string = 'Unable to send your report to the telemetry.';
}

$this->string .= PHP_EOL;
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
}
],
"require": {
"php": ">=5.5.0",
"php": ">=5.4.0",
"twig/twig": "^1.18",
"symfony/filesystem": "^2.6 | ^3.0",
"guzzlehttp/guzzle": "^6.2"
"symfony/filesystem": "^2.6 | ^3.0"
},
"require-dev": {
"atoum/atoum": "^2.5.1"
Expand Down
90 changes: 46 additions & 44 deletions tests/units/classes/telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,45 @@ public function testSetTelemetryUrl()
{
$this
->given(
$client = new \mock\GuzzleHttp\Client(),
$this->calling($client)->request->doesNothing,
$http = new \mock\mageekguy\atoum\writers\http(),
$this->calling($http)->write->doesNothing,
$runner = new \mock\mageekguy\atoum\runner(),
$telemetry = $this->newTestedInstance($client)
$telemetry = $this->newTestedInstance($http)
)
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl)->once
->mock($http)
->call('setUrl')->withArguments(testedClass::defaultUrl)->once
->call('setMethod')->withArguments('POST')->once
->call('write')->once
->if(
$this->resetMock($http),
$url = uniqid(),
$this->testedInstance->setTelemetryUrl($url)
)
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->mock($client)->call('request')->withArguments('POST', $url)->once
->mock($http)
->call('setUrl')->withArguments($url)->once
->call('setMethod')->withArguments('POST')->once
->call('write')->once
;
}

public function testSetProjectName()
{
$this
->given(
$client = new \mock\GuzzleHttp\Client(),
$this->calling($client)->request->doesNothing,
$http = new \mock\mageekguy\atoum\writers\http(),
$this->calling($http)->write->doesNothing,
$runner = new \mock\mageekguy\atoum\runner(),
$telemetry = $this->newTestedInstance($client),
$telemetry = $this->newTestedInstance($http),
$this->function->getenv = false
)
->if($this->function->uniqid = 'anon/' . ($project = uniqid()))
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -88,15 +95,15 @@ public function testSetProjectName()
'duration' => 0,
'memory' => 0
]
])])->once
]))->once
->if(
$vendor = uniqid(),
$project = uniqid(),
$this->testedInstance->setProjectName($vendor . '/' . $project)
)
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -125,14 +132,14 @@ public function testSetProjectName()
'duration' => 0,
'memory' => 0
]
])])->once
]))->once
->if(
$this->function->uniqid = 'anon/' . ($project = uniqid()),
$this->testedInstance->sendAnonymousReport()
)
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -161,7 +168,7 @@ public function testSetProjectName()
'duration' => 0,
'memory' => 0
]
])])->once
]))->once
->exception(function($test) {
$test->testedInstance->setProjectName(uniqid());
}
Expand All @@ -175,10 +182,10 @@ public function testSendAnonymousProjectName()
{
$this
->given(
$client = new \mock\GuzzleHttp\Client(),
$this->calling($client)->request->doesNothing,
$http = new \mock\mageekguy\atoum\writers\http(),
$this->calling($http)->write->doesNothing,
$runner = new \mock\mageekguy\atoum\runner(),
$telemetry = $this->newTestedInstance($client),
$telemetry = $this->newTestedInstance($http),
$this->function->getenv = false
)
->if(
Expand All @@ -187,7 +194,7 @@ public function testSendAnonymousProjectName()
)
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -216,18 +223,18 @@ public function testSendAnonymousProjectName()
'duration' => 0,
'memory' => 0
]
])])->once
]))->once
;
}

public function testHandleEvent()
{
$this
->given(
$client = new \mock\GuzzleHttp\Client(),
$this->calling($client)->request->doesNothing,
$http = new \mock\mageekguy\atoum\writers\http(),
$this->calling($http)->write->doesNothing,
$runner = new \mock\mageekguy\atoum\runner(),
$telemetry = $this->newTestedInstance($client),
$telemetry = $this->newTestedInstance($http),
$this->function->getenv = false
)
->if($this->function->uniqid = 'anon/' . ($project = uniqid()))
Expand All @@ -236,7 +243,7 @@ public function testHandleEvent()
$this->testedInstance->handleEvent(atoum\runner::runStop, $runner)
)
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -265,13 +272,13 @@ public function testHandleEvent()
'duration' => 0,
'memory' => 0
]
])])->once
]))->once
->when(
$this->testedInstance->handleEvent(atoum\test::beforeTestMethod, $runner),
$this->testedInstance->handleEvent(atoum\runner::runStop, $runner)
)
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -300,13 +307,13 @@ public function testHandleEvent()
'duration' => 0,
'memory' => 0
]
])])->once
]))->once
->when(
$this->testedInstance->handleEvent(atoum\test::beforeTestMethod, $runner),
$this->testedInstance->handleEvent(atoum\runner::runStop, $runner)
)
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -335,14 +342,14 @@ public function testHandleEvent()
'duration' => 0,
'memory' => 0
]
])])->once
]))->once
->when(
$this->testedInstance->handleEvent(atoum\test::runStart, $runner),
$this->testedInstance->handleEvent(atoum\test::beforeTestMethod, $runner),
$this->testedInstance->handleEvent(atoum\runner::runStop, $runner)
)
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -371,7 +378,7 @@ public function testHandleEvent()
'duration' => 0,
'memory' => 0
]
])])->once
]))->once
->given(
$score = new atoum\runner\score(),
$coverage = new \mock\mageekguy\atoum\score\coverage(),
Expand All @@ -381,7 +388,7 @@ public function testHandleEvent()
->if($runner->setScore($score))
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -413,14 +420,14 @@ public function testHandleEvent()
'lines' => $coverageValue
]
]
])])->once
]))->once
->given(
$this->calling($coverage)->getBranchesCoverageValue = $branchesCoverageValue = rand(0, 100),
$this->calling($coverage)->getPathsCoverageValue = $pathsCoverageValue = rand(0, 100)
)
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->mock($client)->call('request')->withArguments('POST', testedClass::defaultUrl, ['body' => json_encode([
->mock($http)->call('write')->withArguments(json_encode([
'php' => null,
'atoum' => null,
'os' => php_uname('s') . ' ' . php_uname('r'),
Expand Down Expand Up @@ -454,18 +461,13 @@ public function testHandleEvent()
'paths' => $pathsCoverageValue
]
]
])])->once
->given(
$request = new \mock\Psr\Http\Message\RequestInterface(),
$response = new \mock\Psr\Http\Message\ResponseInterface(),
$this->calling($response)->getStatusCode = $code = rand(400, 599),
$exception = new \mock\GuzzleHttp\Exception\RequestException(uniqid(), $request, $response)
)
->if($this->calling($client)->request->throw = $exception)
]))->once
->given($exception = new \mageekguy\atoum\writers\http\exception())
->if($this->calling($http)->write->throw = $exception)
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->castToString($this->testedInstance)->isEqualTo('Unable to send your report to the telemetry: HTTP ' . $code . PHP_EOL)
->if($this->calling($client)->request->doesNothing)
->castToString($this->testedInstance)->isEqualTo('Unable to send your report to the telemetry.' . PHP_EOL)
->if($this->calling($http)->write->doesNothing)
->when($this->testedInstance->handleEvent(atoum\runner::runStop, $runner))
->then
->castToString($this->testedInstance)->isEqualTo('Your report has been sent to the telemetry. Thanks for sharing it with us!' . PHP_EOL)
Expand Down