Skip to content

Commit

Permalink
improved coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 21, 2015
1 parent 3bad28f commit a1034a0
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 101 deletions.
8 changes: 4 additions & 4 deletions src/Mail/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Mail;

use Nette,
Nette\Utils\Strings;
use Nette;
use Nette\Utils\Strings;


/**
Expand Down Expand Up @@ -248,7 +248,7 @@ public function setHtmlBody($html, $basePath = NULL)
}

if ($this->getSubject() == NULL) { // intentionally ==
$html = Strings::replace($html, '#<title>(.+?)</title>#is', function($m) use (& $title) {
$html = Strings::replace($html, '#<title>(.+?)</title>#is', function ($m) use (& $title) {
$title = $m[1];
});
$this->setSubject(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
Expand Down Expand Up @@ -403,7 +403,7 @@ protected function buildText($html)
{
$text = Strings::replace($html, [
'#<(style|script|head).*</\\1>#Uis' => '',
'#<t[dh][ >]#i' => " $0",
'#<t[dh][ >]#i' => ' $0',
'#[\r\n]+#' => ' ',
'#<(/?p|/?h\d|li|br|/tr)[ >/]#i' => "\n$0",
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Mail/MimePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Nette\Mail;

use Nette,
Nette\Utils\Strings;
use Nette;
use Nette\Utils\Strings;


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Mail/SendmailMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function send(Message $mail)
if ($this->commandArgs) {
$args[] = (string) $this->commandArgs;
}
$res = Nette\Utils\Callback::invokeSafe('mail', $args, function($message) use (& $info) {
$res = Nette\Utils\Callback::invokeSafe('mail', $args, function ($message) use (& $info) {
$info = ": $message";
});
if ($res === FALSE) {
Expand Down
14 changes: 7 additions & 7 deletions tests/Mail.DI/Mail.extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Test: MailExtension.
*/

use Nette\DI,
Nette\Bridges\MailDI\MailExtension,
Tester\Assert;
use Nette\DI;
use Nette\Bridges\MailDI\MailExtension;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -20,8 +20,8 @@ $container1 = createContainer($compiler, '
test:
smtp: false
');
Assert::type( 'Nette\Mail\SendmailMailer', $container1->getService('test.mailer') );
Assert::false( $container1->hasService('nette.mailer') );
Assert::type('Nette\Mail\SendmailMailer', $container1->getService('test.mailer'));
Assert::false($container1->hasService('nette.mailer'));


$compiler = new DI\Compiler;
Expand All @@ -30,5 +30,5 @@ $container2 = createContainer($compiler, '
mail:
smtp: true
');
Assert::type( 'Nette\Mail\SmtpMailer', $container2->getService('mail.mailer') );
Assert::type( $container2->getService('mail.mailer'), $container2->getService('nette.mailer') );
Assert::type('Nette\Mail\SmtpMailer', $container2->getService('mail.mailer'));
Assert::type($container2->getService('mail.mailer'), $container2->getService('nette.mailer'));
8 changes: 4 additions & 4 deletions tests/Mail/Mail.HtmlBody.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Mail\Message - HTML body.
*/

use Nette\Mail\Message,
Tester\Assert;
use Nette\Mail\Message;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -24,7 +24,7 @@ $mail->setHTMLBody('<b><span>Příliš </span> žluťoučký <br>kůň</b>');
$mailer = new TestMailer();
$mailer->send($mail);

Assert::match( <<<EOD
Assert::match(<<<EOD
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
Expand All @@ -48,4 +48,4 @@ Content-Transfer-Encoding: 8bit
<b><span>Příliš </span> žluťoučký <br>kůň</b>
----------%S%--
EOD
, TestMailer::$output );
, TestMailer::$output);
16 changes: 8 additions & 8 deletions tests/Mail/Mail.attachment.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Mail\Message - attachments.
*/

use Nette\Mail\Message,
Tester\Assert;
use Nette\Mail\Message;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -19,7 +19,7 @@ $mail = new Message();
$mail->addAttachment(__DIR__ . '/files/example.zip', NULL, 'application/zip');
$mailer->send($mail);

Assert::match( <<<EOD
Assert::match(<<<EOD
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
Expand All @@ -43,15 +43,15 @@ AAgAJ4gyOyaRKmdAAAAAQQAAAAsAAAAAAAAAAAAgAAAAAAAAAHZlcnNpb24udHh0UEsFBgAAAAAB
AAEAOQAAAGkAAAAAAA==
----------%S%--
EOD
, TestMailer::$output );
, TestMailer::$output);


$mail = new Message();
$mail->addAttachment(__DIR__ . '/files/example.zip', NULL, 'application/zip')
->setEncoding(Message::ENCODING_QUOTED_PRINTABLE);
$mailer->send($mail);

Assert::match( <<<EOD
Assert::match(<<<EOD
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
Expand All @@ -72,15 +72,15 @@ Content-Disposition: attachment; filename="example.zip"
PK=03=04=14=00=00=00=08=00'=882;&=91*g@=00=00=00A=00=00=00=0B=00=00=00versi=%A%00
----------%S%--
EOD
, TestMailer::$output );
, TestMailer::$output);


$mail = new Message();
$name = iconv('UTF-8', 'WINDOWS-1250', 'žluťoučký.zip');
$mail->addAttachment($name, file_get_contents(__DIR__ . '/files/example.zip'), 'application/zip');
$mailer->send($mail);

Assert::match( <<<EOD
Assert::match(<<<EOD
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
Expand All @@ -104,4 +104,4 @@ AAgAJ4gyOyaRKmdAAAAAQQAAAAsAAAAAAAAAAAAgAAAAAAAAAHZlcnNpb24udHh0UEsFBgAAAAAB
AAEAOQAAAGkAAAAAAA==
----------%S%--
EOD
, TestMailer::$output );
, TestMailer::$output);
22 changes: 11 additions & 11 deletions tests/Mail/Mail.email.errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,60 @@
* Test: Nette\Mail\Message invalid email addresses.
*/

use Nette\Mail\Message,
Tester\Assert;
use Nette\Mail\Message;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$mail = new Message();

Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
// From
$mail->setFrom('John Doe <doe@example. com>');
}, 'Nette\Utils\AssertionException', "The header 'From' expects to be email, string 'doe@example. com' given.");


Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
$mail->setFrom('John Doe <>');
}, 'Nette\Utils\AssertionException', "The header 'From' expects to be email, string '' given.");


Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
$mail->setFrom('John Doe <doe@examplecom>');
}, 'Nette\Utils\AssertionException', "The header 'From' expects to be email, string 'doe@examplecom' given.");


Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
$mail->setFrom('John Doe');
}, 'Nette\Utils\AssertionException', "The header 'From' expects to be email, string 'John Doe' given.");


Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
$mail->setFrom('doe;@examplecom');
}, 'Nette\Utils\AssertionException', "The header 'From' expects to be email, string 'doe;@examplecom' given.");


Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
// addReplyTo
$mail->addReplyTo('@');
}, 'Nette\Utils\AssertionException', "The header 'Reply-To' expects to be email, string '@' given.");


Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
// addTo
$mail->addTo('@');
}, 'Nette\Utils\AssertionException', "The header 'To' expects to be email, string '@' given.");


Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
// addCc
$mail->addCc('@');
}, 'Nette\Utils\AssertionException', "The header 'Cc' expects to be email, string '@' given.");


Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
// addBcc
$mail->addBcc('@');
}, 'Nette\Utils\AssertionException', "The header 'Bcc' expects to be email, string '@' given.");
8 changes: 4 additions & 4 deletions tests/Mail/Mail.email.long.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Mail\Message valid email addresses.
*/

