protected function assertResultSetResponse(Response $response) { $this->assertEquals(200, $response->getCode(), $response->getBody()); $result = Json::decode($response->getBody()); $this->assertEquals(true, isset($result['totalResults']), $response->getBody()); $this->assertEquals(true, isset($result['startIndex']), $response->getBody()); $this->assertEquals(true, isset($result['itemsPerPage']), $response->getBody()); $tblActivity = getContainer()->get('handlerManager')->getTable('AmunService\\User\\Activity')->getName(); $tblAccount = getContainer()->get('handlerManager')->getTable('AmunService\\User\\Account')->getName(); $count = $this->sql->getField('SELECT COUNT(*) FROM ' . $tblActivity . ' INNER JOIN ' . $tblAccount . ' ON ' . $tblActivity . '.userId = ' . $tblAccount . '.id'); $this->assertEquals($count, $result['totalResults']); }
public function testCacheHit() { $request = new Request(new Url('http://localhost.com/foo/bar'), 'GET'); $response = new Response(); $response->setBody(new StringStream()); $filters = array(); $filters[] = function ($request, $response, $filterChain) { $response->getBody()->write('foobar'); $filterChain->handle($request, $response); }; $filterChain = new FilterChain($filters); $filterChain->handle($request, $response); $cache = new Cache(new CacheHandler\Memory()); $item = $cache->getItem(md5('/foo/bar')); $item->set(array('headers' => array('Last-Modified' => 'Sat, 27 Dec 2014 15:54:49 GMT', 'Content-Type' => 'text/plain'), 'body' => 'foobar')); $cache->save($item); $filter = new StaticCache($cache); $filter->handle($request, $response, $filterChain); $result = $cache->getItem(md5('/foo/bar'))->get(); $this->assertArrayHasKey('headers', $result); $this->assertArrayHasKey('Content-Type', $result['headers']); $this->assertEquals('text/plain', $result['headers']['Content-Type']); $this->assertArrayHasKey('Last-Modified', $result['headers']); $this->assertEquals('Sat, 27 Dec 2014 15:54:49 GMT', $result['headers']['Last-Modified']); $this->assertArrayHasKey('body', $result); $this->assertEquals('foobar', $result['body']); }
protected function assertNegativeResponse(Response $response) { //$this->assertEquals(200, $response->getCode(), $response->getBody()); $resp = Json::decode($response->getBody()); $this->assertEquals(true, isset($resp['text']), $response->getBody()); $this->assertEquals(true, isset($resp['success']), $response->getBody()); $this->assertEquals(false, $resp['success'], $response->getBody()); }