I am new to PHPUnit, and I am currently trying to test a function that authenticates a user on the system. The function is called authenticate()
and is located inside the Account
class.
Test
public function passwordAreNotTheSame_Test()
{
require 'login/app/models/Account.php';
require 'login/app/controllers/Pages.php';
require 'login/lib/Controller.php';
$pages = new Pages();
$account = new Account($pages);
$username = "test_name";
$password = "test_password";
$cpassword = "invalid_password";
$email = "email@test.com";
$Expected = "Passwords do not match!";
$Received = $account->register($username, $password, $cpassword, $email);
$this->assertEquals($Expected, $Received);
}
However, my issue is that the constructor in the Account
class also requires a controller called Pages
. My issue is that the class Pages,
located in the file Pages.php
extends the class Controller
. Like this:
class Pages extends Controller {
// some code
}
So when I run my test, I get the following issue.
Error: Class "Controller" not found C:\xampp\htdocs\apex-management\login\app\controllers\Pages.php:3 C:\xampp\htdocs\apex-management\tests\Unit\RegisterAccountTests.php:13 Time: 00:00.019, Memory: 8.00 MB
ERRORS: Tests, 1: Assertions, 0: Errors. 1. Process finished with exit code 2
How could I make this test work? I want to learn how to use PHPUnit, but I've found no documentation online for that type of issue.
In php oop, it is supporing 'extends' keyword. Here is the example for that
<?php
class parent{
//parent class definition
}
class child extends parent{
//child class declarations
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.