Skip to content

Commit 651ec51

Browse files
committed
adds tests
1 parent 1b98253 commit 651ec51

File tree

8 files changed

+234
-0
lines changed

8 files changed

+234
-0
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ script:
7373
- composer install
7474
- phpunit
7575
- popd
76+
# run appengine logging tests
77+
- pushd appengine/standard/logging
78+
- composer install
79+
- phpunit
80+
- popd
7681
# run modules tests
7782
- pushd appengine/standard/modules
7883
- if [ ${TRAVIS_PHP_VERSION} == '5.5' ]; then composer install; fi;

appengine/standard/logging/index.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
2+
/**
3+
* Copyright 2015 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
217

318
require __DIR__ . '/vendor/autoload.php';
419

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
xml version="1.0" encoding="UTF-8"?>
2+
17+
<phpunit bootstrap="test/bootstrap.php">
18+
<testsuites>
19+
<testsuite name="AppEngine logging test">
20+
<directory>testdirectory>
21+
testsuite>
22+
testsuites>
23+
<logging>
24+
<log type="coverage-clover" target="../../../build/logs/clover-gae-logging.xml"/>
25+
logging>
26+
<filter>
27+
<whitelist>
28+
<file>index.phpfile>
29+
whitelist>
30+
filter>
31+
phpunit>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
require_once __DIR__ . '/mocks/AppLogLine.php';
5+
require_once __DIR__ . '/mocks/LogService.php';
6+
require_once __DIR__ . '/mocks/RequestLog.php';
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
/**
3+
* Copyright 2015 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
use google\appengine\api\log\LogService;
19+
20+
class loggingTest extends PHPUnit_Framework_TestCase
21+
{
22+
public function testNoLogs()
23+
{
24+
ob_start();
25+
include __DIR__ . '/../index.php';
26+
$result = ob_get_contents();
27+
ob_end_clean();
28+
// Make sure it looks like Shakespeare.
29+
$this->assertContains('No logs!', $result);
30+
}
31+
32+
public function testSomeLogs()
33+
{
34+
$log1 = $this->getMock('google\appengine\api\log\RequestLog');
35+
$applog1 = $this->getMock('google\appengine\api\log\AppLogLine');
36+
$expectedLog = [
37+
[ 'method' => 'getIp', 'return' => '127.0.0.1' ],
38+
[ 'method' => 'getStatus', 'return' => 'log-status-1' ],
39+
[ 'method' => 'getMethod', 'return' => 'log-method-1' ],
40+
[ 'method' => 'getResource', 'return' => 'log-resource-1' ],
41+
[ 'method' => 'getEndDateTime', 'return' => $d1 = new DateTime() ],
42+
[ 'method' => 'getAppLogs', 'return' => [ $applog1 ] ],
43+
];
44+
$expectedAppLog = [
45+
[ 'method' => 'getMessage', 'return' => 'applog-message-1' ],
46+
[ 'method' => 'getDateTime', 'return' => $d2 = new DateTime('-1 hour') ],
47+
];
48+
foreach ($expectedLog as $expected) {
49+
$log1->expects($this->once())
50+
->method($expected['method'])
51+
->will($this->returnValue($expected['return']));
52+
}
53+
foreach ($expectedAppLog as $expected) {
54+
$applog1->expects($this->once())
55+
->method($expected['method'])
56+
->will($this->returnValue($expected['return']));
57+
}
58+
59+
LogService::$logs = [ $log1 ];
60+
ob_start();
61+
include __DIR__ . '/../index.php';
62+
$result = ob_get_contents();
63+
ob_end_clean();
64+
// Make sure it looks like Shakespeare.
65+
$this->assertContains('127.0.0.1', $result);
66+
$this->assertContains('log-status-1', $result);
67+
$this->assertContains('log-method-1', $result);
68+
$this->assertContains('log-resource-1', $result);
69+
$this->assertContains($d1->format('c'), $result);
70+
$this->assertContains('applog-message-1', $result);
71+
$this->assertContains($d2->format('c'), $result);
72+
}
73+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
/**
3+
* Copyright 2015 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace google\appengine\api\log;
19+
20+
class AppLogLine
21+
{
22+
public function getMessage()
23+
{
24+
}
25+
26+
public function getDateTime()
27+
{
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
/**
3+
* Copyright 2015 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace google\appengine\api\log;
19+
20+
class LogService
21+
{
22+
const LEVEL_INFO = 0;
23+
24+
public static $logs = [];
25+
26+
public static function fetch($options)
27+
{
28+
return self::$logs;
29+
}
30+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
/**
3+
* Copyright 2015 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace google\appengine\api\log;
19+
20+
class RequestLog
21+
{
22+
public function getIp()
23+
{
24+
}
25+
26+
public function getStatus()
27+
{
28+
}
29+
30+
public function getMethod()
31+
{
32+
}
33+
34+
public function getResource()
35+
{
36+
}
37+
38+
public function getEndDateTime()
39+
{
40+
}
41+
42+
public function getAppLogs()
43+
{
44+
}
45+
}

0 commit comments

Comments
 (0)