Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to SF 3/4 #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .php_cs

This file was deleted.

24 changes: 24 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

function recur_ksort(&$array) {
foreach ($array as &$value) {
if (is_array($value)) recur_ksort($value);
}
return ksort($array);
}

$rules = json_decode(file_get_contents('.php_cs.rules.json'), true);

recur_ksort($rules);

file_put_contents('.php_cs.rules.json', json_encode($rules, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules($rules)
->setUsingCache(false)
->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers())
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__))
;

return $config;
56 changes: 56 additions & 0 deletions .php_cs.rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"@Symfony": true,
"@Symfony:risky": true,
"PedroTroller/forbidden_functions": {
"comment": "@TODO remove it",
"functions": [
"dump",
"var_dump"
]
},
"PedroTroller/line_break_between_method_arguments": {
"max-args": 4,
"max-length": 80
},
"PedroTroller/line_break_between_statements": true,
"PedroTroller/phpspec": true,
"PedroTroller/single_line_comment": {
"action": "expanded"
},
"align_multiline_comment": true,
"array_syntax": {
"syntax": "short"
},
"binary_operator_spaces": {
"operators": {
"=": "align_single_space_minimal",
"=>": "align_single_space_minimal"
}
},
"blank_line_before_statement": true,
"combine_consecutive_issets": true,
"combine_consecutive_unsets": true,
"compact_nullable_typehint": true,
"general_phpdoc_annotation_remove": true,
"heredoc_to_nowdoc": true,
"linebreak_after_opening_tag": true,
"list_syntax": {
"syntax": "long"
},
"mb_str_functions": true,
"no_multiline_whitespace_before_semicolons": true,
"no_null_property_initialization": true,
"no_superfluous_elseif": true,
"no_useless_else": true,
"no_useless_return": true,
"ordered_class_elements": true,
"ordered_imports": true,
"phpdoc_add_missing_param_annotation": {
"only_untyped": true
},
"phpdoc_order": true,
"phpdoc_types_order": true,
"self_accessor": false,
"semicolon_after_instruction": true,
"single_line_comment_style": true
}
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
],
"require": {
"doctrine/collections": "~1.0",
"swiftmailer/swiftmailer": "~5.0",
"symfony/config": "~2.4",
"symfony/dependency-injection": "~2.4",
"symfony/framework-bundle": "~2.4",
"symfony/http-kernel": "~2.4",
"symfony/security-bundle": "~2.0",
"symfony/twig-bundle": "~2.4"
"swiftmailer/swiftmailer": "~6.0",
"symfony/config": "~3.0 | ~4.0",
"symfony/dependency-injection": "~3.0 | ~4.0",
"symfony/framework-bundle": "~3.0 | ~4.0",
"symfony/http-kernel": "~3.0 | ~4.0",
"symfony/security-bundle": "~3.0 | ~4.0",
"symfony/twig-bundle": "~3.0 | ~4.0"
},
"require-dev": {
"knplabs/phpspec-welldone-extension": "~1.0",
"phpspec/phpspec": "^2.3"
"pedrotroller/php-cs-custom-fixer": "^2.2",
"phpspec/phpspec": "^4.2"
},
"autoload": {
"psr-0": {
"Knp\\UniMail": "src/"
}
},
"config": {
"bin-dir": "bin"
"sort-packages": "true"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "2.0.x-dev"
}
}
}
2 changes: 0 additions & 2 deletions phpspec.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace spec\Knp\Rad\Mailer\AttachmentFactory;
namespace spec\Knp\UniMail\AttachmentFactory;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class LocalAttachmentFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Knp\Rad\Mailer\AttachmentFactory\LocalAttachmentFactory');
$this->shouldHaveType('Knp\UniMail\AttachmentFactory\LocalAttachmentFactory');
}

function it_supports_existing_files()
Expand All @@ -22,7 +21,6 @@ function it_creates_attachment_from_file()
{
$this
->createAttachment('foo', __FILE__)
->shouldHaveType('Swift_Mime_MimeEntity')
;
->shouldHaveType('Swift_Mime_MimeEntity');
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace spec\Knp\Rad\Mailer\AttachmentFactory;
namespace spec\Knp\UniMail\AttachmentFactory;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class RemoteAttachmentFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Knp\Rad\Mailer\AttachmentFactory\RemoteAttachmentFactory');
$this->shouldHaveType('Knp\UniMail\AttachmentFactory\RemoteAttachmentFactory');
}

function it_supports_existing_urls()
Expand All @@ -22,7 +21,6 @@ function it_creates_attachment_from_file()
{
$this
->createAttachment('foo', 'http://symfony.com/pdf/Symfony_book_2.7.pdf?v=4')
->shouldHaveType('Swift_Mime_MimeEntity')
;
->shouldHaveType('Swift_Mime_MimeEntity');
}
}
29 changes: 13 additions & 16 deletions spec/Knp/UniMail/MailFactory/ConfigurationAwareFactorySpec.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace spec\Knp\Rad\Mailer\MailFactory;
namespace spec\Knp\UniMail\MailFactory;

