Skip to content

Commit

Permalink
Remove dependency on Guzzle and restore PHP 5.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jubianchi committed May 19, 2016
1 parent 7af90b2 commit 43b58bb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 2.2.0 - 2015-05-12

* [#15](https://github.com/atoum/reports-extension/pull/15) Remove dependency on Guzzle and restore PHP 5.4 support ([@jubianchi])
* [#11](https://github.com/atoum/reports-extension/pull/11) Anonymize only project name ([@jubianchi])
* [#3](https://github.com/atoum/reports-extension/pull/3) Add xUnit and clover reports for Sonar ([@vonglasow])
* [#10](https://github.com/atoum/reports-extension/pull/10) Add continuousphp to CI environments ([@ppaulis])
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 @@ -22,12 +22,12 @@ class telemetry extends asynchronous
protected $projectName;
protected $telemetryUrl;

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 @@ -163,13 +163,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
80 changes: 41 additions & 39 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,18 +378,13 @@ public function testHandleEvent()
'duration' => 0,
'memory' => 0
]
])])->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

0 comments on commit 43b58bb

Please sign in to comment.