XBackBone/tests/TestCase.php

33 lines
1.2 KiB
PHP
Raw Normal View History

2020-04-14 22:08:51 +00:00
<?php
namespace Tests;
2020-04-14 22:08:51 +00:00
use PHPUnit\Framework\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
2020-10-01 16:08:35 +00:00
use WithApplication;
2020-04-14 22:08:51 +00:00
protected function setUp()
{
2020-10-01 16:08:35 +00:00
parent::setUp();
$_SESSION = []; // ugly workaround to the the session superglobal between tests
$this->createApplication();
2020-09-28 16:20:25 +00:00
}
2020-10-03 14:01:00 +00:00
public function updateSetting($key, $value = null)
{
if (!$this->database()->query('SELECT `value` FROM `settings` WHERE `key` = '.$this->database()->getPdo()->quote($key))->fetch()) {
$this->database()->query('INSERT INTO `settings`(`key`, `value`) VALUES ('.$this->database()->getPdo()->quote($key).', ?)', $value);
} else {
$this->database()->query('UPDATE `settings` SET `value`=? WHERE `key` = '.$this->database()->getPdo()->quote($key), $value);
}
}
public function createAdminUser($email = 'admin@example.com', $username = 'admin', $password = 'admin')
{
$this->database()->query("INSERT INTO `users` (`email`, `username`, `password`, `is_admin`, `user_code`) VALUES (?, ?, ?, 1, ?)", [$email, $username, password_hash($password, PASSWORD_DEFAULT), humanRandomString(5)]);
return $this->database()->getPdo()->lastInsertId();
}
}