diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a76a6c015..18ed67ca2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1105,16 +1105,6 @@ parameters: count: 1 path: src/MailerBundle/Factory/MailerConfigFactory.php - - - message: "#^Property SolidInvoice\\\\MailerBundle\\\\Factory\\\\MailerConfigFactory\\:\\:\\$config has no type specified\\.$#" - count: 1 - path: src/MailerBundle/Factory/MailerConfigFactory.php - - - - message: "#^Property SolidInvoice\\\\MailerBundle\\\\Factory\\\\MailerConfigFactory\\:\\:\\$inner has no type specified\\.$#" - count: 1 - path: src/MailerBundle/Factory/MailerConfigFactory.php - - message: "#^Method SolidInvoice\\\\MoneyBundle\\\\Calculator\\:\\:calculateDiscount\\(\\) has parameter \\$entity with no type specified\\.$#" count: 1 diff --git a/src/InvoiceBundle/Tests/Form/Handler/InvoiceEditHandlerTest.php b/src/InvoiceBundle/Tests/Form/Handler/InvoiceEditHandlerTest.php index 1156daca8..6836056bf 100644 --- a/src/InvoiceBundle/Tests/Form/Handler/InvoiceEditHandlerTest.php +++ b/src/InvoiceBundle/Tests/Form/Handler/InvoiceEditHandlerTest.php @@ -20,6 +20,7 @@ use SolidInvoice\CoreBundle\Response\FlashResponse; use SolidInvoice\CoreBundle\Templating\Template; use SolidInvoice\FormBundle\Test\FormHandlerTestCase; +use SolidInvoice\InvoiceBundle\Email\InvoiceEmail; use SolidInvoice\InvoiceBundle\Entity\Invoice; use SolidInvoice\InvoiceBundle\Form\Handler\InvoiceEditHandler; use SolidInvoice\InvoiceBundle\Listener\WorkFlowSubscriber; @@ -92,7 +93,12 @@ public function getHandler(): InvoiceEditHandler ->withAnyArgs() ->andReturn('/invoices/1'); - $handler = new InvoiceEditHandler($stateMachine, $recurringStateMachine, $router, M::mock(MailerInterface::class)); + $mailer = M::mock(MailerInterface::class); + $mailer->shouldReceive('send') + ->zeroOrMoreTimes() + ->with(M::type(InvoiceEmail::class)); + + $handler = new InvoiceEditHandler($stateMachine, $recurringStateMachine, $router, $mailer); $handler->setDoctrine($this->registry); return $handler; diff --git a/src/MailerBundle/Factory/MailerConfigFactory.php b/src/MailerBundle/Factory/MailerConfigFactory.php index b83264f06..11c2d6937 100644 --- a/src/MailerBundle/Factory/MailerConfigFactory.php +++ b/src/MailerBundle/Factory/MailerConfigFactory.php @@ -19,6 +19,7 @@ use SolidInvoice\SettingsBundle\SystemConfig; use Symfony\Component\Mailer\Transport; use Symfony\Component\Mailer\Transport\TransportInterface; +use function json_decode; /** * @see \SolidInvoice\MailerBundle\Tests\Factory\MailerConfigFactoryTest @@ -27,14 +28,14 @@ final class MailerConfigFactory { private const CONFIG_KEY = 'email/sending_options/provider'; - private $config; + private SystemConfig $config; - private $inner; + private Transport $inner; /** * @var ConfiguratorInterface[] */ - private $transports; + private iterable $transports; public function __construct(Transport $inner, SystemConfig $config, iterable $transports) { @@ -48,7 +49,13 @@ public function __construct(Transport $inner, SystemConfig $config, iterable $tr */ public function fromStrings(): TransportInterface { - $config = \json_decode($this->config->get(self::CONFIG_KEY), true, 512, JSON_THROW_ON_ERROR); + $config = $this->config->get(self::CONFIG_KEY); + + if (null === $config) { + return $this->inner->fromString('null://null'); + } + + $config = json_decode($this->config->get(self::CONFIG_KEY), true, 512, JSON_THROW_ON_ERROR); $provider = $config['provider'] ?? ''; foreach ($this->transports as $transport) {