Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
[TASK] Add code coverage for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Jan 27, 2020
1 parent d1aea7f commit 2203be5
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
coverage_clover: coverage.xml
json_path: coverage.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.php_cs
.php_cs.cache
composer.lock
phpunit.xml
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 7.0
- 7.1
- 7.2
- 7.3

env:
- TYPO3_VERSION="^8.7.0"
Expand Down Expand Up @@ -35,25 +36,27 @@ notifications:
before_install:
- composer self-update
- composer --version
- phpenv config-rm xdebug.ini || return 0

before_script:
- |
# Remove Xdebug for a huge performance increase:
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
phpenv config-rm xdebug.ini
else
echo "xdebug.ini does not exist"
fi
- composer require typo3/minimal=$TYPO3_VERSION
# Restore composer.json
- git checkout composer.json
- export TYPO3_PATH_WEB=$PWD/.Build/Web
- mv phpunit.xml.dist phpunit.xml

script:
- >
echo;
echo "Running unit tests";
.Build/bin/phpunit --colors -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit/
.Build/bin/phpunit --colors -c phpunit.xml
- >
echo;
echo "Test coverage";
phpdbg -qrr -d memory_limit=-1 .Build/bin/phpunit -c phpunit.xml --coverage-clover coverage.xml;
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar;
php php-coveralls.phar --verbose
- >
echo;
Expand Down
3 changes: 3 additions & 0 deletions Classes/Aspect/SingleRecipientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