use Nette\Mail\Message,
Tester\Assert;
use Nette\Mail\Message;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -24,7 +24,7 @@ $mail->addBcc('veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryv
$mailer = new TestMailer();
$mailer->send($mail);

Assert::match( <<<EOD
Assert::match(<<<EOD
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
Expand All @@ -37,4 +37,4 @@ Message-ID: <%a%@%a%>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
EOD
, TestMailer::$output );
, TestMailer::$output);
8 changes: 4 additions & 4 deletions tests/Mail/Mail.email.multiple.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Mail\Message - textual body.
*/

use Nette\Mail\Message,
Tester\Assert;
use Nette\Mail\Message;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -27,7 +27,7 @@ $mail->setBody('Žluťoučký kůň');
$mailer = new TestMailer();
$mailer->send($mail);

Assert::match( <<<EOD
Assert::match(<<<EOD
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
Expand All @@ -42,4 +42,4 @@ Content-Transfer-Encoding: 8bit
Žluťoučký kůň
EOD
, TestMailer::$output );
, TestMailer::$output);
8 changes: 4 additions & 4 deletions tests/Mail/Mail.email.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Mail\Message valid email addresses.
*/

use Nette\Mail\Message,
Tester\Assert;
use Nette\Mail\Message;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand Down Expand Up @@ -35,7 +35,7 @@ $mail->setReturnPath('[email protected]');
$mailer = new TestMailer();
$mailer->send($mail);

Assert::match( <<<'EOD'
Assert::match(<<<'EOD'
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
Expand All @@ -53,4 +53,4 @@ Message-ID: <%a%@%a%>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
EOD
, TestMailer::$output );
, TestMailer::$output);
10 changes: 5 additions & 5 deletions tests/Mail/Mail.headers.001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Mail\Message invalid headers.
*/

use Nette\Mail\Message,
Tester\Assert;
use Nette\Mail\Message;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -15,14 +15,14 @@ require __DIR__ . '/Mail.inc';

$mail = new Message();

Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
$mail->setHeader('', 'value');
}, 'InvalidArgumentException', "Header name must be non-empty alphanumeric string, '' given.");

Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
$mail->setHeader(' name', 'value');
}, 'InvalidArgumentException', "Header name must be non-empty alphanumeric string, ' name' given.");

Assert::exception(function() use ($mail) {
Assert::exception(function () use ($mail) {
$mail->setHeader('n*ame', 'value');
}, 'InvalidArgumentException', "Header name must be non-empty alphanumeric string, 'n*ame' given.");
8 changes: 4 additions & 4 deletions tests/Mail/Mail.headers.002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Mail\Message valid headers.
*/

use Nette\Mail\Message,
Tester\Assert;
use Nette\Mail\Message;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -31,7 +31,7 @@ $mail->setHeader('X-Gmail-Label', 'love');
$mailer = new TestMailer();
$mailer->send($mail);

Assert::match( <<<EOD
Assert::match(<<<EOD
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
Expand All @@ -48,4 +48,4 @@ Message-ID: <%a%@%a%>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
EOD
, TestMailer::$output );
, TestMailer::$output);
4 changes: 2 additions & 2 deletions tests/Mail/Mail.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Common code for Mail test cases.
*/

use Nette\Mail\Message,
Nette\Mail\IMailer;
use Nette\Mail\Message;
use Nette\Mail\IMailer;


class TestMailer implements IMailer
Expand Down
Loading

0 comments on commit a1034a0

Please sign in to comment.