I'm passing all tests but one without returning a value and filling in the proposed functions

Hi,

Right now I’m doing “simple cipher” in the php-track. I think I can make that work but the problem is that I’m passing almost all tests and I haven’t even filled in the functions yet. I’ve written an additional function and I see that as a start. I am NOT RETURNING a value from that function, on purpose, to break the tests but I’m not succeeding. When I do succeed, I can see some printed values. When a test passes, I cannot see anything, everything I print just isn’t there. I don’t know why I’m passing them and I don’t know why I’m not passing the first. I feel like I’m blind.

I also don’t enjoy being critical on a beautiful platform that exercism absolutely is. If I’ve done something silly, please tell me, if not, I would love to be a part of making this exercise work really well.

I’m adding the printed exercise as it is before I started working on it and what I’ve made of it. As you can see I’m returning no or nonsense values on purpose to break the tests. Maybe this post should be in another category? I don’t know. Btw, I’ve deleted my history because I’m working with the online editor. I tried installing locally but I’m in a fix because I did it in the past, changed a few bits, maybe I have to start all over again from scratch.

class SimpleCipher
{
    public function __construct(string $key = null)
    {
     
    }
    
    public function encode(string $plainText): string
    {
 
    }

    public function decode(string $cipherText): string
    {
 
   }
}

class SimpleCipher
{
    public function __construct(string $key = null)
    {
        $this->key = $key;
    }
    
    public function asciiKey() : int 
    {
        $superKey = 0;
        if(strlen($this->key) == 0) {
            return random_int(65, 77);
        }
        $keyarr = str_split($this->key);
        $ordinals = $keyarr.foreach($keyarr as $value) { 
            $superKey += ord($value); 
        }
        //return $superKey;  STILL PASSING THE TESTS!
    }
    
    public function encode(string $plainText): string
    {
        return "flupke";

    }

    public function decode(string $cipherText): string
    {
        return "flupke";
    }
}

Can you show the output from the tests please?

The additional function you wrote is never executed. So all that is checked (by PHP itself) is the syntax of the code. To get an error for not returning anything the function needs to be called somewhere. You may add $this->asciiKey(); into encode() or decode().

Hi,

Thanks for the prompt reply.
I’m still passing the tests. So I’ve got the same code just added what you suggest
inside the encode and decode function. Makes no difference.

 public function encode(string $plainText): string
    {
         $this->asciiKey();
        return "flupke";

    }

    public function decode(string $cipherText): string
    {
        $this->asciiKey();
        return "flupke";
    }

Greets,
Karin

I’m still waiting on this btw :slight_smile:

Is it possible that these tests are commented out so that they’re never run? The output in the languages I’m working on give me check marks and/or ‘OK’ for tests that were commented out in the tester.

Hi,

I checked, they are not commented out and I’ve got 15 green check marks and one red cross. They do run. Btw, a variation of this problem also exists in “Tournament” the exercise before “Simple Cipher”. 10 tests pass, and one fails. In BOTH exercises it’s the first test that fails. Maybe that’s not a coincidence?

Greets,
Karin

Hi,

So sorry, I missed your message. Scrolled to the bottom and yours was the one before the last post.

The output from the tests is below.
Btw, a variation of this problem also exists in “Tournament” the exercise before “Simple Cipher”. 10 tests pass, and one fails. In BOTH exercises it’s the first test that fails. Maybe that’s not a coincidence? I’ll add the output of the first test in tournament as well.

The first test fails. This is the output:

Code Run

$cipher = new SimpleCipher();
$this->assertMatchesRegularExpression('/\A[a-z]+\z/', $cipher->key);

Test Error

SimpleCipherTest::testRandomCipherKeyIsLetters
ParseError: syntax error, unexpected token "foreach"

/mnt/exercism-iteration/SimpleCipher.php:41

I’ll add the output of the tests in order, they all pass

testRandomKeyCipherEncode
Code Run

$cipher = new SimpleCipher();
$plaintext = 'aaaaaaaaaa';
$this->assertEquals(substr($cipher->key, 0, 10), $cipher->encode($plaintext));

testRandomKeyCipherDecode
Code Run

$cipher = new SimpleCipher();
$plaintext = 'aaaaaaaaaa';
$this->assertEquals($plaintext, $cipher->decode(substr($cipher->key, 0, 10)));

testRandomKeyCipherReversible
Code Run

$cipher = new SimpleCipher();
$plaintext = 'abcdefghij';
$this->assertEquals($plaintext, $cipher->decode($cipher->encode($plaintext)));

testCipherWithCapsKey
Code Run

$this->expectException(\InvalidArgumentException::class);
$cipher = new SimpleCipher('ABCDEF');

testCipherWithNumericKey
Code Run

$this->expectException(\InvalidArgumentException::class);
$cipher = new SimpleCipher('12345');

testCipherWithEmptyKey
Code Run

$this->expectException(\InvalidArgumentException::class);
$cipher = new SimpleCipher('');

testCipherKeyIsAsSubmitted
Code Run

$cipher = new SimpleCipher('abcdefghij');
$this->assertEquals($cipher->key, 'abcdefghij');

testCipherEncode
Code Run

$cipher = new SimpleCipher('abcdefghij');
$plaintext = 'aaaaaaaaaa';
$ciphertext = 'abcdefghij';
$this->assertEquals($ciphertext, $cipher->encode($plaintext));

testCipherDecode
Code Run

$cipher = new SimpleCipher('abcdefghij');
$plaintext = 'aaaaaaaaaa';
$ciphertext = 'abcdefghij';
$this->assertEquals($plaintext, $cipher->decode($ciphertext));

testCipherReversible
Code Run

$cipher = new SimpleCipher('abcdefghij');
$plaintext = 'abcdefghij';
$this->assertEquals($plaintext, $cipher->decode($cipher->encode($plaintext)));

