/** * @dataProvider getConfigureParams * * @param Response $response * @param Request $request * @param int $lifetime * @param array $private_headers * @param bool $expected_public */ public function testConfigure(Response $response, Request $request, $lifetime, array $private_headers, $expected_public) { $last_modified = new \DateTime(); if ($response->getEtag()) { $etag = $response->getEtag(); } else { $etag = md5('bar'); $this->key_builder->expects($this->once())->method('getEtag')->with($response)->will($this->returnValue($etag)); $etag = '"' . $etag . '"'; } $this->request_stack->expects($this->once())->method('getMasterRequest')->will($this->returnValue($request)); $expires = null; if ($lifetime >= 0) { $expires = clone $last_modified; $expires->modify(sprintf('now +%s seconds', $lifetime)); } $configurator = new ResponseConfigurator($this->key_builder, $this->request_stack, $private_headers); // exec test method $configured_response = $configurator->configure($response, $last_modified, $lifetime); $this->assertEquals($response, $configured_response); $this->assertEquals($last_modified, $response->getLastModified()); $this->assertEquals($etag, $response->getEtag()); $this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate')); $this->assertTrue($response->headers->hasCacheControlDirective($expected_public ? 'public' : 'private')); if ($lifetime >= 0) { $this->assertEquals($lifetime, $response->headers->getCacheControlDirective('max-age')); $this->assertEquals($expires, $response->getExpires()); if ($expected_public) { $this->assertEquals($lifetime, $response->headers->getCacheControlDirective('s-maxage')); } } }
/** * @dataProvider getTrackMethods * * @param string $method * @param bool $track_individually * @param bool $remove * @param array $ids */ public function testHandleEvent($method, $track_individually, $remove, array $ids) { $alias = 'foo'; $this->keeper->expects($this->at(0))->method('set')->with($alias, $this->isInstanceOf('DateTime')); $this->builder->expects($this->once())->method('getEntityAlias')->with($this->entity)->will($this->returnValue($alias)); if ($track_individually) { $suffix = implode(',', $ids); $this->builder->expects($this->once())->method('getEntityIdentifier')->with($this->entity)->will($this->returnValue($suffix)); if ($suffix) { if ($remove) { $this->keeper->expects($this->once())->method('remove')->with($alias . $suffix); } else { $this->keeper->expects($this->at(1))->method('set')->with($alias . $suffix, $this->isInstanceOf('DateTime')); } } } else { $this->builder->expects($this->never())->method('getEntityIdentifier'); } $listener = new DoctrineListener($this->keeper, $this->builder, $track_individually); call_user_func([$listener, $method], $this->args); }