exercism / php-test-runner

GNU Affero General Public License v3.0
0 stars 6 forks source link

No debug output and test inputs in online editor for dataProvider #116

Open mk-mxp opened 3 weeks ago

mk-mxp commented 3 weeks ago

While looking into this forum thread, I found that students cannot output anything to debug their code. Also the test feedback somehow is incomplete:

Code Run

): void {
    $class = new LuckyNumbers();

    $actual = $class->validate($input);

    $this->assertSame('', $actual);

Test Failure

LuckyNumbersTest::testErrorMessageForValidInput with data set #5
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'Must be a whole number larger than 0'

LuckyNumbersTest.php:138

This test file uses @dataProvider to ease coding of tests, but that must be designed to deliver acceptable test feedback (students must see test input, not "data set #5"). It is best to avoid data providers.

Anyways, there should be test output delivered when using echo or var_dump(). And that's missing.

Code submitted:

<?php

class LuckyNumbers
{
    public function sumUp(array $digitsOfNumber1, array $digitsOfNumber2): int
    {
        return \implode($digitsOfNumber1) + \implode($digitsOfNumber2);
    }

    public function isPalindrome(int $number): bool
    {
        return (string)$number == \strrev($number);
    }

    public function validate(string $input): string
    {
        echo $input;

        if ($input == ""){
return "Required field";
}
else if(!is_numeric($input) || intval($input) <= 0 || (intval($input)) != $input){
return "Must be a whole number larger than 0";
}
else return "";
    }
}
mk-mxp commented 3 weeks ago

I have analysed the possible sources for including the input values into the test feedback. There is no hint in JUnit results.xml nor teamcity.txt. So this must be solved by re-designing the test files in the PHP track:

If we choose the last option (variables in @testdox) the test runner must have a test case for that, too.

mk-mxp commented 3 weeks ago

We currently have @dataProvider in these exercises:

I'll leave this issue opened for reference in PHP track https://github.com/exercism/php/issues/755