use Knp\Rad\Mailer\Mail;
use Knp\Rad\Mailer\MailFactory;
use Knp\UniMail\Mail;
use Knp\UniMail\MailFactory;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ConfigurationAwareFactorySpec extends ObjectBehavior
{
Expand All @@ -15,40 +14,38 @@ function let(MailFactory $factory)
'the_mail' => [
'from' => '[email protected]',
'to' => '[email protected]',
]
],
];

$this->beConstructedWith($configuration, $factory);
}

function it_is_initializable()
{
$this->shouldHaveType('Knp\Rad\Mailer\MailFactory\ConfigurationAwareFactory');
$this->shouldHaveType('Knp\UniMail\MailFactory\ConfigurationAwareFactory');
}

function it_instantiate_a_new_mail_with_configuration($factory, Mail $mail)
{
$factory
->createMail('the_mail', ['from' => '[email protected]', 'to' => '[email protected]'])
->willReturn($mail)
;
->willReturn($mail);

$this
->createMail('the_mail', ['from' => '[email protected]'])
->shouldReturn($mail)
;
->shouldReturn($mail);
}

function it_instantiate_a_new_mail_without_configuration($factory, Mail $mail)
{
function it_instantiate_a_new_mail_without_configuration(
$factory,
Mail $mail
) {
$factory
->createMail('the_other_mail', ['from' => '[email protected]'])
->willReturn($mail)
;
->willReturn($mail);

$this
->createMail('the_other_mail', ['from' => '[email protected]'])
->shouldReturn($mail)
;
->shouldReturn($mail);
}
}
38 changes: 16 additions & 22 deletions spec/Knp/UniMail/Mailer/EventDispatcherMailerSpec.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace spec\Knp\Rad\Mailer\Mailer;
namespace spec\Knp\UniMail\Mailer;

use Knp\Rad\Mailer\Mail;
use Knp\Rad\Mailer\Mail\SwiftMail;
use Knp\Rad\Mailer\Mailer;
use Knp\Rad\Mailer\MailerEvents;
use Knp\UniMail\Mail;
use Knp\UniMail\Mail\SwiftMail;
use Knp\UniMail\Mailer;
use Knp\UniMail\MailerEvents;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand All @@ -19,21 +19,19 @@ function let(Mailer $wrapped, EventDispatcherInterface $dispatcher)

function it_is_initializable()
{
$this->shouldHaveType('Knp\Rad\Mailer\Mailer\EventDispatcherMailer');
$this->shouldHaveType('Knp\UniMail\Mailer\EventDispatcherMailer');
}

function it_ask_to_wrapped_mailer_to_create_a_mail($wrapped, Mail $mail)
{
$wrapped
->createMail('name', ['template' => 'the template'])
->shouldBeCalled()
->willReturn($mail)
;
->willReturn($mail);

$this
->createMail('name', ['template' => 'the template'])
->shouldReturn($mail)
;
->shouldReturn($mail);
}

function it_dispatchs_events_when_a_mail_is_sent($wrapped, $dispatcher)
Expand All @@ -43,42 +41,38 @@ function it_dispatchs_events_when_a_mail_is_sent($wrapped, $dispatcher)
$dispatcher
->dispatch(
MailerEvents::PRE_SEND,
Argument::that(function($e) use ($mail) {
Argument::that(function ($e) use ($mail) {
return $mail === $e->getMail();
})
)
->shouldBeCalled()
;
->shouldBeCalled();

$dispatcher
->dispatch(
MailerEvents::preSend($mail),
Argument::that(function($e) use ($mail) {
Argument::that(function ($e) use ($mail) {
return $mail === $e->getMail();
})
)
->shouldBeCalled()
;
->shouldBeCalled();

$dispatcher
->dispatch(
MailerEvents::POST_SEND,
Argument::that(function($e) use ($mail) {
Argument::that(function ($e) use ($mail) {
return $mail === $e->getMail();
})
)
->shouldBeCalled()
;
->shouldBeCalled();

$dispatcher
->dispatch(
MailerEvents::postSend($mail),
Argument::that(function($e) use ($mail) {
Argument::that(function ($e) use ($mail) {
return $mail === $e->getMail();
})
)
->shouldBeCalled()
;
->shouldBeCalled();

$wrapped->sendMail($mail)->shouldBeCalled();

Expand Down
4 changes: 4 additions & 0 deletions src/Knp/UniMail/AttachmentFactory/ChainAttachmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(array $factories)
{
$this->factories = $factories;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -48,12 +49,15 @@ public function createAttachment($name, $content)
switch (true) {
case is_array($content):
$message = sprintf($message, 'an', 'array');

break;
case is_object($content):
$message = sprintf($message, 'object', get_class($content));

break;
default:
$message = sprintf($message, gettype($content), $content);

break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function supports($content)
return false;
}

return false === strpos($headers[0], '404');
return false === mb_strpos($headers[0], '404');
}

/**
Expand Down
Loading