Completed
Push — master ( 70c3fb...bc6738 )
by Simon
01:48
created

PartialSubmissionTaskTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 54.41 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 8
dl 37
loc 68
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testTitle() 0 5 1
A testRun() 0 14 1
A testExtraUser() 19 19 1
A testNoConfigButUser() 18 18 1
A setUp() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: simon
5
 * Date: 10-May-18
6
 * Time: 10:02
7
 */
8
9
namespace Firesphere\PartialUserforms\Tests;
10
11
use Firesphere\PartialUserforms\Tasks\PartialSubmissionTask;
12
use SilverStripe\Control\HTTPRequest;
13
use SilverStripe\Core\Config\Config;
14
use SilverStripe\Core\Injector\Injector;
15
use SilverStripe\Dev\SapphireTest;
16
use SilverStripe\Security\IdentityStore;
17
use SilverStripe\Security\Member;
18
use SilverStripe\Security\Security;
19
use SilverStripe\SiteConfig\SiteConfig;
20
use Symbiote\QueuedJobs\Services\QueuedJobService;
21
22
class PartialSubmissionTaskTest extends SapphireTest
23
{
24
    public function testTitle()
25
    {
26
        $task = Injector::inst()->get(PartialSubmissionTask::class);
27
        $this->assertEquals('Export partial form submissions to email address', $task->getTitle());
28
    }
29
30
    public function testRun()
31
    {
32
        $config = SiteConfig::current_site_config();
33
        $config->SendDailyEmail = true;
34
        $config->SendMailTo = '[email protected]';
35
        $config->write();
36
        $request = new HTTPRequest('GET', 'dev/tasks/partialsubmissiontask');
37
38
        $task = Injector::inst()->get(PartialSubmissionTask::class);
39
40
        $task->run($request);
41
42
        $this->assertEmailSent('[email protected]');
43
    }
44
45 View Code Duplication
    public function testExtraUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $config = SiteConfig::current_site_config();
48
        $config->SendDailyEmail = true;
49
        $config->SendMailTo = '[email protected]';
50
        $config->write();
51
        $rand = uniqid('', false);
52
        $user = Member::create(['FirstName' => 'Test', 'Email' => $rand . '@example.com']);
53
        $user->write();
54
        Security::setCurrentUser($user);
55
        $request = new HTTPRequest('GET', 'dev/tasks/partialsubmissiontask');
56
57
        $task = Injector::inst()->get(PartialSubmissionTask::class);
58
59
        $task->run($request);
60
61
        $this->assertEmailSent($rand . '@example.com');
62
        $this->assertEmailSent('[email protected]');
63
    }
64
65 View Code Duplication
    public function testNoConfigButUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        $rand = uniqid('', false);
68
        $user = Member::create(['FirstName' => 'Test', 'Email' => $rand . '@example.com']);
69
        $user->write();
70
        Security::setCurrentUser($user);
71
        $config = SiteConfig::current_site_config();
72
        $config->SendDailyEmail = true;
73
        $config->write();
74
        $request = new HTTPRequest('GET', 'dev/tasks/partialsubmissiontask');
75
76
        $task = Injector::inst()->get(PartialSubmissionTask::class);
77
78
        $task->run($request);
79
80
        $this->assertEmailSent($rand . '@example.com');
81
82
    }
83
84
    protected function setUp()
85
    {
86
        parent::setUp();
87
        Config::modify()->set(QueuedJobService::class, 'use_shutdown_function', false);
88
    }
89
}
90