Skip to content

Type of returning for functions of the prepareSubject and the prepare…#241

Closed
artemii-karkusha wants to merge 770 commits intolaminas:2.23.xfrom
artemii-karkusha:fix-for-sendmail-class-mail
Closed

Type of returning for functions of the prepareSubject and the prepare…#241
artemii-karkusha wants to merge 770 commits intolaminas:2.23.xfrom
artemii-karkusha:fix-for-sendmail-class-mail

Conversation

@artemii-karkusha
Copy link
Copy Markdown
Contributor

Type of returning for functions of the prepareSubject and the prepareParameters have been fixed

#240

laminas-bot and others added 30 commits January 26, 2021 13:40
Updates the CHANGELOG.md to set the release date.
Updates the CHANGELOG.md file to add a changelog entry for a new 2.14.0 version.
Updates the CHANGELOG.md file to add a changelog entry for a new 2.13.1 version.
- Removes `.travis.yml`
- Adds continuous-integration GHA workflow
- Updates badges in `README.md`
- Removes `CHANGELOG.md`; changelogs will be kept in milestone descriptions and propagated to tag and release notes

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Related to glpi-project/glpi#8495

Signed-off-by: Edgard <edgardmessias@gmail.com>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Line lengths

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
….x_6026c1d0016d83.30821085

Merge release 2.13.1 into 2.14.x
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Signed-off-by: AdrienClairembault <aclairembault@teclib.com>
[2.14]: QA: Add specific type hints for $params
[2.14]: QA: Fix markdown lint errors
…mpty-continuation-lines

Fix laminas#25; Skip empty continuation lines
Keep original ZF references
refs:
- 4665599

Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
[2.14]: Tests: Fix references to ZF issue tracker
To deal with the 998/78 character limitations per line,
long lines can be split into a multiple-line representation
separated by CRLF + WSP; this is called "folding".
Correct folding is particularly important for long header fields.

Signed-off-by: Vlad Safronov <vladislav.safronov@oracle.com>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
This isolates the logic of handling incomplete reads to own unit.

Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
As the buffer max size is known, can check last byte with isset

Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Signed-off-by: Elan Ruusamäe <glen@pld-linux.org>
Slamdunk and others added 3 commits May 22, 2023 09:57
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
…Parameters have been fixed

Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
Copy link
Copy Markdown
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need a test to verify this change: I suppose you expect getSubject() to always return a string?

@Xerkus
Copy link
Copy Markdown
Member

Xerkus commented May 22, 2023

dockblock and usage checks out, it is expected to always return string.

Return values are passed to mail() with signature

 mail(
    string $to,
    string $subject,
    string $message,
    array|string $additional_headers = [],
    string $additional_params = ""
): bool

@Ocramius
Copy link
Copy Markdown
Member

Yes, I mean a test case (additions to our PHPUnit test suite :D )

The test should fail before this change, and pass after this change.

@artemii-karkusha
Copy link
Copy Markdown
Contributor Author

We'd need a test to verify this change: I suppose you expect getSubject() to always return a string?

I will add for this case

@artemii-karkusha
Copy link
Copy Markdown
Contributor Author

@Ocramius
Result of test the testAllowMessageWithEmptySubjectButHasBccHeader before changes for SendMail was made.
Screenshot 2023-05-23 at 11 39 26

Copy link
Copy Markdown
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artemii-karkusha looking much better now, thanks!

What's missing now is some cleanup around the test case.

Comment thread test/Transport/SendmailTest.php Outdated
$this->transport->setCallable([$this->transport, 'mailHandler']);
try {
$this->transport->send($message);
} catch (\RuntimeException $runtimeException) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a RuntimeException expected to be thrown at all times?

If so, PHPUnit can help you here:

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Something different from a warning');

The try-catch can then be removed :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius No. It is not expected to throw all time. It was added to be sure logic will not be broken for mailHandler in future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but then this test has no assertions, and is a risky test 🤔

Can we somehow verify the outcome with a valid assertion?

/cc @Slamdunk for ideas

Copy link
Copy Markdown
Contributor Author

@artemii-karkusha artemii-karkusha May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not real to cover outcome. Function doesn't return nothing. What we can cover is exception which is thrown when someone will change behaviour for subject and it will influence on function the mail(..., #subject).
prepareSubject which can be better place for test case is protected.
I don't have any ideas how can we cover it in another way. If you have let it will share with me, please.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's why I poked @Slamdunk to get some more brains :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we don't need tests here, it's a type mismatch so getting rid of PSalm suppressions should be enough:

diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 88d83696..0140e43e 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -1737,18 +1737,12 @@
     <InvalidArgument>
       <code><![CDATA[[$this, 'handleMailErrors']]]></code>
     </InvalidArgument>
-    <InvalidNullableReturnType>
-      <code>string</code>
-    </InvalidNullableReturnType>
     <MissingReturnType>
       <code>mailHandler</code>
     </MissingReturnType>
     <MixedAssignment>
       <code>$param</code>
     </MixedAssignment>
-    <MixedInferredReturnType>
-      <code>string</code>
-    </MixedInferredReturnType>
     <MixedOperand>
       <code>$param</code>
     </MixedOperand>
diff --git a/src/Transport/Sendmail.php b/src/Transport/Sendmail.php
index aae76f49..58868dda 100644
--- a/src/Transport/Sendmail.php
+++ b/src/Transport/Sendmail.php
@@ -9,6 +9,7 @@ use Laminas\Mail\Transport\Exception\InvalidArgumentException;
 use Laminas\Mail\Transport\Exception\RuntimeException;
 use Traversable;
 
+use function assert;
 use function count;
 use function escapeshellarg;
 use function gettype;
@@ -200,10 +201,12 @@ class Sendmail implements TransportInterface
     {
         $headers = $message->getHeaders();
         if (! $headers->has('subject')) {
-            return;
+            return '';
         }
-        $header = $headers->get('subject');
-        return $header->getFieldValue(HeaderInterface::FORMAT_ENCODED);
+        $header     = $headers->get('subject');
+        $fieldValue = $header->getFieldValue(HeaderInterface::FORMAT_ENCODED);
+        assert(is_string($fieldValue));
+        return $fieldValue;
     }
 
     /**
@@ -259,7 +262,7 @@ class Sendmail implements TransportInterface
     protected function prepareParameters(Mail\Message $message)
     {
         if ($this->isWindowsOs()) {
-            return;
+            return '';
         }
 
         $parameters = (string) $this->parameters;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this outcome too 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius
It has to be closed. I did mistake when changed author for commits. I have created new PL with all needed changes.
#242

@artemii-karkusha artemii-karkusha force-pushed the fix-for-sendmail-class-mail branch from 695288c to 7faa761 Compare May 23, 2023 09:51
…mail has been added.

Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
@artemii-karkusha
Copy link
Copy Markdown
Contributor Author

@Ocramius Please let me know if something is needed to changing. It is ready for merging

@Slamdunk Slamdunk added the Bug Something isn't working label May 24, 2023
@Slamdunk Slamdunk added this to the 2.23.0 milestone May 24, 2023
…sending mail has been added."

This reverts commit fab234c.
Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
…ng' for Laminas\Mail\Transport\Envelope::getFrom is not nullable, but 'null|string' contains null (see https://psalm.dev/144)" has been fixed

Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
Signed-off-by: Artemii Karkusha <artemii.karkusha@alshaya.com>
@Slamdunk
Copy link
Copy Markdown
Contributor

See #242

@Slamdunk Slamdunk closed this May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.