ControllerWithDbTest.php 1.1 KB

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