Skip to content

Commit

Permalink
turn off log request when no debug
Browse files Browse the repository at this point in the history
  • Loading branch information
imsamurai committed Dec 18, 2014
1 parent 48ac271 commit 90ccd4f
Showing 1 changed file with 219 additions and 3 deletions.
222 changes: 219 additions & 3 deletions Test/Case/Model/Datasource/HttpSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ public function requestFlowProvider() {
/**
* Test single request
*
* @param int $debug
* @param array $request
* @param array $requestFull
* @param array $response
Expand All @@ -585,7 +586,8 @@ public function requestFlowProvider() {
* @param HttpSourceEndpoint $Endpoint
* @dataProvider singleRequestProvider
*/
public function testSingleRequest($request, $requestFull, $response, $responseResult, $asModel, $requestMethod, array $config, array $connectionData, $log, $Endpoint = null) {
public function testSingleRequest($debug, $request, $requestFull, $response, $responseResult, $asModel, $requestMethod, array $config, array $connectionData, $log, $Endpoint = null) {
Configure::write('debug', $debug);
$Connection = $this->getMockBuilder('HttpSourceConnection')
->setMethods(array(
'request',
Expand Down Expand Up @@ -625,11 +627,13 @@ public function testSingleRequest($request, $requestFull, $response, $responseRe
->setConstructorArgs(array(array('datasource' => 'HttpSource.Http/HttpSource') + $config, $Connection))
->setMethods($sourceMethods)
->getMock();
$Source->expects($this->once())->method('logRequest');
if ($debug > 1) {
$Source->expects($this->once())->method('logRequest');
}
$Source->expects($this->once())->method('swapTokens')->with($requestFull);
$Source->expects($this->once())->method('beforeRequest')->with($requestFull, $requestMethod)->will($this->returnArgument(0));

if ($connectionData['error']) {
if ($debug < 2 && $connectionData['error']) {
$Source->expects($this->once())->method('log')->with($log, LOG_ERR);
}

Expand Down Expand Up @@ -676,6 +680,8 @@ public function singleRequestProvider() {
return array(
//set #0
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -709,6 +715,8 @@ public function singleRequestProvider() {
),
//set #1
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -753,6 +761,8 @@ public function singleRequestProvider() {
),
//set #2
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -786,6 +796,8 @@ public function singleRequestProvider() {
),
//set #3
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -830,6 +842,8 @@ public function singleRequestProvider() {
),
//set #4
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -874,6 +888,8 @@ public function singleRequestProvider() {
),
//set #5
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -918,6 +934,8 @@ public function singleRequestProvider() {
),
//set #6
array(
//debug
2,
//request
array(
'lol',
Expand Down Expand Up @@ -967,6 +985,8 @@ public function singleRequestProvider() {
),
//set #7
array(
//debug
2,
//request
array(
'lol',
Expand Down Expand Up @@ -1016,6 +1036,8 @@ public function singleRequestProvider() {
),
//set #8
array(
//debug
2,
//request
array(
'lol',
Expand Down Expand Up @@ -1066,6 +1088,8 @@ public function singleRequestProvider() {
),
//set #9
array(
//debug
2,
//request
array(
'lol',
Expand Down Expand Up @@ -1116,6 +1140,8 @@ public function singleRequestProvider() {
),
//set #10
array(
//debug
2,
//request
array(
'lol',
Expand Down Expand Up @@ -1166,6 +1192,8 @@ public function singleRequestProvider() {
),
//set #11
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -1199,6 +1227,8 @@ public function singleRequestProvider() {
),
//set #12
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -1231,6 +1261,8 @@ public function singleRequestProvider() {
),
//set #13
array(
//debug
2,
//request
array(
'lol'
Expand Down Expand Up @@ -1268,6 +1300,138 @@ public function singleRequestProvider() {
),
//set #14
array(
//debug
2,
//request
array(
'lol'
),
//requestFull
array(
'lol'
),
//response
array('hello dolly'),
//responseResult
array('hello dolly'),
//asModel
true,
//requestMethod
HttpSource::METHOD_CHECK,
//config
array(),
//connectionData
array(
'error' => '',
'took' => 10,
'query' => 'GET somethong',
'affected' => 1,
),
//log,
'',
//Endpoint
$CF->endpoint()
->result($CF->result()
->map(function($result) {
return array_merge($result, array('Hi Jack!'));
})
)
),
//set #15
array(
//debug
0,
//request
array(
'lol'
),
//requestFull
array(
'lol'
),
//response
array('hello dolly'),
//responseResult
array('hello dolly'),
//asModel
true,
//requestMethod
HttpSource::METHOD_CHECK,
//config
array(),
//connectionData
array(
'error' => '',
'took' => 10,
'query' => 'GET somethong',
'affected' => 1,
),
//log,
'',
//Endpoint
$CF->endpoint()
->result($CF->result()
->map(function($result) {
return array_merge($result, array('Hi Jack!'));
})
)
),
//set #16
array(
//debug
0,
//request
array(
'lol',
'uri' => array(
'host' => 'example2.com',
'port' => 2880,
'path' => '/api2',
'scheme' => 'https'
)
),
//requestFull
array(
'lol',
'uri' => array(
'host' => 'example2.com',
'port' => 2880,
'path' => '/api2',
'scheme' => 'https'
)
),
//response
array(),
//responseResult
array(),
//asModel
false,
//requestMethod
HttpSource::METHOD_CHECK,
//config
array(
'path' => '/api',
'scheme' => 'http',
'port' => 7880,
'host' => 'example.com'
),
//connectionData
array(
'error' => 'oh crap!',
'took' => 10,
'query' => 'GET somethong',
'affected' => 1,
'numRows' => 0
),
//log,
'HttpSource: oh crap! Request: GET somethong',
//Endpoint
null
),
//set #17
array(
//debug
1,
//request
array(
'lol'
Expand Down Expand Up @@ -1303,6 +1467,58 @@ public function singleRequestProvider() {
})
)
),
//set #18
array(
//debug
1,
//request
array(
'lol',
'uri' => array(
'host' => 'example2.com',
'port' => 2880,
'path' => '/api2',
'scheme' => 'https'
)
),
//requestFull
array(
'lol',
'uri' => array(
'host' => 'example2.com',
'port' => 2880,
'path' => '/api2',
'scheme' => 'https'
)
),
//response
array(),
//responseResult
array(),
//asModel
false,
//requestMethod
HttpSource::METHOD_CHECK,
//config
array(
'path' => '/api',
'scheme' => 'http',
'port' => 7880,
'host' => 'example.com'
),
//connectionData
array(
'error' => 'oh crap!',
'took' => 10,
'query' => 'GET somethong',
'affected' => 1,
'numRows' => 0
),
//log,
'HttpSource: oh crap! Request: GET somethong',
//Endpoint
null
),
);
}

Expand Down

0 comments on commit 90ccd4f

Please sign in to comment.