(SOLVED) Failed Swift Unit Tests

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

covina
Forum Newbie
Posts: 15
Joined: Tue May 22, 2007 1:55 pm

(SOLVED) Failed Swift Unit Tests

Post by covina »

I just installed the script and ran the units tests, but half of the 4 alltests failed, here is the result:
runAllAuthenticatorTests.php - pass
runAllMimeTests.php - pass

runAllConnectionTests.php - failed with following message:
Fail: testofsmtpconnection -> testauthenticationisonlyinvokedifusernameandpasswordset -> Maximum call count for [isAuthenticated] was [0] got [1] at [/homepages/54/d171027348/htdocs/xxxx.com/tests/units/testcases/TestOfSMTPConnection.php line 47]

7/7 test cases complete: 104 passes, 1 fails and 0 exceptions.

runAllCoreTests.php - failed too, part of the error message as follows:
Fail: testofeasyswift -> testsmtpauthenticationreturnstrueonsuccess -> Mock method [write] at [1] -> Parameter expectation differs at parameter 1 with [Identical expectation [String: AUTH PLAIN Zm9vAGZvbwBiYXI=] fails with [String: AUTH PLAIN XXXXXXXXXX] at character 11 with [AUTH PLAIN Zm9vAGZvbwBiYXI=] and [AUTH PLAIN XXXXXXXXXXXXXXXXX]] at [/[/homepages/54/d171027348/htdocs/xxxx.com/tests/units/testcases/TestOfEasySwift.php line 215]
Fail: testofeasyswift -> testsmtpauthenticationreturnstrueonsuccess -> at [/[/homepages/54/d171027348/htdocs/xxxx.com/tests/units/testcases/TestOfEasySwift.php line 221]

I'm new to Swift and php newbie too. Appreciate very much if anybody could help.
CS
Last edited by covina on Wed Dec 19, 2007 11:33 pm, edited 2 times in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Hmm... :?

Sorry about this. It almost looks as if I've got a md5() where I should have a base64_encode(). You can carry on using it anyway.... failing tests doesn't make the library is completely useless to you ;) In this particular case things will still work since even if you do need to authenticate it tries them all until one works.

---------------

Hmm... I just looked at the test and it appears to be correctly written. I have no idea how this line:

Code: Select all

$conn->expectAt(1, "write", array("AUTH PLAIN " . base64_encode("foo\0foo\0bar"), "*"));
Is producing XXXXXXXXXXXXXXXXXXXXXXXXXXX as the base64 encoded string on your installation :?

Let me do some more digging... this could very well be a PHP bug with base64_encode() on a certain version.

Weirdan| d11, you cited the credentials
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'm stumped... have you modified any of the files in any way? I'm running the tests here but cannot reproduce this error.

What version of Swift are you running, what version of PHP and what version of simpletest? :)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

this could very well be a PHP bug with base64_encode() on a certain version.
base64_decode of that string produces meaningful result, so it must be a broken unit test (or a broken code for that matter).
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I just decoded your base64_encoded string. It contains your username and password so I'm removing it. The only way this could happen in the test results is if the test file, or the Swift/Authenticator/PLAIN.php file has been modified to add those credentials.

I guess you're called stan ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

To clarify. The test is comparing this:

Code: Select all

function isAuthenticated($user, $pass, &$swift)
  {
    //The authorization string uses ascii null as a separator (See RFC 2554)
    $credentials = base64_encode($user . chr(0) . $user . chr(0) . $pass);
    Swift_ClassLoader::load("Swift_Errors");
    Swift_Errors::expect($e, "Swift_Connection_Exception");
      $swift->command("AUTH PLAIN " . $credentials, 235);
    if ($e) {
      $swift->reset();
      return false;
    }
    Swift_Errors::clear("Swift_Connection_Exception");
    return true;
  }
With this:

Code: Select all

/**
   * The authenticate() method comes from the old API, but is now wrapped around the new API.
   */
  function testSMTPAuthenticationReturnsTrueOnSuccess()
  {
    $conn =& new MockSMTPConnectionAuth($this);
    $conn->setReturnValue("isAlive", true);
    $conn->setReturnValueAt(0, "read", "220 xxx ESMTP");
    $conn->setReturnValueAt(1, "read", "250-Hello xxx\r\n250-AUTH PLAIN\r\n250 HELP");
    $conn->setReturnValueAt(2, "read", "235 Authenticated");
    $conn->expectAt(1, "write", array("AUTH PLAIN " . base64_encode("foo\0foo\0bar"), "*"));
    
    $auth =& new Swift_Authenticator_PLAIN();
    
    $swift =& new EasySwift($conn);
    $swift->loadAuthenticator($auth);
    $this->assertTrue($swift->authenticate("foo", "bar"));
  }
I really can't see a way to defeat that :? :(
covina
Forum Newbie
Posts: 15
Joined: Tue May 22, 2007 1:55 pm

Post by covina »

d11wtq wrote:I'm stumped... have you modified any of the files in any way? I'm running the tests here but cannot reproduce this error.

What version of Swift are you running, what version of PHP and what version of simpletest? :)
Thanks for the help.

FYI, I'm running PHP Version 4.4.4, Swift-3.2.3-php4 and simpletest_1.0.1beta.

