Some PHP exercises can't be submitted via the online editor

With the exercise Binary, my code passes all 6 tests but there’s a red banner at the top of the Results section that says “0 TEST FAILURES” and the Submit button won’t enable.

With the Gigasecond exercise, the tests appear to run but no test results appear, neither passed tests nor failed tests. The same “0 TEST FAILURES” banner appears (note: I don’t have any actual code going in that exercise, just some comments, so all tests should be failing). For this exercise it’s less about the inability to submit and more about not being able to see the results of any tests. The red banner seems like it might be a significant common thread between the two issues.

These exercises aren’t holding me up so I’m not overly concerned about when or if this gets addressed. If I’m in the wrong place, please let me know and I’ll move this post or otherwise fix this. Thanks!

@Eggman: Thanks for reporting. This is the right place :) Could you paste here exactly what was in the editor when you submitted please (even if it was just some comments etc)

(cc @neenjaw and @ErikSchierboom)

This is what I submitted for Gigasecond:

<?php

/*
 * By adding type hints and enabling strict type checking, code can become
 * easier to read, self-documenting and reduce the number of potential bugs.
 * By default, type declarations are non-strict, which means they will attempt
 * to change the original type to match the type specified by the
 * type-declaration.
 *
 * In other words, if you pass a string to a function requiring a float,
 * it will attempt to convert the string value to a float.
 *
 * To enable strict mode, a single declare directive must be placed at the top
 * of the file.
 * This means that the strictness of typing is configured on a per-file basis.
 * This directive not only affects the type declarations of parameters, but also
 * a function's return type.
 *
 * For more info review the Concept on strict type checking in the PHP track
 * <link>.
 *
 * To disable strict typing, comment out the directive below.
 */

declare(strict_types=1);

function from(DateTimeImmutable $date): DateTimeImmutable
{
    echo "In *** from ***";
    //$interval = DateInterval::createFromDateString('1_000_000_000 seconds');

    //$date.add($interval);
    
    return $date;
}

This is what I submitted for Binary:

<?php

/*
 * By adding type hints and enabling strict type checking, code can become
 * easier to read, self-documenting and reduce the number of potential bugs.
 * By default, type declarations are non-strict, which means they will attempt
 * to change the original type to match the type specified by the
 * type-declaration.
 *
 * In other words, if you pass a string to a function requiring a float,
 * it will attempt to convert the string value to a float.
 *
 * To enable strict mode, a single declare directive must be placed at the top
 * of the file.
 * This means that the strictness of typing is configured on a per-file basis.
 * This directive not only affects the type declarations of parameters, but also
 * a function's return type.
 *
 * For more info review the Concept on strict type checking in the PHP track
 * <link>.
 *
 * To disable strict typing, comment out the directive below.
 */

declare(strict_types=1);

function parse_binary(string $binary): int
{
    $digits_count = strlen($binary);
    $base_10_number = 0;

    foreach ( str_split($binary) as $index => $binary_digit ) {
        $base_10_number += intval($binary_digit) * 2**($digits_count - 1 - $index);
    }

    return $base_10_number;
}
1 Like

Using an echo in phpunit, is technically a test failure, probably not capturing that properly for gigs second. Not sure why the binary one is failing from inspection.

Might be able to look at it this weekend.

1 Like

Adding for the sake of full disclosure: commenting out the echo didn’t make a difference and I’ve been using echo to troubleshoot on a pretty regular basis on the PHP track without running into this issue in the other exercises. Could well still be part of the problem, I’m not the person who would know. ;)

@neenjaw It seems to be an issue with the test runner, which outputs:

{"version":3,"status":"fail","tests":[]}

The fail (and success) state should only be used when at least one test has run, otherwise it should be error (and message should be populated).

The results.xml file that is created during the test run looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" tests="10" assertions="10" errors="0" warnings="0" failures="5" skipped="0" time="0.004059">
    <testsuite name="GigasecondTest::testFrom" tests="5" assertions="5" errors="0" warnings="0" failures="5" skipped="0" time="0.003839">
      <testcase name="testFrom with data set #0" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="67" assertions="1" time="0.003351">
        <failure type="PHPUnit\Framework\ExpectationFailedException">GigasecondTest::testFrom with data set #0 ('2011-04-25', '2043-01-01 01:46:40')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'2043-01-01 01:46:40'
+'2011-04-25 00:00:00'

/mnt/exercism-iteration/GigasecondTest.php:72</failure>
        <system-out>In *** from ***</system-out>
      </testcase>
      <testcase name="testFrom with data set #1" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="67" assertions="1" time="0.000119">
        <failure type="PHPUnit\Framework\ExpectationFailedException">GigasecondTest::testFrom with data set #1 ('1977-06-13', '2009-02-19 01:46:40')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'2009-02-19 01:46:40'
+'1977-06-13 00:00:00'

/mnt/exercism-iteration/GigasecondTest.php:72</failure>
        <system-out>In *** from ***</system-out>
      </testcase>
      <testcase name="testFrom with data set #2" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="67" assertions="1" time="0.000032">
        <failure type="PHPUnit\Framework\ExpectationFailedException">GigasecondTest::testFrom with data set #2 ('1959-07-19', '1991-03-27 01:46:40')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'1991-03-27 01:46:40'
+'1959-07-19 00:00:00'

