public function testNextIncrement()
{
$nextIncField = array('type' => 'hidden', 'options' => array('label' => false), 'event' => array('name' => 'next_increment', 'params' => array('table' => 'koalas', 'column' => 'gum_leaves', 'min' => 42)));
$app = $this->getApp(false);
$this->getExtension($app)->config['csrf'] = false;
$this->getExtension($app)->config['testing_form']['fields']['next_inc'] = $nextIncField;
$app['request'] = Request::create('/');
$boltforms = new BoltForms($app);
$boltforms->makeForm('testing_form');
$fields = $this->formValues();
$fields['next_inc'] = $nextIncField;
$boltforms->addFieldArray('testing_form', $fields);
$parameters = array('testing_form' => array('name' => 'Gawain Lynch', 'email' => '*****@*****.**', 'message' => 'Hello'));
$app['request'] = Request::create('/', 'POST', $parameters);
$app->boot();
// Mock the database query
$mocker = new DoctrineMockBuilder();
$db = $mocker->getConnectionMock();
$queries = array();
$db->expects($this->any())->method('executeQuery')->will($this->returnCallback(function ($query, $params) use(&$queries, $mocker) {
$queries[] = $query;
return $mocker->getStatementMock();
}));
$db->expects($this->any())->method('fetchColumn')->with($this->equalTo('koalas'))->willReturn(55);
$app['db'] = $db;
// Mock Bolt\Users
$users = $this->getMock('\\Bolt\\Users', array('getUsers'), array($app));
$users->expects($this->any())->method('getUsers')->willReturn(array('id' => 1));
$app['users'] = $users;
$result = $boltforms->processRequest('testing_form', array('success' => true), true);
$this->assertEquals('SELECT MAX(gum_leaves) as max FROM koalas', $queries[0]);
$this->assertArrayHasKey('next_inc', $result);
$this->assertSame(42, $result['next_inc']);
}