1
0

ControllerWithDbTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use PrivateBin\Data\Database;
  3. require_once 'ControllerTest.php';
  4. class ControllerWithDbTest extends ControllerTest
  5. {
  6. private $_options = array(
  7. 'usr' => null,
  8. 'pwd' => null,
  9. 'opt' => array(
  10. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  11. PDO::ATTR_PERSISTENT => true,
  12. ),
  13. );
  14. public function setUp()
  15. {
  16. /* Setup Routine */
  17. $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
  18. if (!is_dir($this->_path)) {
  19. mkdir($this->_path);
  20. }
  21. $this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3';
  22. $this->_model = Database::getInstance($this->_options);
  23. $this->reset();
  24. }
  25. public function reset()
  26. {
  27. parent::reset();
  28. // but then inject a db config
  29. $options = parse_ini_file(CONF, true);
  30. $options['model'] = array(
  31. 'class' => 'Database',
  32. );
  33. $options['model_options'] = $this->_options;
  34. Helper::createIniFile(CONF, $options);
  35. }
  36. }