S
S
sqiiiiiizy942021-03-23 15:38:24
PHP
sqiiiiiizy94, 2021-03-23 15:38:24

How to test an HTTP request?

Hello, I can't find the answer to this seemingly simple question anywhere.
Started learning testing (Outside Laravel\Symfony, pure php) but can't figure out how to test the request.
For example, there is a class:

class Test
{
    public function __construct()
    {
        //
    }

    public function function()
    {
        if ($_SERVER['REQUEST_METHOD'] == 'GET') {
            include 'testhtml.php';
        } else {
            return $this->newFunc($_POST['login'], $_POST['password']);
        }
    }

    public function newFunc($login, $password)
    {
        echo "Ваш логин: $login, пароль: $password";
    }

testhtml.php file:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form method="POST">
        <input type="text" name="login">
        <input type="password" name="password">
        <input type="submit" name="submit">
    </form>
</body>
</html>

How can I test a bunch of these functions in a class so as not to reduce everything to a separate test (stupidly passing not POST\GET requests, but the values ​​themselves)? I just saw a similar functionality in Laravel.
In general, how to properly test WEB projects? I just can't find anything about functional testing at all, only a unit with examples a la "Make a calculator" and check it. Yes, I know about "@depend", but is it really all done like that, stupidly modeling the values ​​themselves (and not the requests), implying that the conditional form will always accurately convey what is asked of it, and the requests are ignored?
Thanks in advance:)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question