I didn't touch PLAIN.php, but add my credentials(auth info) in lib/Swift/connection/SMTP.php and /tests/units/testcases/TestOfSMTPConnection.php.
Below is the code piece in the TestOfSMTPConnection.php mentioned above:

Code: Select all

$auth->setReturnValue("getAuthExtensionName", "*foo");
what's the use of string ("*foo" or "foo"), should it be changed to LOGIN?

Also, you think I should just go ahead implement Swift and starting using it? I'm afraid that not a clean start may make things conmplicated later.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Never ever edit any files in the download. By editting Swift/Connection/SMTP.php you've made it impossible to authenticate as any other user ;) That's why the tests are failing.

Documentation shows how to authenticate correctly... you do not *ever* have to modify the files in the download (apart from TestConfiguration.php -- which is an exception if you want to run the tests).

http://www.swiftmailer.org/wikidocs/v3/smtpauth
covina
Forum Newbie
Posts: 15
Joined: Tue May 22, 2007 1:55 pm

Post by covina »

Oooops, sorry for the messup.
Thanks for the help. I'll reload the scripts and run the test again, will update you soon.
covina
Forum Newbie
Posts: 15
Joined: Tue May 22, 2007 1:55 pm

Post by covina »

I reload the scripts and simpletest, this time a little bit strange. As the screenshots won't show for those smoke tests, and I got the following errors when running All Swift MIME Tests, it is about the image type .png:

Code: Select all

Fail: testofimage -> testimagetypeisdetected -> Equal expectation fails at character 0 with [image/png] and [application/octet-stream] at [/homepages/514/d1710273/htdocs/xxx.com/tests/units/testcases/TestOfImage.php line 16]
Exception: testofimage -> testimagetypeisdetected -> Unexpected PHP error [<br /><strong>Uncaught Error</strong> of type [swift_message_mimeexception] with message [Cannot use file '../files/gecko.png' as image since getimagesize() was unable to detect a file format. Try using Swift_Message_EmbeddedFile instead]<br /> @0 grouptest::run() in /homepages/514/d1710273/htdocs/xxx.com/tests/units/runAllMimeTests.php on line 46<br /> @1 testofimage::run() in /homepages/514/d1710273/htdocs/lib/simpletest/test_case.php on line 591<br /> @2 simpleerrortrappinginvoker::invoke() in /homepages/514/d1710273/htdocs/lib/simpletest/test_case.php on line 135<br /> @3 simpleinvokerdecorator::invoke() in /homepages/514/d1710273/htdocs/lib/simpletest/errors.php on line 48<br /> @4 simpleinvoker::invoke() in /homepages/514/d1710273/htdocs/lib/simpletest/invoker.php on line 126<br /> @5 testofimage::testimagetypeisdetected() in /homepages/514/d1710273/htdocs/lib/simpletest/invoker.php on line 68<br /><br />] severity [E_USER_ERROR] in [/homepages/514/d1710273/htdocs/lib/Swift/Errors.php line 99]
Any idea of what causes this?
covina
Forum Newbie
Posts: 15
Joined: Tue May 22, 2007 1:55 pm

It's all about img type/format

Post by covina »

All the unit tests passed except All Swift Core Tests failed as below and All Swift MIME Tests as in my last post

Code: Select all

Fail: testofeasyswift -> testcidsrcvalueisreturnedwhenaddingimage -> Pattern [/^cid:.+$/i] not detected in [Boolean: false] at [/homepages/514/d1710273/htdocs/xxx.com/tests/units/testcases/TestOfEasySwift.php line 166]
It's all about img type of png, what's the problem? it's weird.
Chris, could you help?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

When you extracted the directory, did you move any files at all? Also check the permissions on the png file in the directory tests/files/* and if you uploaded the contents of the archive make sure you transfered those files in binary mode (most FTP clients will automatically detect this).

It's vital that the tests directory remains in the same format (i.e. "tests/units/testcases", "tests/files", "tests/smokes").

The tests are not failing for me. getimagesize() is returning false by the look of it, which suggests it can't find the file, or the file is corrupt.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

or the file is corrupt.
... or that particular php installation was compiled without png support
covina
Forum Newbie
Posts: 15
Joined: Tue May 22, 2007 1:55 pm

Post by covina »

That works, Everything works from smokes to unit tests after I reloaded the scripts as told by Chris, though I couldn't install xdebug as my ISP doesn't allow me to do that.
Except that, I'm a happy puppy now. :D
From a beginner point, I think I assume Swift to be very complicated than it really is, that's why I got into so much trouble.
Just for people after me, upload in auto mode or binary, change nothing except TestConfiguration.php, that's all it's required to install and test the Swift mailer script.
Thanks again for your guys, especially Chris.
Last edited by covina on Wed May 23, 2007 7:40 pm, edited 1 time in total.
covina
Forum Newbie
Posts: 15
Joined: Tue May 22, 2007 1:55 pm

$SMTP_PORT = 587

Post by covina »

Chris, I wondering why the smoke tests wont work if the smtp_port is changed to 587, the alternative to 25 provided by my ISP.
Any thoughts or clues?

BTW, without xebug, I can run time_sending_with_swift.php, but not the other two.
Post Reply