Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

issue.global_function_call

Edson Medina edited this page Jul 7, 2017 · 6 revisions

Global function call

class foo
{
    public function bar ($x) 
    {
        $x = validate($x);

        // ...
    }
}

function validate ($x)
{
    // ...
}

Why is this a testing issue?

Global function calls can't be replaced in run-time, so there's no way of testing the code in isolation.

Possible refactorings

Write the function as a method

class foo
{
    public function bar ($x) 
    {
        $x = $this->validate($x);

        // ...
    }

    public function validate ($val)
    {
        // ...
    }
}
Clone this wiki locally