/mnt/exercism-iteration/GigasecondTest.php:72</failure>
        <system-out>In *** from ***</system-out>
      </testcase>
      <testcase name="testFrom with data set #3" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="67" assertions="1" time="0.000294">
        <failure type="PHPUnit\Framework\ExpectationFailedException">GigasecondTest::testFrom with data set #3 ('2015-01-24 22:00:00', '2046-10-02 23:46:40')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'2046-10-02 23:46:40'
+'2015-01-24 22:00:00'

/mnt/exercism-iteration/GigasecondTest.php:72</failure>
        <system-out>In *** from ***</system-out>
      </testcase>
      <testcase name="testFrom with data set #4" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="67" assertions="1" time="0.000042">
        <failure type="PHPUnit\Framework\ExpectationFailedException">GigasecondTest::testFrom with data set #4 ('2015-01-24 23:59:59', '2046-10-03 01:46:39')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'2046-10-03 01:46:39'
+'2015-01-24 23:59:59'

/mnt/exercism-iteration/GigasecondTest.php:72</failure>
        <system-out>In *** from ***</system-out>
      </testcase>
    </testsuite>
    <testsuite name="GigasecondTest::testFromReturnType" tests="5" assertions="5" errors="0" warnings="0" failures="0" skipped="0" time="0.000220">
      <testcase name="testFromReturnType with data set #0" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="79" assertions="1" time="0.000156">
        <system-out>In *** from ***</system-out>
      </testcase>
      <testcase name="testFromReturnType with data set #1" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="79" assertions="1" time="0.000031">
        <system-out>In *** from ***</system-out>
      </testcase>
      <testcase name="testFromReturnType with data set #2" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="79" assertions="1" time="0.000011">
        <system-out>In *** from ***</system-out>
      </testcase>
      <testcase name="testFromReturnType with data set #3" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="79" assertions="1" time="0.000012">
        <system-out>In *** from ***</system-out>
      </testcase>
      <testcase name="testFromReturnType with data set #4" class="GigasecondTest" classname="GigasecondTest" file="/mnt/exercism-iteration/GigasecondTest.php" line="79" assertions="1" time="0.000011">
        <system-out>In *** from ***</system-out>
      </testcase>
    </testsuite>
  </testsuite>
</testsuites>
2 Likes

Thanks for sharing the output here. On a plain read I am unsure why the junit parser can’t read that output, but this will make it easier to find the issue.

1 Like

Ah, this test file uses a data provider which the test runner wasn’t prepared for. I am weighing whether there is an easy solution for this, as it affects the ability to get the “task id” associated with a test.

It may be simpler to re-write the test case to not use doc-blocks.

Update: The Protein Translation exercise in the PHP track has the same issue as Binary, which is that although all the tests report passing I get a red banner in the Results tab saying “0 TEST FAILURES” and the Submit button isn’t enabled.

Update: The Allergies exercise in the PHP track is showing the same issue as Binary and Protein Translation as described earlier in this thread. Running the tests reports “5 tests passed” and a red banner is displayed that says “0 TEST FAILURES”, and the submit button doesn’t enable.

This is the exercise code in the online editor:

<?php

declare(strict_types=1);

class Allergies
{
    private $allergen_list = [];
    
    private $allergens = [];
    
    public function __construct(int $score)
    {
        $this->allergen_list = [ new Allergen(Allergen::EGGS),
                                 new Allergen(Allergen::PEANUTS),
                                 new Allergen(Allergen::SHELLFISH),
                                 new Allergen(Allergen::STRAWBERRIES),
                                 new Allergen(Allergen::TOMATOES),
                                 new Allergen(Allergen::CHOCOLATE),
                                 new Allergen(Allergen::POLLEN),
                                 new Allergen(Allergen::CATS) ];
        
        $allergen_markers = array_reverse( str_split( decbin($score) ) );

        foreach ( $allergen_markers as $index => $this_allergen ) {
            if ( $this_allergen === '1' && $index < 8 ) {
                $this->allergens[] = $this->allergen_list[$index];
            }
        }
    }

    public function isAllergicTo(Allergen $allergen): bool
    {
        return in_array($allergen, $this->allergens);
    }

    public function getList(): array
    {
       return $this->allergens;
    }
}

class Allergen
{
    const EGGS = 1;
    const PEANUTS = 2;
    const SHELLFISH = 4;
    const STRAWBERRIES = 8;
    const TOMATOES = 16;
    const CHOCOLATE = 32;
    const POLLEN = 64;
    const CATS = 128;

    function __construct(public int $allergen) {}
    
    public static function allergenList(): array
    {
        return [ self::EGGS,
                 self::PEANUTS,
                 self::SHELLFISH,
                 self::STRAWBERRIES,
                 self::TOMATOES,
                 self::CHOCOLATE,
                 self::POLLEN,
                 self::CATS ];
    }
}

I have a PR now ready merged for review to fix this issue. It should address all of the table test related failures as it is able to now traverse the nested testsuite xml path.

Sorry for the delay.

This has been now merged. And is working as expected for the exercises I tested with.

Brilliant. Thanks @neenjaw :blue_heart:

All the exercises I was having an issue with on this track now work correctly, thanks!

Well, except one, which seems to be an issue with the test code itself. I want to double check that one (Allergies) before I say more. ;)