0

Say you have a PHP function getId that calls a function from another class:

public function getFoosForBar(int $bar): array
{
    $helperClass = new HelperClass();
    return $helperClass->getFoos($bar);
}

You, as the smart cookie you are, recognise that $helperClass is an inline variable, and you want to refactor it to:

public function getFoosForBar(int $bar): array
{
    return (new HelperClass)->getFoos($bar);
}

Your IDE (in my case, PHPStorm) also recognises it is an inline variable and offers the same solution, so you make the change. Does this trigger a regression test for all functions that call getFoosForBar?

I've tried googling this several times, as I'm new in the programming career path, so I am unsure if this should trigger regression testing, or any testing for that matter, especially if they're not automated. I appreciate your input!

Zectzozda
  • 77
  • 7
  • 1
    I don't really understand the question. If you have tests written for this method it will just keep on passing (no error was introduced). What do you mean by "does this trigger regression testing"? You say you don't have it automated.. – Mat May 05 '22 at 07:35
  • 1
    I'm also a bit confused about how the test would be "trigger" if it isn't automated. Either way, regardless if you "just" removed an inline variable, if you changed the code, you should run your tests. Even if the change seems trivial, you should always test it before it goes to production. Basically, never deploy untested code. – M. Eriksson May 05 '22 at 07:38
  • ah, I didn't realise using "triggered" would be a bit of a faux pas here. Let me clarify: would refactoring an inline variable in a function require a tester to regression test (or any other kind of test) this function and other functions that use it? – Zectzozda May 05 '22 at 23:25

0 Answers0