kodus / mail

Simple, modern library of services for sending UTF-8 e-mail
38 stars 5 forks source link

Fix HEREDOC in tests for php 7.3 #13

Closed jakejohns closed 5 years ago

jakejohns commented 5 years ago

PHP Parse error: syntax error, unexpected ':' in [...]

Appears that php7.3 sees MIME in the body as the terminating identifier.

mindplay-dk commented 5 years ago

Appears that php7.3 sees MIME in the body as the terminating identifier.

I don't understand.

Using a different identifier for for the heredoc supposedly fixes something?

You'll have to explain.

I haven't had a chance to test with PHP 7.3 myself, but it sounds like you may have found a bug in PHP?

jakejohns commented 5 years ago

Yes it appears so. The HEREDOC strings in the test contain a line which starts with "MIME" (eg. here) and "MIME" is also the identifier.

I believe it has somethig to do with the "Flexible Heredoc syntax" in 7.3?

$ ./vendor/bin/codecept run
Codeception PHP Testing Framework v2.5.2
Powered by PHPUnit 7.5.2 by Sebastian Bergmann and contributors.
Running with seed:

In Parser.php line 128:

  Couldn't parse test '/[...]/kodus.mail/tests/integration/SMTPClientCest.php' on
  line 31
  syntax error, unexpected ':'

[...]

(master $ u=)$ php -v
PHP 7.3.1 (cli) (built: Jan 11 2019 07:28:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.0beta1, Copyright (c) 2002-2018, by Derick Rethans
jakejohns commented 5 years ago

Simplified example:

<?php
// foo.php

echo <<<FOO
    Ok

FOO;
<?php
// bar.php

echo <<<FOO
    FOO Ok

FOO;
$ php foo.php
    Ok

$ php bar.php 
PHP Parse error:  syntax error, unexpected 'Ok' (T_STRING), expecting ',' or ';'
in [...]bar.php on line 5
mindplay-dk commented 5 years ago

Yes, I see now.

Looks like a minor breaking change in the parser - the documentation states:

If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one.

Looks like they broke this assumption in PHP 7.3 while introducing the flexible heredoc syntax.

I've opened a bug report.

In the mean time, yeah, we need to patch this.

I hate to be nitpicky, but would you mind changing it from EOF to EOT?

(It doesn't mark the end of the File, just the end of the Text.)

Then I can merge and release this right away.

Otherwise, it'll have to wait until I can slot this in at work.

jakejohns commented 5 years ago

Ah yes. My mistake sorry. s/EOF/EOT/ done

mindplay-dk commented 5 years ago

Published in 1.0.1 - thank you for helping out :-)