PagePropsIdGeneratorTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testIncrementsIdByOne() 0 8 1
A testIncrementsNamedId() 0 8 1
A newGenerator() 0 6 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace IdGenerator\Tests;
6
7
use IdGenerator\IdGenerator;
8
use IdGenerator\PackagePrivate\DatabaseIdGenerator;
9
use IdGenerator\PackagePrivate\PagePropsIdDatabase;
10
use MediaWiki\MediaWikiServices;
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * @ingroup Database
15
 * @covers \IdGenerator\PackagePrivate\DatabaseIdGenerator
16
 * @covers \IdGenerator\PackagePrivate\PagePropsIdDatabase
17
 */
18
class PagePropsIdGeneratorTest extends TestCase {
19
20
	public function testIncrementsIdByOne() {
21
		$generator = $this->newGenerator();
22
23
		$this->assertSame(
24
			$generator->getNewId() + 1,
25
			$generator->getNewId()
26
		);
27
	}
28
29
	public function testIncrementsNamedId() {
30
		$generator = $this->newGenerator();
31
32
		$this->assertSame(
33
			$generator->getNewId( 'TestName' ) + 1,
34
			$generator->getNewId( 'TestName' )
35
		);
36
	}
37
38
	private function newGenerator(): IdGenerator {
39
		return new DatabaseIdGenerator(
40
			MediaWikiServices::getInstance()->getDBLoadBalancer(),
41
			new PagePropsIdDatabase()
42
		);
43
	}
44
45
}
46