summaryrefslogtreecommitdiff
path: root/vendor/chillerlan/php-qrcode/tests/Output/QRImageTest.php
blob: c4466a658f954b8d58b45de63739d3e92fe2a117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
 * Class QRImageTest
 *
 * @filesource   QRImageTest.php
 * @created      24.12.2017
 * @package      chillerlan\QRCodeTest\Output
 * @author       Smiley <[email protected]>
 * @copyright    2017 Smiley
 * @license      MIT
 */

namespace chillerlan\QRCodeTest\Output;

use chillerlan\QRCode\{QRCode, Output\QRImage};
use const PHP_MAJOR_VERSION;

class QRImageTest extends QROutputTestAbstract{

	protected $FQCN = QRImage::class;

	public function types(){
		return [
			'png' => [QRCode::OUTPUT_IMAGE_PNG],
			'gif' => [QRCode::OUTPUT_IMAGE_GIF],
			'jpg' => [QRCode::OUTPUT_IMAGE_JPG],
		];
	}

	/**
	 * @dataProvider types
	 * @param $type
	 */
	public function testImageOutput($type){
		$this->options->outputType  = $type;
		$this->options->imageBase64 = false;

		$this->setOutputInterface();
		$this->outputInterface->dump($this::cachefile.$type);
		$img = $this->outputInterface->dump();

		if($type === QRCode::OUTPUT_IMAGE_JPG){ // jpeg encoding may cause different results
			$this->markAsRisky();
		}

		$this->assertSame($img, file_get_contents($this::cachefile.$type));
	}

	public function testSetModuleValues(){

		$this->options->moduleValues = [
			// data
			1024 => [0, 0, 0],
			4    => [255, 255, 255],
		];

		$this->setOutputInterface()->dump();

		$this->assertTrue(true); // tricking the code coverage
	}

	public function testOutputGetResource():void{
		$this->options->returnResource = true;

		$this->setOutputInterface();

		$data = $this->outputInterface->dump();

		if(PHP_MAJOR_VERSION >= 8){
			$this::assertInstanceOf('\\GdImage', $data);
		}
		else{
			$this::assertIsResource($data);
		}
	}

}