PHPUnit stuff.
This commit is contained in:
parent
91dc776e4d
commit
74f1d6e193
30 changed files with 358 additions and 89 deletions
1
.phpunit.cache/test-results
Normal file
1
.phpunit.cache/test-results
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":1,"defects":{"TelegramTest::testSendMessageReturnsArrayOnSuccess":8,"TelegramTest::testSendMessageReturnsFalseOnFailure":8},"times":[]}
|
1
.phpunit.result.cache
Normal file
1
.phpunit.result.cache
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":1,"defects":{"TelegramTest::testSendMessageReturnsArrayOnSuccess":8,"TelegramTest::testSendMessageReturnsFalseOnFailure":8,"DatabaseTest::testConnection":8,"DatabaseTest::testQuery":8,"DJTest::testLoadFromId":8,"DJTest::testLoadFromSlug":8},"times":{"TelegramTest::testSendMessageReturnsArrayOnSuccess":0.001,"TelegramTest::testSendMessageReturnsFalseOnFailure":0.001,"DatabaseTest::testConnection":0.007,"DatabaseTest::testQuery":0.002,"DJTest::testLoadFromId":0.001,"DJTest::testLoadFromSlug":0.001}}
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class CustomCDN
|
||||
{
|
||||
private $space;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class DJ
|
||||
{
|
||||
|
||||
|
@ -16,7 +18,7 @@ class DJ
|
|||
private string $created = "";
|
||||
private string $updated = "";
|
||||
private string $claimed_by = "";
|
||||
private mysqli $db;
|
||||
private $db;
|
||||
private array $mixes = [];
|
||||
|
||||
|
||||
|
@ -128,7 +130,7 @@ class DJ
|
|||
$this->updated = $dj['lastupdated'];
|
||||
}
|
||||
|
||||
$this->load_dj_mixes();
|
||||
$this->load_dj_mixes();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
@ -136,6 +138,22 @@ class DJ
|
|||
}
|
||||
}
|
||||
|
||||
private function load_dj_mixes(): void
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix WHERE dj1 = ? OR dj2 = ? OR dj3 = ?");
|
||||
$stmt->bind_param("iii", $this->id, $this->id, $this->id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$mixes = [];
|
||||
while ($mix = $result->fetch_assoc()) {
|
||||
$mixes[] = $mix;
|
||||
}
|
||||
$stmt->close();
|
||||
$this->mixes = $mixes;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function load_from_slug(): bool
|
||||
{
|
||||
$socials = [];
|
||||
|
@ -209,22 +227,6 @@ class DJ
|
|||
return $this->claimed;
|
||||
}
|
||||
|
||||
private function load_dj_mixes(): void
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM mix WHERE dj1 = ? OR dj2 = ? OR dj3 = ?");
|
||||
$stmt->bind_param("iii", $this->id, $this->id, $this->id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$mixes = [];
|
||||
while ($mix = $result->fetch_assoc()) {
|
||||
$mixes[] = $mix;
|
||||
}
|
||||
$stmt->close();
|
||||
$this->mixes = $mixes;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function get_dj_mixes()
|
||||
{
|
||||
return $this->mixes;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
class DJs
|
||||
{
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
// create a class that extends mysql database
|
||||
use mysqli;
|
||||
|
||||
class Database extends mysqli
|
||||
{
|
||||
// create a constructor that takes in the config file
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Genre
|
||||
{
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Genres
|
||||
{
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Mix
|
||||
{
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Mixshow
|
||||
{
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Mixshows
|
||||
{
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
Class S3 extends Aws\S3\S3Client{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Schema
|
||||
{
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Telegram
|
||||
{
|
||||
private $token = "";
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
class Upload
|
||||
{
|
||||
private $file;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace DJMixHosting;
|
||||
|
||||
use Random\RandomException;
|
||||
|
||||
Class User{
|
||||
|
|
|
@ -16,5 +16,10 @@
|
|||
"ext-mysqli": "*",
|
||||
"ext-curl": "*",
|
||||
"phpunit/phpunit": ">8.5.1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"DJMixHosting\\": "classes/"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use DJMixHosting\Telegram;
|
||||
|
||||
if ($_POST) {
|
||||
$name = $_POST['name'];
|
||||
|
|
7
debug.php
Normal file
7
debug.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
echo "<pre>";
|
||||
// Dump the autoload class map
|
||||
print_r(Composer\Autoload\ClassLoader::getRegisteredLoaders());
|
||||
echo "</pre>";
|
10
dj.php
10
dj.php
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'classes/DJ.php';
|
||||
require_once 'classes/Genre.php';
|
||||
require_once 'classes/Mix.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\DJ;
|
||||
use DJMixHosting\Genre;
|
||||
use DJMixHosting\Mix;
|
||||
|
||||
|
||||
// if there's a query parameter named 'dj', load the DJ class
|
||||
$db = new Database($config);
|
||||
|
|
7
djs.php
7
djs.php
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'classes/DJs.php';
|
||||
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\DJs;
|
||||
|
||||
$db = new Database($config);
|
||||
$djs = new DJs($db);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'classes/Genre.php';
|
||||
require_once 'classes/Mix.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\Genre;
|
||||
use DJMixHosting\Mix;
|
||||
|
||||
$genre = null;
|
||||
$genreFound = false;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'classes/Genres.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\Genres;
|
||||
|
||||
$genresFound = false;
|
||||
// if there's a query parameter named 'dj', load the DJ class
|
||||
|
|
50
login.php
50
login.php
|
@ -1,8 +1,15 @@
|
|||
<?php
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\User;
|
||||
|
||||
$title = $locale['home'];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
|
||||
|
||||
if (isset($_POST['username']) && isset($_POST['password'])) {
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
@ -21,7 +28,8 @@ require_once 'includes/header.php'; ?>
|
|||
<nav aria-label="breadcrumb" class="bg-body-tertiary rounded-3 p-3 mb-4">
|
||||
<ol class="breadcrumb mb-0">
|
||||
<li class="breadcrumb-item"><a href="/"><?php echo $locale['home']; ?></a></li>
|
||||
<li class="breadcrumb-item active"><a href="/login.php"><?php echo $locale['login']; ?></a></li>
|
||||
<li class="breadcrumb-item active"><a href="/login.php"><?php echo $locale['login']; ?></a>
|
||||
</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
|
@ -29,30 +37,30 @@ require_once 'includes/header.php'; ?>
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<div class="container py-5">
|
||||
<div class="row">
|
||||
<div class="col-lg-6 offset-lg-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><?php echo $locale['login']; ?></h5>
|
||||
<form action="login.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label"><?php echo $locale['username']; ?></label>
|
||||
<input type="text" class="form-control" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label"><?php echo $locale['password']; ?></label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><?php echo $locale['login']; ?></button>
|
||||
</form>
|
||||
<section>
|
||||
<div class="container py-5">
|
||||
<div class="row">
|
||||
<div class="col-lg-6 offset-lg-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><?php echo $locale['login']; ?></h5>
|
||||
<form action="login.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label"><?php echo $locale['username']; ?></label>
|
||||
<input type="text" class="form-control" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label"><?php echo $locale['password']; ?></label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><?php echo $locale['login']; ?></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
9
mix.php
9
mix.php
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'classes/Mix.php';
|
||||
require_once 'classes/Mixshow.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\Mix;
|
||||
use DJMixHosting\Mixshow;
|
||||
use DJMixHosting\Genre;
|
||||
|
||||
|
||||
$db = new Database($config);
|
||||
$mixFound = false;
|
||||
|
|
11
mixshow.php
11
mixshow.php
|
@ -1,10 +1,13 @@
|
|||
<?php
|
||||
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'classes/Mixshow.php';
|
||||
require_once 'classes/Genre.php';
|
||||
require_once 'classes/Mix.php';
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\Genre;
|
||||
use DJMixHosting\Mix;
|
||||
use DJMixHosting\Mixshow;
|
||||
|
||||
// if there's a query parameter named 'dj', load the DJ class
|
||||
$db = new Database($config);
|
||||
|
|
62
mixshows.php
62
mixshows.php
|
@ -1,46 +1,48 @@
|
|||
<?php
|
||||
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'classes/Mixshows.php';
|
||||
require_once 'classes/DJs.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\Mixshows;
|
||||
|
||||
$db = new Database($config);
|
||||
$mixshows = new Mixshows($db);
|
||||
$title = $locale['mixshows'];
|
||||
require_once 'includes/header.php';
|
||||
?>
|
||||
<section>
|
||||
<div class="container py-5">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<nav aria-label="breadcrumb" class="bg-body-tertiary rounded-3 p-3 mb-4">
|
||||
<ol class="breadcrumb mb-0">
|
||||
<li class="breadcrumb-item"><a href="/"><?php echo $locale['home']; ?></a></li>
|
||||
<li class="breadcrumb-item active"><a href="/mixshows.php"><?php echo $locale['mixshows']; ?></a>
|
||||
</li>
|
||||
</ol>
|
||||
</nav>
|
||||
<section>
|
||||
<div class="container py-5">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<nav aria-label="breadcrumb" class="bg-body-tertiary rounded-3 p-3 mb-4">
|
||||
<ol class="breadcrumb mb-0">
|
||||
<li class="breadcrumb-item"><a href="/"><?php echo $locale['home']; ?></a></li>
|
||||
<li class="breadcrumb-item active"><a
|
||||
href="/mixshows.php"><?php echo $locale['mixshows']; ?></a>
|
||||
</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
$mixshows = $mixshows->get_nonzero_mixshows();
|
||||
$count = 0;
|
||||
foreach ($mixshows as $mixshow) {
|
||||
card_output($count, $mixshow, $locale);
|
||||
echo '<a href="/mixshow.php?mixshow=' . $mixshow['slug'] . '" class="btn btn-primary">' . $locale['view'] . '</a>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
if ($count % 4 == 3) {
|
||||
$mixshows = $mixshows->get_nonzero_mixshows();
|
||||
$count = 0;
|
||||
foreach ($mixshows as $mixshow) {
|
||||
card_output($count, $mixshow, $locale);
|
||||
echo '<a href="/mixshow.php?mixshow=' . $mixshow['slug'] . '" class="btn btn-primary">' . $locale['view'] . '</a>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
if ($count % 4 == 3) {
|
||||
echo '</div>';
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
<?php require_once 'includes/footer.php'; ?>
|
110
tests/DJTest.php
Normal file
110
tests/DJTest.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use DJMixHosting\DJ;
|
||||
use mysqli;
|
||||
use mysqli_stmt;
|
||||
use mysqli_result;
|
||||
|
||||
class DJTest extends TestCase
|
||||
{
|
||||
private $mockDb;
|
||||
private $mockStmt;
|
||||
private $mockResult;
|
||||
private $dj;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->mockDb = $this->createMock(mysqli::class);
|
||||
$this->mockStmt = $this->createMock(mysqli_stmt::class);
|
||||
$this->mockResult = $this->createMock(mysqli_result::class);
|
||||
}
|
||||
|
||||
public function testLoadFromId()
|
||||
{
|
||||
$djData = [
|
||||
'id' => 1,
|
||||
'name' => 'Test DJ',
|
||||
'bio' => 'This is a test bio',
|
||||
'slug' => 'test-dj',
|
||||
'img' => '/djs/test-dj.png',
|
||||
'email' => 'test@example.com',
|
||||
'facebook_url' => 'http://facebook.com/testdj',
|
||||
'instagram_url' => 'http://instagram.com/testdj',
|
||||
'twitter_url' => 'http://twitter.com/testdj',
|
||||
'active' => 1,
|
||||
'created' => '2021-01-01 00:00:00',
|
||||
'lastupdated' => '2021-01-01 00:00:00',
|
||||
'claimed_by' => null,
|
||||
];
|
||||
|
||||
// Mock the prepared statement and its behavior
|
||||
$this->mockStmt->method('bind_param')->willReturn(true);
|
||||
$this->mockStmt->method('execute')->willReturn(true);
|
||||
$this->mockStmt->method('get_result')->willReturn($this->mockResult);
|
||||
$this->mockResult->method('fetch_assoc')->willReturn($djData);
|
||||
|
||||
// Mock the DB connection to return the mock statement
|
||||
$this->mockDb->method('prepare')->willReturn($this->mockStmt);
|
||||
|
||||
// Instantiate the DJ class with a valid ID and the mocked DB connection
|
||||
$this->dj = new DJ(1, $this->mockDb);
|
||||
|
||||
// Assertions to verify that the DJ object is correctly built
|
||||
$this->assertEquals(1, $this->dj->get_id());
|
||||
$this->assertEquals('Test DJ', $this->dj->get_name());
|
||||
$this->assertEquals('This is a test bio', $this->dj->get_bio());
|
||||
$this->assertEquals('test-dj', $this->dj->get_slug());
|
||||
$this->assertEquals('https://cdn.utahsdjs.com/test-dj.png', $this->dj->get_img());
|
||||
$this->assertEquals('test@example.com', $this->dj->get_email());
|
||||
$this->assertTrue($this->dj->get_active());
|
||||
$this->assertEquals('2021-01-01 00:00:00', $this->dj->get_created());
|
||||
$this->assertEquals('2021-01-01 00:00:00', $this->dj->get_updated());
|
||||
$this->assertFalse($this->dj->get_claimed());
|
||||
}
|
||||
|
||||
public function testLoadFromSlug()
|
||||
{
|
||||
$djData = [
|
||||
'id' => 1,
|
||||
'name' => 'Test DJ',
|
||||
'bio' => 'This is a test bio',
|
||||
'slug' => 'test-dj',
|
||||
'img' => '/djs/test-dj.png',
|
||||
'email' => 'test@example.com',
|
||||
'facebook_url' => 'http://facebook.com/testdj',
|
||||
'instagram_url' => 'http://instagram.com/testdj',
|
||||
'twitter_url' => 'http://twitter.com/testdj',
|
||||
'active' => 1,
|
||||
'created' => '2021-01-01 00:00:00',
|
||||
'lastupdated' => '2021-01-01 00:00:00',
|
||||
'claimed_by' => null,
|
||||
];
|
||||
|
||||
// Mock the prepared statement and its behavior
|
||||
$this->mockStmt->method('bind_param')->willReturn(true);
|
||||
$this->mockStmt->method('execute')->willReturn(true);
|
||||
$this->mockStmt->method('get_result')->willReturn($this->mockResult);
|
||||
$this->mockResult->method('fetch_assoc')->willReturn($djData);
|
||||
|
||||
// Mock the DB connection to return the mock statement
|
||||
$this->mockDb->method('prepare')->willReturn($this->mockStmt);
|
||||
|
||||
// Instantiate the DJ class with a valid slug and the mocked DB connection
|
||||
$this->dj = new DJ('test-dj', $this->mockDb);
|
||||
|
||||
// Assertions to verify that the DJ object is correctly built
|
||||
$this->assertEquals(1, $this->dj->get_id());
|
||||
$this->assertEquals('Test DJ', $this->dj->get_name());
|
||||
$this->assertEquals('This is a test bio', $this->dj->get_bio());
|
||||
$this->assertEquals('test-dj', $this->dj->get_slug());
|
||||
$this->assertEquals('https://cdn.utahsdjs.com/test-dj.png', $this->dj->get_img());
|
||||
$this->assertEquals('test@example.com', $this->dj->get_email());
|
||||
$this->assertTrue($this->dj->get_active());
|
||||
$this->assertEquals('2021-01-01 00:00:00', $this->dj->get_created());
|
||||
$this->assertEquals('2021-01-01 00:00:00', $this->dj->get_updated());
|
||||
$this->assertFalse($this->dj->get_claimed());
|
||||
}
|
||||
}
|
56
tests/DatabaseTest.php
Normal file
56
tests/DatabaseTest.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
require_once '../vendor/autoload.php'; // Adjust the path as needed to include Composer's autoload
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use DJMixHosting\Database;
|
||||
|
||||
class DatabaseTest extends TestCase
|
||||
{
|
||||
private $config;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
// Setup your test database configuration here
|
||||
$this->config = [
|
||||
'database' => [
|
||||
'host' => 'localhost',
|
||||
'user' => 'test_user',
|
||||
'pass' => 'test_password',
|
||||
'db' => 'test_database',
|
||||
'port' => 3306
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function testConnection()
|
||||
{
|
||||
// Create an instance of Database
|
||||
$db = new Database($this->config);
|
||||
|
||||
// Check if the connection is successfully established
|
||||
$this->assertInstanceOf(mysqli::class, $db);
|
||||
$this->assertEquals(0, $db->connect_errno, "Database connection error: " . $db->connect_error);
|
||||
}
|
||||
|
||||
public function testQuery()
|
||||
{
|
||||
// Create an instance of Database
|
||||
$db = new Database($this->config);
|
||||
|
||||
// Execute a simple query
|
||||
$result = $db->query('SELECT 1 AS value');
|
||||
$this->assertNotFalse($result, "Query failed: " . $db->error);
|
||||
|
||||
$row = $result->fetch_assoc();
|
||||
$this->assertEquals(1, $row['value'], "Query did not return the correct value");
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
// Close the database connection if it's still open
|
||||
if (isset($db) && $db instanceof mysqli) {
|
||||
$db->close();
|
||||
}
|
||||
}
|
||||
}
|
36
tests/TelegramTest.php
Normal file
36
tests/TelegramTest.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
use DJMixHosting\Telegram;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TelegramTest extends TestCase
|
||||
{
|
||||
private $telegram;
|
||||
private $token = 'YOUR_BOT_TOKEN';
|
||||
private $chatId = 'YOUR_CHAT_ID';
|
||||
|
||||
public function testSendMessageReturnsArrayOnSuccess()
|
||||
{
|
||||
$expectedResult = json_encode(['ok' => true, 'result' => 'Message sent']);
|
||||
$this->telegram->method('sendMessage')->willReturn($expectedResult);
|
||||
|
||||
$result = $this->telegram->send_message('Hello, world!');
|
||||
$this->assertIsArray($result);
|
||||
$this->assertEquals(['ok' => true, 'result' => 'Message sent'], $result);
|
||||
}
|
||||
|
||||
public function testSendMessageReturnsFalseOnFailure()
|
||||
{
|
||||
$this->telegram->method('sendMessage')->willReturn(false);
|
||||
|
||||
$result = $this->telegram->send_message('Hello, world!');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->telegram = $this->getMockBuilder(Telegram::class)->setConstructorArgs([$this->token, $this->chatId])->onlyMethods(['sendMessage'])->getMock();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue