Passed
Branch master (947605)
by smiley
03:06
created

DataTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 86
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A bitProvider() 0 10 1
A setUp() 0 3 1
A testMode() 0 4 1
A testWrite() 0 5 1
A testAlphaNumCharException() 0 5 1
A testKanjiCharExceptionA() 0 5 1
A testKanjiCharExceptionB() 0 5 1
A testNumberCharException() 0 5 1
1
<?php
2
/**
3
 *
4
 * @filesource   DataTest.php
5
 * @created      08.02.2016
6
 * @author       Smiley <[email protected]>
7
 * @copyright    2015 Smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\QRCodeTest\Data;
12
13
use chillerlan\QRCode\BitBuffer;
14
use chillerlan\QRCode\QRConst;
15
use chillerlan\QRCode\Data\AlphaNum;
16
use chillerlan\QRCode\Data\Byte;
17
use chillerlan\QRCode\Data\Kanji;
18
use chillerlan\QRCode\Data\Number;
19
20
class DataTest extends \PHPUnit_Framework_TestCase{
21
22
	/**
23
	 * @var \chillerlan\QRCode\BitBuffer
24
	 */
25
	protected $bitBuffer;
26
27
	/**
28
	 * @var \chillerlan\QRCode\Data\QRDataInterface
29
	 */
30
	protected $module;
31
32
	public function bitProvider(){
33
		return [
34
			[QRConst::MODE_NUMBER, Number::class, '123456789'],
35
			[QRConst::MODE_NUMBER, Number::class, '1234567890'],
36
			[QRConst::MODE_NUMBER, Number::class, '12345678901'],
37
			[QRConst::MODE_ALPHANUM, AlphaNum::class, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'],
38
			[QRConst::MODE_BYTE, Byte::class, '#\\'],
39
			[QRConst::MODE_KANJI, Kanji::class, '茗荷'],
40
		];
41
	}
42
43
	protected function setUp(){
44
		$this->bitBuffer = new BitBuffer;
45
	}
46
47
	/**
48
	 * @dataProvider bitProvider
49
	 */
50
	public function testMode($mode, $class, $data){
51
		$this->module = new $class($data);
52
		$this->assertEquals($mode, $this->module->mode);
53
	}
54
55
	/**
56
	 * @dataProvider bitProvider
57
	 */
58
	public function testWrite($mode, $class, $data){
0 ignored issues
show
Unused Code introduced by
The parameter $mode is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
		$this->bitBuffer->clear();
60
		$this->module = new $class($data);
61
		$this->module->write($this->bitBuffer);
62
	}
63
64
	/**
65
	 * @expectedException \chillerlan\QRCode\Data\QRCodeDataException
66
	 * @expectedExceptionMessage illegal char: 92
67
	 */
68
	public function testAlphaNumCharException(){
69
		$this->bitBuffer->clear();
70
		$this->module = new AlphaNum('\\');
71
		$this->module->write($this->bitBuffer);
72
	}
73
74
	/**
75
	 * @expectedException \chillerlan\QRCode\Data\QRCodeDataException
76
	 * @expectedExceptionMessage illegal char at 7 (50051)
77
	 */
78
	public function testKanjiCharExceptionA(){
79
		$this->bitBuffer->clear();
80
		$this->module = new Kanji('茗荷Ã');
81
		$this->module->write($this->bitBuffer);
82
	}
83
84
	/**
85
	 * @expectedException \chillerlan\QRCode\Data\QRCodeDataException
86
	 * @expectedExceptionMessage illegal char at 7
87
	 */
88
	public function testKanjiCharExceptionB(){
89
		$this->bitBuffer->clear();
90
		$this->module = new Kanji('茗荷\\');
91
		$this->module->write($this->bitBuffer);
92
	}
93
94
	/**
95
	 * @expectedException \chillerlan\QRCode\Data\QRCodeDataException
96
	 * @expectedExceptionMessage illegal char: 92
97
	 */
98
	public function testNumberCharException(){
99
		$this->bitBuffer->clear();
100
		$this->module = new Number('\\');
101
		$this->module->write($this->bitBuffer);
102
	}
103
104
105
}
106