-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.php
59 lines (45 loc) · 2.09 KB
/
Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require '../../vendor/autoload.php';
use Controllers\Account;
use PHPUnit\Framework\TestCase;
class AccountTests extends TestCase
{
protected $account;
protected function setUp() : void {
$this->account = new Account();
}
public function testPasswordSetting() {
$password = 'examplePassword';
$this->account->setPassword($password);
$this->assertSame($password, $this->account->getPassword());
}
public function testAccountRegistrationWithValidData() {
$this->account->setPassword('secure123');
$this->account->username = 'newUser';
$this->account->email = '[email protected]';
$registrationErrors = $this->account->registerAccount();
$this->assertEmpty($registrationErrors, "Registration should not produce errors");
}
public function testUserValidations() {
$this->account->setPassword('secure123');
$this->account->username = 'newUser';
$validationErrors = $this->account->validateAccount();
$this->assertEmpty($validationErrors, "Validation should pass without errors");
}
public function testUserRetrieval() {
$username = 'existingUser';
$userData = $this->account->getUser($username);
$this->assertIsArray($userData, "User data should be returned as an array");
}
}
$testSuite = new AccountTests('Account Test Suite');
$results = [];
$testSuite->setUp();
$results[] = ["Test 1 (Set Password)", $testSuite->testPasswordSetting() ? "passed" : "failed"];
$results[] = ["Test 2 (Account Registration)", $testSuite->testAccountRegistrationWithValidData() ? "passed" : "failed"];
$results[] = ["Test 3 (User Validation)", $testSuite->testUserValidations() ? "passed" : "failed"];
$results[] = ["Test 4 (User Retrieval)", $testSuite->testUserRetrieval() ? "passed" : "failed"];
echo "<h1>Account Class Tests</h1>";
foreach ($results as $test) {
echo "<div style='width: 300px; display: flex; justify-content: space-between;'><span>{$test[0]}</span><span>{$test[1]}</span></div><br>";
}