Completed
Push — master ( cebd6a...4982e0 )
by Simon
01:36
created

PartialSubmissionJobTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 38.89 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 6
dl 28
loc 72
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetTitle() 0 4 1
A testProcess() 0 12 1
A testIsSend() 13 13 1
A testIsDeleted() 15 15 1
A setUp() 0 10 1
A tearDown() 0 4 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
namespace Firesphere\PartialUserforms\Tests;
4
5
use Firesphere\PartialUserforms\Jobs\PartialSubmissionJob;
6
use Firesphere\PartialUserforms\Models\PartialFormSubmission;
7
use SilverStripe\Core\Config\Config;
8
use SilverStripe\Core\Injector\Injector;
9
use SilverStripe\Dev\SapphireTest;
10
use SilverStripe\ORM\FieldType\DBDatetime;
11
use SilverStripe\SiteConfig\SiteConfig;
12
use Symbiote\QueuedJobs\Services\QueuedJobService;
13
14
class PartialSubmissionJobTest extends SapphireTest
15
{
16
    protected static $fixture_file = '../fixtures/submission.yml';
17
    /**
18
     * @var PartialSubmissionJob
19
     */
20
    protected $job;
21
22
    public function testGetTitle()
23
    {
24
        $this->assertEquals('Export partial submissions to Email', $this->job->getTitle());
25
    }
26
27
    public function testProcess()
28
    {
29
        $this->assertTrue(method_exists($this->job, 'process'));
30
        $config = SiteConfig::current_site_config();
31
        $config->SendDailyEmail = true;
32
        $config->SendMailTo = '[email protected]';
33
        $config->write();
34
        $this->job->process();
35
36
        $this->assertEmailSent('[email protected]');
37
        $this->assertFileExists('/tmp/Export of TestForm - 2018-01-01 12:00:00.csv');
38
    }
39
40 View Code Duplication
    public function testIsSend()
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...
41
    {
42
        $submission = $this->objFromFixture(PartialFormSubmission::class, 'submission1');
43
        $config = SiteConfig::current_site_config();
44
        $config->SendDailyEmail = true;
45
        $config->SendMailTo = '[email protected]';
46
        $config->write();
47
        $this->job->process();
48
49
        $processedSubmission = $submission->get()->byID($submission->ID);
50
51
        $this->assertTrue($processedSubmission->IsSend);
52
    }
53
54 View Code Duplication
    public function testIsDeleted()
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...
55
    {
56
        $submission = $this->objFromFixture(PartialFormSubmission::class, 'submission1');
57
        $config = SiteConfig::current_site_config();
58
        $config->SendDailyEmail = true;
59
        $config->CleanupAfterSend = true;
60
        $config->SendMailTo = '[email protected]';
61
        $config->write();
62
        $this->job->process();
63
64
        $processedSubmission = $submission->get()->byID($submission->ID);
65
66
        $this->assertNull($processedSubmission);
67
68
    }
69
70
    protected function setUp()
71
    {
72
        $this->usesDatabase = true;
73
        Config::modify()->set(QueuedJobService::class, 'use_shutdown_function', false);
74
        DBDatetime::set_mock_now('2018-01-01 12:00:00');
75
        /** @var PartialSubmissionJob $job */
76
        $this->job = Injector::inst()->get(PartialSubmissionJob::class);
77
78
        return parent::setUp();
79
    }
80
81
    protected function tearDown()
82
    {
83
        parent::tearDown(); // TODO: Change the autogenerated stub
84
    }
85
}
86