Completed
Push — master ( 225222...7d085e )
by Schlaefer
05:18 queued 02:52
created

CronJobTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAll() 0 16 1
A testConstructorWrongDue() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace Cron\Test;
14
15
use Cake\TestSuite\TestCase;
16
use Cron\Lib\CronJob;
17
18
class CronJobTest extends TestCase
19
{
20
    public function testAll()
21
    {
22
        $mock = $this->getMockBuilder('stdClass')
23
            ->setMethods(['callback'])
24
            ->getMock();
25
        $mock->expects($this->once())->method('callback');
26
27
        $due = '+1 day';
28
        $job = new CronJob('foo', $due, [$mock, 'callback']);
29
30
        $this->assertEquals('foo', $job->getUid());
31
        $due = new \DateTimeImmutable($due);
32
        $this->assertWithinRange($due->getTimestamp(), $job->getDue(), 2);
33
34
        $job->execute();
35
    }
36
37
    public function testConstructorWrongDue()
38
    {
39
        $this->expectException(\InvalidArgumentException::class);
40
        $this->expectExceptionCode(1571567221);
41
        new CronJob('foo', 'bar', [$this, '__construct']);
42
    }
43
}
44