/** * @expectedException \RuntimeException */ public function testGetCallThrowsExceptionAndStillTriggersProfiler() { $this->profiler->expects($this->once())->method('start')->will($this->returnValue(new Benchmark('test'))); $this->profiler->expects($this->once())->method('stop')->will($this->returnValue(new Benchmark('test'))); $this->container->expects($this->once())->method('get')->will($this->throwException(new \RuntimeException())); $instance = $this->adapter->get('sample-id'); }
/** * @covers Fabfuel\Prophiler\Decorator\Elasticsearch\ClientDecorator::__call */ public function testCall() { $payload = ['lorem' => 'ipsum']; $benchmark = $this->getMock('Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface'); $this->client->expects($this->once())->method('get')->with($payload); $this->profiler->expects($this->once())->method('start')->with('ElasticMock::get', [$payload], 'Elasticsearch')->willReturn($benchmark); $this->profiler->expects($this->once())->method('stop')->with($benchmark); $this->decorator->get($payload); }
/** * @covers Fabfuel\Prophiler\Toolbar\Formatter\TimelineFormatter::getOffset * @covers Fabfuel\Prophiler\Toolbar\Formatter\TimelineFormatter::getProfilerDuration * @uses Fabfuel\Prophiler\Toolbar\Formatter\TimelineFormatter * @uses Fabfuel\Prophiler\Toolbar\Formatter\BenchmarkFormatterAbstract */ public function testGetOffset() { $startTimeBenchmark = 100000; $startTimeProfiler = 100050; $durationProfiler = 100; $this->benchmark->expects($this->any())->method('getStartTime')->willReturn($startTimeBenchmark); $this->profiler->expects($this->any())->method('getStartTime')->willReturn($startTimeProfiler); $this->profiler->expects($this->any())->method('getDuration')->willReturn($durationProfiler); $offset = $startTimeBenchmark - $startTimeProfiler; $expectedOffset = number_format($offset / ($durationProfiler * TimelineFormatter::TIMEBUFFER_FACTOR) * 100, 2, '.', ''); $this->assertSame($expectedOffset, $this->formatter->getOffset()); }
/** * @param string $method * @param array $params * @covers Fabfuel\Prophiler\Decorator\Phalcon\Cache\BackendDecorator * @dataProvider gatewayMethods */ public function testCallGatewayMethods($method, array $params) { $benchmark = $this->getMock('Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface'); $methodMock = $this->backend->expects($this->once())->method($method); call_user_func_array([$methodMock, 'with'], $params); $this->profiler->expects($this->once())->method('start')->with('CacheMock::' . $method, $params, 'Cache CacheMock')->willReturn($benchmark); $this->profiler->expects($this->once())->method('stop')->with($benchmark); call_user_func_array([$this->decorator, $method], $params); }
/** * @covers Fabfuel\Prophiler\Decorator\PDO\PDO::prepare * @uses Fabfuel\Prophiler\Decorator\PDO\PDO * @uses Fabfuel\Prophiler\Decorator\PDO\PDOStatement */ public function testPrepareInvalidStatement() { $query = 'SELECT * FROM users;'; $options = ['foo' => 'bar']; $benchmark = $this->getMock('Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface'); $this->profiler->expects($this->once())->method('start')->with('PDO::prepare', ['statement' => $query], 'Database')->willReturn($benchmark); $this->profiler->expects($this->once())->method('stop')->with($benchmark); $this->pdo->expects($this->once())->method('prepare')->with($query, $options)->willReturn(false); $statement = $this->decorator->prepare($query, $options); $this->assertFalse($statement); }
/** * @covers Fabfuel\Prophiler\Decorator\PDO\PDOStatement::execute * @covers Fabfuel\Prophiler\Decorator\PDO\PDOStatement::bindParam * @uses Fabfuel\Prophiler\Decorator\PDO\PDOStatement */ public function testExecute() { $lorem = 'ipsum'; $inputParameters = ['foo' => 'bar']; $boundParameters = ['lorem' => $lorem]; $metadata = ['input parameters' => $inputParameters, 'bound parameters' => $boundParameters, 'query' => null]; $benchmark = $this->getMock('Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface'); $this->profiler->expects($this->once())->method('start')->with('PDOStatement::execute', $metadata, 'Database')->willReturn($benchmark); $this->profiler->expects($this->once())->method('stop')->with($benchmark); $this->pdoStatement->expects($this->once())->method('execute')->with($inputParameters)->willReturn(true); $this->decorator->bindParam('lorem', $lorem); $result = $this->decorator->execute($inputParameters); $this->assertTrue($result); }
/** * @covers Fabfuel\Prophiler\Adapter\Psr\Log\Logger::debug * @covers Fabfuel\Prophiler\Adapter\Psr\Log\Logger::log * @uses Fabfuel\Prophiler\Adapter\AdapterAbstract */ public function testDebug() { $this->profiler->expects($this->once())->method('start')->with('Lorem Ipsum', ['foo' => 'bar', 'severity' => 'debug'], 'Logger'); $this->logger->debug('Lorem Ipsum', ['foo' => 'bar']); }