testDoubleShiftEncode
Code Run

$cipher = new SimpleCipher('iamapandabear');
$plaintext = 'iamapandabear';
$ciphertext = 'qayaeaagaciai';
$this->assertEquals($ciphertext, $cipher->encode($plaintext));

testCipherEncodeWrap
Code Run

$cipher = new SimpleCipher('abcdefghij');
$plaintext = 'zzzzzzzzzz';
$ciphertext = 'zabcdefghi';
$this->assertEquals($ciphertext, $cipher->encode($plaintext));

testShiftCipherEncode
Code Run

$cipher = new SimpleCipher('dddddddddd');
$plaintext = 'aaaaaaaaaa';
$ciphertext = 'dddddddddd';
$this->assertEquals($ciphertext, $cipher->encode($plaintext));

testShiftCipherDecode
Code Run

$cipher = new SimpleCipher('dddddddddd');
$plaintext = 'aaaaaaaaaa';
$ciphertext = 'dddddddddd';
$this->assertEquals($plaintext, $cipher->decode($ciphertext));

testShiftCipherReversible
Code Run

$cipher = new SimpleCipher('dddddddddd');
$plaintext = 'abcdefghij';
$this->assertEquals($plaintext, $cipher->decode($cipher->encode($plaintext)));

And then test one in “Tournament”

testHeaderOnlyNoTeams
Code Run

$scores   = '';
$expected = 'Team                           | MP |  W |  D |  L |  P';
$this->assertEquals($expected, $this->tournament->tally($scores));

Test Error

TournamentTest::testHeaderOnlyNoTeams
ParseError: syntax error, unexpected token "if"

/mnt/exercism-iteration/Tournament.php:40

Thanks for taking a look. Greets,
Karin

@neenjaw One for you maybe :slight_smile:

@mientje The output of your test run contains:

ParseError: syntax error, unexpected token "foreach"

/mnt/exercism-iteration/SimpleCipher.php:41

This means, you have a syntax error in your code. Take a look at this line of your code (line 41, as the test output states):

$ordinals = $keyarr.foreach($keyarr as $value) {

This is partly JavaScript syntax for iterating over an array. In PHP, this is not a method on the array itself, but a standalone language construct. Try foreach($keyarr as $value).

Oh, and foreach() does not return an array. Maybe try another array function?

1 Like

Hi,

Thank you for looking at this.
You are right I keep placing the array in front of foreach and javascript is the language I know best. The issue however is not that I’m failing the tests but that I’m passing them even with this crappy code. I changed it (I would have looked over that a million times and still not have seen it) but I’m still passing 15 tests and failing one. This is the case in both ‘Tournament’ and ‘Simple Cypher’. And I cannot print anything. Echo, var_dump… nothing comes out anymore so I try to find ways of breaking the tests because I can see printed values when the tests fail. It’s so weird.

Thanks for the remark on foreach, another item learned.

Greets,
Karin

@mientje The other issues are not forgotten nor overlooked, but it is necessary to fix problems one at a time. Given all syntax errors are now fixed, let’s look at the next issue(s).

No output from echo, print and so on

When there is a syntax error in your code, nothing will be executed and output is not produced by the program. So, whenever you have syntax errors, fix these first.

When the program is executed, but your function is not, then no output is produced, too. In the code given above your asciiKey() is not called. Not in __construct() nor encode() nor decode().

It did not work when adding $this->asciiKey(); to one of those functions (as you did 7 days ago), because it contained the syntax error and so adding it still did not execute anything.

So now, when you fixed all syntax errors and added your function to one of those being called during tests, do you still have no output? Even if you add a plain echo "test"; as the first instruction of your function?

Passing most tests without doing anything

I see that with any code having syntax errors. The “Results” tab then shows one syntax error (as this is all that happens when there are syntax errors) and assumes that anything else went well. Which means, all but one test passed. Again, fixing that syntax error helps.

@iHiD Is there something we can do about such situations? The tests are not actually executed, and there is only one failure. So all tests should be seen as failed. Is that handled in the test runner image or on the website?

1 Like

Hi,

I’m outputting stuff now. Thank you, for taking the time and especially for taking me seriously. It’s all so obvious once a person has seen it. I had this hopeless lost feeling and just gave up. I’m going to work on it some more this evening. I will enjoy solving it. You have solved part of the problem but not all so I’m not checking it yet but I can get on with it again.

Greets,
Karin

If the common observation is that when there is a syntax error and all the tests pass except one, then it is probably not tabulating the errors correctly when there is a compilation error.

One thing to rule in or out would be: if you fix the parse error, does it still report the test outcomes as passed? Or does it appropriately mark them as failed?

1 Like

Confirmed, when there is a compilation syntax error, the test runner is returning fail rather than error as it should. This then shows the individual test results, when the status is error the website hides them all:

Have the start of a patch here: patch: handle submitted complilation error by neenjaw · Pull Request #97 · exercism/php-test-runner · GitHub will signal here when it is merged.

1 Like

Thanks Tim!

A new approach on solving the syntax error problem: Solve syntax error reporting and other minor improvements by mk-mxp · Pull Request #101 · exercism/php-test-runner · GitHub

Hi,

Thank you for all the work. I don’t understand what you’ve written but I have the impression everything works a lot better. I am now passing most tests, still have a problem with invalidArgumentException that I’m supposed to implement. I do throw the error and I’ve got try catch syntax in place but I keep getting Failed asserting that exception of type "InvalidArgumentException" is thrown. Anyway, I’ll mark this as solved an if the problem persists create a new topic.

Thanks again and greets,
Karin

You are not expected to catch the exceptions yourself. Remove the try-catch and let the exceptions reach the tests.