Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion appengine/flexible/memcache/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"require": {
"silex/silex": "^1.3",
"twig/twig": "^1.24"
"twig/twig": "^1.24",
"gecko-packages/gecko-memcache-mock": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "~4",
Expand Down
92 changes: 90 additions & 2 deletions appengine/flexible/memcache/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions appengine/flexible/memcache/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<filter>
<whitelist>
<file>app.php</file>
</whitelist>
</filter>
</phpunit>
84 changes: 84 additions & 0 deletions appengine/flexible/memcache/tests/LocalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Google\Cloud\Test;

use Silex\WebTestCase;
use GeckoPackages\MemcacheMock\MemcachedMock;

class LocalTest extends WebTestCase
{
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}

public function createApplication()
{
$app = require __DIR__ . '/../app.php';
$app['memcached'] = new MemcachedMock;
$app['memcached']->addServer("localhost", 11211);
return $app;
}

public function testIndex()
{
// Access the modules app top page.
$client = $this->client;
$client->request('GET', '/');
$this->assertTrue($client->getResponse()->isOk());

// Make sure it handles a POST request too, which will increment the
// counter.
$this->client->request('POST', '/');
$this->assertTrue($this->client->getResponse()->isOk());
}

public function testGetAndPut()
{
// Use a random key to avoid colliding with simultaneous tests.
$key = rand(0, 1000);

// Test the /memcached REST API.
$this->put("/memcached/test$key", "sour");
$this->assertEquals("sour", $this->get("/memcached/test$key"));
$this->put("/memcached/test$key", "sweet");
$this->assertEquals("sweet", $this->get("/memcached/test$key"));
}

/**
* HTTP PUTs the body to the url path.
* @param $path string
* @param $body string
*/
private function put($path, $body)
{
$this->client->request('PUT', $path, array(), array(), array(), $body);
return $this->client->getResponse()->getContent();
}

/**
* HTTP GETs the url path.
* @param $path string
* @return string The HTTP Response.
*/
private function get($path)
{
$this->client->request('GET', $path);
return $this->client->getResponse()->getContent();
}
}