Skip to content

Commit 8a91e91

Browse files
Merge pull request GoogleCloudPlatform#109 from GoogleCloudPlatform/mockMemcached
Mock memcached and test locally.
2 parents 004c538 + 56338b2 commit 8a91e91

File tree

4 files changed

+184
-3
lines changed

4 files changed

+184
-3
lines changed

appengine/flexible/memcache/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"require": {
33
"silex/silex": "^1.3",
4-
"twig/twig": "^1.24"
4+
"twig/twig": "^1.24",
5+
"gecko-packages/gecko-memcache-mock": "^2.0"
56
},
67
"require-dev": {
78
"phpunit/phpunit": "~4",

appengine/flexible/memcache/composer.lock

Lines changed: 90 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

appengine/flexible/memcache/phpunit.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@
55
<directory>testsdirectory>
66
testsuite>
77
testsuites>
8+
<logging>
9+
<log type="coverage-clover" target="build/logs/clover.xml"/>
10+
logging>
11+
<filter>
12+
<whitelist>
13+
<file>app.phpfile>
14+
whitelist>
15+
filter>
816
phpunit>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
/**
3+
* Copyright 2016 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+
*/
17+
namespace Google\Cloud\Test;
18+
19+
use Silex\WebTestCase;
20+
use GeckoPackages\MemcacheMock\MemcachedMock;
21+
22+
class LocalTest extends WebTestCase
23+
{
24+
public function setUp()
25+
{
26+
parent::setUp();
27+
$this->client = $this->createClient();
28+
}
29+
30+
public function createApplication()
31+
{
32+
$app = require __DIR__ . '/../app.php';
33+
$app['memcached'] = new MemcachedMock;
34+
$app['memcached']->addServer("localhost", 11211);
35+
return $app;
36+
}
37+
38+
public function testIndex()
39+
{
40+
// Access the modules app top page.
41+
$client = $this->client;
42+
$client->request('GET', '/');
43+
$this->assertTrue($client->getResponse()->isOk());
44+
45+
// Make sure it handles a POST request too, which will increment the
46+
// counter.
47+
$this->client->request('POST', '/');
48+
$this->assertTrue($this->client->getResponse()->isOk());
49+
}
50+
51+
public function testGetAndPut()
52+
{
53+
// Use a random key to avoid colliding with simultaneous tests.
54+
$key = rand(0, 1000);
55+
56+
// Test the /memcached REST API.
57+
$this->put("/memcached/test$key", "sour");
58+
$this->assertEquals("sour", $this->get("/memcached/test$key"));
59+
$this->put("/memcached/test$key", "sweet");
60+
$this->assertEquals("sweet", $this->get("/memcached/test$key"));
61+
}
62+
63+
/**
64+
* HTTP PUTs the body to the url path.
65+
* @param $path string
66+
* @param $body string
67+
*/
68+
private function put($path, $body)
69+
{
70+
$this->client->request('PUT', $path, array(), array(), array(), $body);
71+
return $this->client->getResponse()->getContent();
72+
}
73+
74+
/**
75+
* HTTP GETs the url path.
76+
* @param $path string
77+
* @return string The HTTP Response.
78+
*/
79+
private function get($path)
80+
{
81+
$this->client->request('GET', $path);
82+
return $this->client->getResponse()->getContent();
83+
}
84+
}

0 commit comments

Comments
 (0)