Completed
Pull Request — master (#16)
by Tonina
121:52 queued 57:20
created

CampaignTest::returnRandomBucket()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types = 1).
Loading history...
2
3
namespace WMDE\BannerServer\Tests\Unit\Entity\BannerSelection;
4
5
use WMDE\BannerServer\Entity\BannerSelection\Campaign;
6
use WMDE\BannerServer\Entity\BannerSelection\TrafficImpressionThreshold;
7
8
class CampaignTest extends \PHPUnit\Framework\TestCase {
9
10
	public static function returnRandomBucket( $buckets ) {
0 ignored issues
show
introduced by
Method \WMDE\BannerServer\Tests\Unit\Entity\BannerSelection\CampaignTest::returnRandomBucket() does not have parameter type hint nor @param annotation for its parameter $buckets.
Loading history...
introduced by
Method \WMDE\BannerServer\Tests\Unit\Entity\BannerSelection\CampaignTest::returnRandomBucket() does not have return type hint nor @return annotation for its return value.
Loading history...
11
		return $buckets[0];
12
	}
13
14
	public function test_given_time_out_of_date_range_campaign_is_not_active() {
15
		$campaign = new Campaign(
16
			'C18_WMDE_Test',
17
			new \DateTime( '2018-10-01 14:00:00' ),
18
			new \DateTime( '2018-10-31 14:00:00' ),
19
			[],
20
			new TrafficImpressionThreshold( 10, 10 )
21
		);
22
		$this->assertTrue(
23
			$campaign->isInActiveDateRange( new \DateTime( '2018-10-20 14:00:00' ) ),
24
			'date given is between the start and the end of the campaign'
25
		);
26
	}
27
28
	public function test_given_time_the_date_range_campaign_is_active() {
29
		$campaign = new Campaign(
30
			'C18_WMDE_Test',
31
			new \DateTime( '2018-10-01 14:00:00' ),
32
			new \DateTime( '2018-10-31 14:00:00' ),
33
			[],
34
			new TrafficImpressionThreshold( 10, 10 )
35
		);
36
		$this->assertFalse(
37
			$campaign->isInActiveDateRange( new \DateTime( '2018-09-22 14:00:00' ) ),
38
			'date given is before the start of the campaign'
39
		);
40
	}
41
42
	public function test_given_valid_bucket_id_returns_bucket() {
43
		$campaign = new Campaign(
44
			'C18_WMDE_Test',
45
			new \DateTime( '2018-10-01 14:00:00' ),
46
			new \DateTime( '2018-10-31 14:00:00' ),
47
			[],
48
			new TrafficImpressionThreshold( 10, 10 )
49
		);
50
		$this->assertEquals(
51
			$campaign->selectBucket( 'C18_WMDE_Test_var', [CampaignTest::class, 'returnRandomBucket'] ),
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
52
			'C18_WMDE_Test_var'
53
		);
54
	}
55
56
	public function test_given_invalid_bucket_id_returns_random_bucket() {
57
		$campaign = new Campaign(
58
			'C18_WMDE_Test',
59
			new \DateTime( '2018-10-01 14:00:00' ),
60
			new \DateTime( '2018-10-31 14:00:00' ),
61
			[],
62
			new TrafficImpressionThreshold( 10, 10 )
63
		);
64
		$this->assertEquals(
65
			$campaign->selectBucket( 9999, [CampaignTest::class, 'returnRandomBucket'] ),
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
66
			''
67
		);
68
	}
69
70
	public function test_given_no_bucket_id_returns_random_bucket() {
71
		$campaign = new Campaign(
72
			'C18_WMDE_Test',
73
			new \DateTime( '2018-10-01 14:00:00' ),
74
			new \DateTime( '2018-10-31 14:00:00' ),
75
			[],
76
			new TrafficImpressionThreshold( 10, 10 )
77
		);
78
		$this->assertEquals(
79
			$campaign->selectBucket( null, [CampaignTest::class, 'returnRandomBucket'] ),
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
80
			''
81
		);
82
	}
83
}
84