Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3KB

  1. <?php
  2. /**
  3. * DatabaseTest class.
  4. */
  5. namespace Friendica\Test;
  6. use dba;
  7. use Friendica\Database\DBStructure;
  8. use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
  9. use PHPUnit\DbUnit\DataSet\YamlDataSet;
  10. use PHPUnit\DbUnit\TestCaseTrait;
  11. use PHPUnit\Framework\TestCase;
  12. use PDO;
  13. /**
  14. * Abstract class used by tests that need a database.
  15. */
  16. abstract class DatabaseTest extends TestCase
  17. {
  18. use TestCaseTrait;
  19. /**
  20. * Get database connection.
  21. * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
  22. * @see https://phpunit.de/manual/5.7/en/database.html
  23. */
  24. protected function getConnection()
  25. {
  26. if (!dba::$connected) {
  27. dba::connect('localhost', getenv('USER'), getenv('PASS'), getenv('DB'));
  28. if (dba::$connected) {
  29. $app = get_app();
  30. // We need to do this in order to disable logging
  31. $app->module = 'install';
  32. // Create database structure
  33. DBStructure::update(false, true, true);
  34. } else {
  35. $this->markTestSkipped('Could not connect to the database.');
  36. }
  37. }
  38. return $this->createDefaultDBConnection(dba::get_db(), 'friendica_test:');
  39. }
  40. /**
  41. * Get dataset to populate the database with.
  42. * @return YamlDataSet
  43. * @see https://phpunit.de/manual/5.7/en/database.html
  44. */
  45. protected function getDataSet()
  46. {
  47. return new YamlDataSet(
  48. __DIR__.'/datasets/api.yml'
  49. );
  50. }
  51. }