final class SingleRecipientAspect
{
/**
* @var \Swift_Events_SendListener
*/
private $plugin;

public function __construct(SingleRecipientPluginFactory $singleRecipientPluginFactory)
Expand Down
15 changes: 12 additions & 3 deletions Classes/Configuration/SingleRecipientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@
use Ssch\SwiftmailerSingleRecipient\ValueObject\EmailAddress;
use Webmozart\Assert\Assert;

final class SingleRecipientConfiguration
/**
* @final
*/
class SingleRecipientConfiguration
{
/**
* @var array|EmailAddress[]
*/
private $singleRecipients;

/**
* @var array|EmailAddress[]
*/
private $whitelist;

/**
Expand All @@ -46,14 +55,14 @@ public function isValid(): bool

public function getSingleRecipients(): array
{
return array_map(function (EmailAddress $emailAddress) {
return array_map(static function (EmailAddress $emailAddress) {
return (string)$emailAddress;
}, $this->singleRecipients);
}

public function getWhitelist(): array
{
return array_map(function (EmailAddress $emailAddress) {
return array_map(static function (EmailAddress $emailAddress) {
return (string)$emailAddress;
}, $this->whitelist);
}
Expand Down
17 changes: 13 additions & 4 deletions Classes/Configuration/SingleRecipientConfigurationFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

/*
* This file is part of the TYPO3 CMS project.
Expand All @@ -20,10 +20,19 @@
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

final class SingleRecipientConfigurationFactory implements SingletonInterface
/**
* @final
*/
class SingleRecipientConfigurationFactory implements SingletonInterface
{
/**
* @var SingleRecipientConfiguration
*/
private $configuration;

/**
* @var array
*/
private $extensionConfiguration;

public function __construct(array $extensionConfiguration = null)
Expand All @@ -39,7 +48,7 @@ public function __construct(array $extensionConfiguration = null)

public function getConfiguration(): SingleRecipientConfiguration
{
if ( ! $this->configuration instanceof SingleRecipientConfiguration) {
if (! $this->configuration instanceof SingleRecipientConfiguration) {
$this->configuration = new SingleRecipientConfiguration(
$this->transformListToEmailAddressArrayIfKeyExists('single_recipient'),
$this->transformListToEmailAddressArrayIfKeyExists('whitelist')
Expand All @@ -53,7 +62,7 @@ private function transformListToEmailAddressArrayIfKeyExists(string $key): array
{
if (array_key_exists($key, $this->extensionConfiguration) && $this->extensionConfiguration[$key] !== '') {
try {
return array_map(function ($email) {
return array_map(static function ($email) {
return new EmailAddress($email);
}, GeneralUtility::trimExplode(',', $this->extensionConfiguration[$key]));
} catch (\InvalidArgumentException $e) {
Expand Down
4 changes: 4 additions & 0 deletions Classes/Mailer/SingleRecipientPluginFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
* The TYPO3 project - inspiring people to share!
*/

use Ssch\SwiftmailerSingleRecipient\Configuration\SingleRecipientConfiguration;
use Ssch\SwiftmailerSingleRecipient\Configuration\SingleRecipientConfigurationFactory;
use Ssch\SwiftmailerSingleRecipient\Mailer\Plugins\NullPlugin;
use Swift_Events_SendListener;
use Swift_Plugins_RedirectingPlugin;

final class SingleRecipientPluginFactory
{
/**
* @var SingleRecipientConfiguration
*/
private $configuration;

public function __construct(SingleRecipientConfigurationFactory $factory)
Expand Down
3 changes: 3 additions & 0 deletions Classes/ValueObject/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

final class EmailAddress
{
/**
* @var string
*/
private $email;

public function __construct(string $email)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/sabbelasichon/swiftmailer_single_recipient.png)](https://travis-ci.org/sabbelasichon/swiftmailer_single_recipient)
[![Build Status](https://img.shields.io/travis/sabbelasichon/swiftmailer_single_recipient/master.svg?style=flat-square)](https://travis-ci.org/sabbelasichon/swiftmailer_single_recipient)
[![Coverage Status](https://img.shields.io/coveralls/sabbelasichon/swiftmailer_single_recipient/master.svg?style=flat-square)](https://coveralls.io/github/sabbelasichon/swiftmailer_single_recipient?branch=master)

How to Work with Emails during Development
==========================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function isInValidConfigurationViaGlobals()
$this->assertFalse($configuration->isValid());
}


/**
* @test
*/
Expand Down
55 changes: 54 additions & 1 deletion Tests/Unit/Mailer/SingleRecipientPluginFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,62 @@

namespace Ssch\SwiftmailerSingleRecipient\Tests\Unit\Mailer;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use Nimut\TestingFramework\TestCase\UnitTestCase;
use Ssch\SwiftmailerSingleRecipient\Configuration\SingleRecipientConfiguration;
use Ssch\SwiftmailerSingleRecipient\Configuration\SingleRecipientConfigurationFactory;
use Ssch\SwiftmailerSingleRecipient\Mailer\Plugins\NullPlugin;
use Ssch\SwiftmailerSingleRecipient\Mailer\SingleRecipientPluginFactory;

class SingleRecipientPluginFactoryTest extends \PHPUnit_Framework_TestCase
class SingleRecipientPluginFactoryTest extends UnitTestCase
{
/**
* @var SingleRecipientPluginFactory
*/
protected $subject;

/**
* @var SingleRecipientConfiguration
*/
private $configuration;

protected function setUp()
{
$this->configuration = $this->prophesize(SingleRecipientConfiguration::class);
$singleRecipientConfigurationFactory = $this->prophesize(SingleRecipientConfigurationFactory::class);
$singleRecipientConfigurationFactory->getConfiguration()->willReturn($this->configuration);
$this->subject = new SingleRecipientPluginFactory($singleRecipientConfigurationFactory->reveal());
}

/**
* @test
*/
public function returnsNullPluginDueToInvalidConfiguration()
{
$this->configuration->isValid()->willReturn(false);
$this->assertInstanceOf(NullPlugin::class, $this->subject->getPlugin());
}

/**
* @test
*/
public function returnsSwiftPluginsRedirectingPlugin()
{
$this->configuration->isValid()->willReturn(true);
$this->configuration->getSingleRecipients()->willReturn([]);
$this->configuration->getWhitelist()->willReturn([]);
$this->assertInstanceOf(\Swift_Plugins_RedirectingPlugin::class, $this->subject->getPlugin());
}
}
18 changes: 18 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.1/phpunit.xsd"
bootstrap=".Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php"
colors="true"
forceCoversAnnotation="true"
stopOnRisky="true">
<testsuites>
<testsuite name="small">
<directory>./Tests/Unit/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./Classes</directory>
</whitelist>
</filter>
</phpunit>

0 comments on commit 2203be5

Please sign in to comment.