last of us fan
last of us fan

Reputation: 9

Can I use phpunit tests on functions that are not in class?

I have a small .php file with that one function which I've pasted below. I would like to test that function.

Is there any way of how I can use phpunit? I'm not using composer.json.

<?php public function LoginMe($a, $b) //nick, psw
        {
        require 'includes/mysql_connection.php';
        require 'includes/config.php';
        require 'includes/messages.php';
        require 'backend/LogsSystem.php';

                // Some code

                return false;
        } ?>

Upvotes: 0

Views: 723

Answers (1)

GabrieleMartini
GabrieleMartini

Reputation: 1722

For example, if your script is called authentication.php, this can be a hint for test:

<?php
use PHPUnit\Framework\TestCase;
include 'authentication.php';
class authenticationTest extends TestCase
{
    public function testAuthentication()
    {
    //your test here, call LoginMe with expected parameters
    }
}

You may find interesting this too: PHP Testing, for Procedural Code

Upvotes: 2

Related Questions