Published 1 week ago by gidaban79
I know subject is not with Laravel, but maybe someone can expain me how to do PHPUnit test?
I have already script in PHP i know it works, but how to write test for it ?
it's simple script to generate multiplication table. Thing is script generates and display data.
Thing is script generates and display data.
That makes it hard to test. You could use expectOutputString() to test against console output. Or you could use shell_exec() in your test and inspect the returned string. But that would be neither elegant nor expedient.
What you should do is refactor your script and separate logic from presentation. Write classes that only generate the data and other classes that only display it. That way, you can instantiate those classes in your tests and test their methods. Neat and lean. :)