ControllerWithDbTest.php 1.3 KB

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