Skip to content
This repository was archived by the owner on Sep 6, 2019. It is now read-only.

Commit 3c6ad10

Browse files
committed
added tests for logging
1 parent 293396d commit 3c6ad10

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
sudo: false
21
language: php
32

43
php:
54
- 5.4
65
- 5.5
76
- 5.6
7+
- 7.0
88
- hhvm
99

10+
matrix:
11+
allow_failures:
12+
- php: 7.0
13+
14+
sudo: false
15+
1016
before_script:
1117
- travis_retry composer self-update
1218
- travis_retry composer install --no-interaction --prefer-source --dev

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "4.*",
21-
"mockery/mockery": "0.9.*"
21+
"mockery/mockery": "0.9.*",
22+
"monolog/monolog": "1.*"
2223
},
2324
"autoload": {
2425
"psr-4": {

src/RequesterServiceProvider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public function boot()
2525
return $app['requester'];
2626
};
2727

28-
if ($this->app->config->get('requester::log.enabled')) {
29-
$logger = $this->app->log->getMonolog();
28+
if ($this->app['config']->get('requester::log.enabled')) {
29+
$logger = $this->app['log']->getMonolog();
3030

31-
if (!empty($this->app->config->get('requester::log.file'))) {
32-
$logger->pushHandler(new StreamHandler($this->app->config->get('requester::log.file'), Logger::INFO));
31+
if (!empty($this->app['config']->get('requester::log.file'))) {
32+
$logger->pushHandler(new StreamHandler($this->app['config']->get('requester::log.file'), Logger::INFO));
3333
}
3434

35-
$this->app['requester']->addLogger($logger, $this->app->config->get('requester::log.format'));
35+
$this->app['requester']->addLogger($logger, $this->app['config']->get('requester::log.format'));
3636
}
3737
}
3838

@@ -43,10 +43,10 @@ public function boot()
4343
*/
4444
public function register()
4545
{
46-
$this->app->config->package('pulkitjalan/requester', realpath(__DIR__.'/config'), 'requester');
46+
$this->app['config']->package('pulkitjalan/requester', realpath(__DIR__.'/config'), 'requester');
4747

4848
$this->app['requester'] = $this->app->share(function ($app) {
49-
return new Requester(new GuzzleClient(), $config = $app->config->get('requester::config'));
49+
return new Requester(new GuzzleClient(), $config = $app['config']->get('requester::config'));
5050
});
5151
}
5252

tests/RequesterTest.php

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function tearDown()
1818
Mockery::close();
1919
}
2020

21-
public function testUrlGetter()
21+
public function test_url_getter()
2222
{
2323
$this->requester->url('example.com');
2424

@@ -33,19 +33,19 @@ public function testUrlGetter()
3333
$this->assertEquals('git://example.com', $this->requester->getUrl());
3434
}
3535

36-
public function testInvalidUrlException()
36+
public function test_invalid_url_exception()
3737
{
3838
$this->setExpectedException('PulkitJalan\Requester\Exceptions\InvalidUrlException');
3939

4040
$this->requester->getUrl();
4141
}
4242

43-
public function testGuzzleGetter()
43+
public function test_guzzle_getter()
4444
{
4545
$this->assertInstanceOf('GuzzleHttp\Client', $this->requester->getGuzzleClient());
4646
}
4747

48-
public function testDisablingSslVerification()
48+
public function test_disabling_ssl_verification()
4949
{
5050
$this->guzzle->shouldReceive('get')->once()->with('https://example.com', [
5151
'verify' => false,
@@ -54,7 +54,7 @@ public function testDisablingSslVerification()
5454
$this->requester->url('example.com')->verify(false)->get();
5555
}
5656

57-
public function testSettingAsync()
57+
public function test_setting_async()
5858
{
5959
$this->guzzle->shouldReceive('get')->once()->with('https://example.com', [
6060
'verify' => true,
@@ -64,7 +64,7 @@ public function testSettingAsync()
6464
$this->requester->url('example.com')->async(true)->get();
6565
}
6666

67-
public function testSettingAndAddingHeaders()
67+
public function test_setting_and_adding_headers()
6868
{
6969
$this->requester->headers(['Authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==']);
7070

@@ -84,7 +84,7 @@ public function testSettingAndAddingHeaders()
8484
], $this->readAttribute($this->requester, 'options'));
8585
}
8686

87-
public function testAddingFileToRequest()
87+
public function test_adding_file_to_request()
8888
{
8989
$this->requester->addFile(__FILE__);
9090

@@ -97,7 +97,7 @@ public function testAddingFileToRequest()
9797
$this->assertInternalType('resource', $this->readAttribute($this->requester, 'options')['body']['image']);
9898
}
9999

100-
public function testChangingRetryOptions()
100+
public function test_changing_retry_options()
101101
{
102102
$this->requester->retry(10);
103103

@@ -116,7 +116,22 @@ public function testChangingRetryOptions()
116116
$this->assertEquals(false, $this->readAttribute($this->requester, 'retry'));
117117
}
118118

119-
public function testSendingGetRequest()
119+
public function test_adding_logger()
120+
{
121+
$monolog = new \Monolog\Logger('name');
122+
$handler = Mockery::mock('Monolog\Handler\NullHandler')->makePartial();
123+
$monolog->pushHandler($handler);
124+
125+
$requester = new \PulkitJalan\Requester\Requester(new \GuzzleHttp\Client());
126+
127+
$requester->addLogger($monolog);
128+
129+
$handler->shouldReceive('handle')->once();
130+
131+
$requester->url('example.com')->get();
132+
}
133+
134+
public function test_sending_get_request()
120135
{
121136
$this->guzzle->shouldReceive('get')->once()->with('https://example.com', [
122137
'verify' => true,
@@ -125,7 +140,7 @@ public function testSendingGetRequest()
125140
$this->requester->url('example.com')->get();
126141
}
127142

128-
public function testSendingHeadRequest()
143+
public function test_sending_head_request()
129144
{
130145
$this->guzzle->shouldReceive('head')->once()->with('https://example.com', [
131146
'verify' => true,
@@ -134,7 +149,7 @@ public function testSendingHeadRequest()
134149
$this->requester->url('example.com')->head();
135150
}
136151

137-
public function testSendingOptionsRequest()
152+
public function test_sending_options_request()
138153
{
139154
$this->guzzle->shouldReceive('options')->once()->with('https://example.com', [
140155
'verify' => true,
@@ -143,7 +158,7 @@ public function testSendingOptionsRequest()
143158
$this->requester->url('example.com')->options();
144159
}
145160

146-
public function testSendingPostRequest()
161+
public function test_sending_post_request()
147162
{
148163
$this->guzzle->shouldReceive('post')->once()->with('https://example.com', [
149164
'verify' => true,
@@ -159,7 +174,7 @@ public function testSendingPostRequest()
159174
]);
160175
}
161176

162-
public function testSendingPutRequest()
177+
public function test_sending_put_request()
163178
{
164179
$this->guzzle->shouldReceive('put')->once()->with('https://example.com', [
165180
'verify' => true,
@@ -175,7 +190,7 @@ public function testSendingPutRequest()
175190
]);
176191
}
177192

178-
public function testSendingPatchRequest()
193+
public function test_sending_patch_request()
179194
{
180195
$this->guzzle->shouldReceive('patch')->once()->with('https://example.com', [
181196
'verify' => true,
@@ -191,7 +206,7 @@ public function testSendingPatchRequest()
191206
]);
192207
}
193208

194-
public function testSendingDeleteRequest()
209+
public function test_sending_delete_request()
195210
{
196211
$this->guzzle->shouldReceive('delete')->once()->with('https://example.com', [
197212
'verify' => true,

0 commit comments

Comments
 (0)