/** * @expectedException PHPUnit_Framework_Error_Warning */ public function testGcWithException() { $key1 = new Key('projectid'); $key1->pathElement(self::KIND, 'sessionid1'); $key2 = new Key('projectid'); $key2->pathElement(self::KIND, 'sessionid2'); $entity1 = new Entity($key1); $entity2 = new Entity($key2); $query = $this->prophesize(Query::class); $query->kind(self::KIND)->shouldBeCalledTimes(1)->willReturn($query->reveal()); $that = $this; $query->filter(Argument::type('string'), Argument::type('string'), Argument::type('int'))->shouldBeCalledTimes(1)->will(function ($args) use($that, $query) { $that->assertEquals('t', $args[0]); $that->assertEquals('<', $args[1]); $that->assertInternalType('int', $args[2]); $diff = time() - $args[2]; // 2 seconds grace period should be enough $that->assertTrue($diff <= 102); $that->assertTrue($diff >= 100); return $query->reveal(); }); $query->order('t')->shouldBeCalledTimes(1)->willReturn($query->reveal()); $query->keysOnly()->shouldBeCalledTimes(1)->willReturn($query->reveal()); $query->limit(1000)->shouldBeCalledTimes(1)->willReturn($query->reveal()); $this->datastore->transaction()->shouldBeCalledTimes(1)->willReturn($this->transaction->reveal()); $this->datastore->query()->shouldBeCalledTimes(1)->willReturn($query->reveal()); $this->datastore->runQuery(Argument::type(Query::class), Argument::type('array'))->shouldBeCalledTimes(1)->will(function ($args) use($that, $query, $entity1, $entity2) { $that->assertEquals($query->reveal(), $args[0]); $that->assertEquals(['namespaceId' => self::NAMESPACE_ID], $args[1]); return [$entity1, $entity2]; }); $this->datastore->deleteBatch([$key1, $key2])->shouldBeCalledTimes(1)->willThrow(new Exception()); $datastoreSessionHandler = new DatastoreSessionHandler($this->datastore->reveal(), 1000); $datastoreSessionHandler->open(self::NAMESPACE_ID, self::KIND); $ret = $datastoreSessionHandler->gc(100); $this->assertEquals(false, $ret); }