Passed
Pull Request — master (#19)
by Tim
05:32
created

BannerSelectionUseCaseTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_given_one_percent_ratio_then_limit_is_applied_for_two_percent_rng() 0 11 1
A test_given_max_percentage_then_limit_is_not_applied() 0 12 1
A test_given_one_percent_ratio_then_limit_is_not_applied_for_one_percent_rng() 0 12 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\BannerServer\Tests\Unit\UseCase\BannerSelection;
6
7
use WMDE\BannerServer\Entity\BannerSelection\ImpressionThreshold;
8
use WMDE\BannerServer\Tests\Fixtures\CampaignFixture;
9
use WMDE\BannerServer\Tests\Fixtures\VisitorFixture;
10
use WMDE\BannerServer\Tests\Utils\FakeRandomIntegerGenerator;
11
use WMDE\BannerServer\UseCase\BannerSelection\BannerSelectionUseCase;
12
use WMDE\BannerServer\Utils\SystemRandomIntegerGenerator;
13
14
/**
15
 * @covers \WMDE\BannerServer\UseCase\BannerSelection\BannerSelectionUseCase
16
 * Class BannerSelectionControllerTest
17
 *
18
 * @package WMDE\BannerServer\Tests\Unit\UseCase
19
 */
20
class BannerSelectionUseCaseTest extends \PHPUnit\Framework\TestCase {
21
	public function test_given_max_percentage_then_limit_is_not_applied() {
22
		$useCase = new BannerSelectionUseCase(
23
			CampaignFixture::getTrueRandomTestCampaignCollection( 100 ),
24
			new ImpressionThreshold( 10 ),
25
			new SystemRandomIntegerGenerator()
26
		);
27
28
		$bannerSelectionData = $useCase->provideBannerRequest( VisitorFixture::getFirstTimeVisitor() );
29
		$this->assertEquals( 'test', $bannerSelectionData->getVisitorData()->getBucketIdentifier() );
30
		$this->assertEquals( 1, $bannerSelectionData->getVisitorData()->getTotalImpressionCount() );
31
		$this->assertEquals( 'TestBanner', $bannerSelectionData->getBannerIdentifier() );
32
		$this->assertEquals( CampaignFixture::getTestCampaignEndDate(), $bannerSelectionData->getCampaignEnd() );
33
	}
34
35
	public function test_given_one_percent_ratio_then_limit_is_not_applied_for_one_percent_rng() {
36
		$useCase = new BannerSelectionUseCase(
37
			CampaignFixture::getTrueRandomTestCampaignCollection( 1 ),
38
			new ImpressionThreshold( 10 ),
39
			new FakeRandomIntegerGenerator( 1 )
40
		);
41
42
		$bannerSelectionData = $useCase->provideBannerRequest( VisitorFixture::getFirstTimeVisitor() );
43
		$this->assertEquals( 'test', $bannerSelectionData->getVisitorData()->getBucketIdentifier() );
44
		$this->assertEquals( 1, $bannerSelectionData->getVisitorData()->getTotalImpressionCount() );
45
		$this->assertEquals( 'TestBanner', $bannerSelectionData->getBannerIdentifier() );
46
		$this->assertEquals( CampaignFixture::getTestCampaignEndDate(), $bannerSelectionData->getCampaignEnd() );
47
	}
48
49
	public function test_given_one_percent_ratio_then_limit_is_applied_for_two_percent_rng() {
50
		$useCase = new BannerSelectionUseCase(
51
			CampaignFixture::getTrueRandomTestCampaignCollection( 1 ),
52
			new ImpressionThreshold( 10 ),
53
			new FakeRandomIntegerGenerator( 2 )
54
		);
55
56
		$bannerSelectionData = $useCase->provideBannerRequest( VisitorFixture::getFirstTimeVisitor() );
57
		$this->assertEquals( false, $bannerSelectionData->displayBanner() );
58
		$this->assertEquals( null, $bannerSelectionData->getVisitorData()->getBucketIdentifier() );
59
		$this->assertEquals( 0, $bannerSelectionData->getVisitorData()->getTotalImpressionCount() );
60
	}
61
}