public function testOnTerminate() { $track_clear_cache = true; $this->keeper->expects($this->once())->method('set')->with(Keeper::LAST_UPDATE_KEY, $this->isInstanceOf(\DateTime::class)); $this->event->expects($this->once())->method('getCommand')->will($this->returnValue($this->command)); $this->command->expects($this->once())->method('getName')->will($this->returnValue('cache:clear')); $listener = new ConsoleListener($this->keeper, $track_clear_cache); $listener->onTerminate($this->event); }
/** * @param LifecycleEventArgs $args * @param bool $remove */ protected function update(LifecycleEventArgs $args, $remove) { $alias = $this->builder->getEntityAlias($args->getEntity()); $this->keeper->set($alias, new \DateTime()); if ($this->track_individually_entity) { $ids = $this->builder->getEntityIdentifier($args->getEntity()); if ($ids !== null) { if ($remove) { $this->keeper->remove($alias . $ids); } else { $this->keeper->set($alias . $ids, new \DateTime()); } } } }
public function testExecute() { /** @var $input \PHPUnit_Framework_MockObject_MockObject|InputInterface */ $input = $this->getMock(InputInterface::class); /** @var $output \PHPUnit_Framework_MockObject_MockObject|OutputInterface */ $output = $this->getMock(OutputInterface::class); $output->expects($this->once())->method('writeln')->with('Reset last update date of the project is complete.'); $this->keeper->expects($this->once())->method('set')->will($this->returnCallback(function ($key, $time) { $this->assertEquals(Keeper::LAST_UPDATE_KEY, $key); $this->assertInstanceOf(\DateTime::class, $time); $this->assertTrue($time >= new \DateTime('-1 second')); return true; })); $this->command->run($input, $output); }
/** * @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); }
public function testGetModifiedResponse() { $this->driver->expects($this->once())->method('getMax')->with(['foo', Keeper::LAST_UPDATE_KEY])->will($this->returnValue($this->time)); /** @var $request \PHPUnit_Framework_MockObject_MockObject|Request */ $request = $this->getMock(Request::class); /** @var $response \PHPUnit_Framework_MockObject_MockObject|Response */ $response = $this->getMock(Response::class); /** @var $configured_response \PHPUnit_Framework_MockObject_MockObject|Response */ $configured_response = $this->getMock(Response::class); $configured_response->expects($this->once())->method('isNotModified')->with($request)->will($this->returnValue(true)); $configured_response->expects($this->atLeastOnce())->method('getStatusCode')->will($this->returnValue(Response::HTTP_NOT_MODIFIED)); $this->configurator->expects($this->once())->method('configure')->with($response, $this->time)->will($this->returnValue($configured_response)); try { $this->keeper->getModifiedResponse($request, 'foo', -1, $response); $this->assertTrue(false, 'Must throw exception'); } catch (NotModifiedException $e) { $this->assertEquals($configured_response, $e->getResponse()); $this->assertEquals(Response::HTTP_NOT_MODIFIED, $e->getCode()); $this->assertEquals(Response::$statusTexts[Response::HTTP_NOT_MODIFIED], $e->getMessage()); } }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int|null */ protected function execute(InputInterface $input, OutputInterface $output) { $this->keeper->set(Keeper::LAST_UPDATE_KEY, new \DateTime()); $output->writeln('Reset last update date of the project is complete.'); }
/** * @param ConsoleTerminateEvent $event */ public function onTerminate(ConsoleTerminateEvent $event) { if ($this->track_clear_cache && $event->getCommand()->getName() == 'cache:clear') { $this->keeper->set(Keeper::LAST_UPDATE_KEY, new \DateTime()); } }