Skip to content

Commit b519dff

Browse files
author
Corey McCormick
committed
Wipe out old unit tests and prepare github actions
1 parent 57acf2f commit b519dff

14 files changed

Lines changed: 137 additions & 167 deletions

File tree

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PHP Composer
1+
name: Unit Tests
22

33
on:
44
push:

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"SimpleSoftwareIO\\QrCode\\": "src"
2828
}
2929
},
30+
"scripts": {
31+
"test": "phpunit"
32+
},
3033
"extra": {
3134
"laravel": {
3235
"providers": [

phpunit.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
>
1312
<testsuites>
1413
<testsuite name="Application Test Suite">

src/SimpleSoftwareIO/QrCode/DataTypes/BTC.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ class BTC implements DataTypeInterface
1111
*/
1212
protected $prefix = 'bitcoin:';
1313

14-
/**
15-
* The separator between the variables.
16-
*
17-
* @var string
18-
*/
19-
protected $separator = '&';
20-
2114
/**
2215
* The BitCoin address.
2316
*
@@ -123,7 +116,7 @@ protected function buildBitCoinString()
123116
$query = http_build_query([
124117
'amount' => $this->amount,
125118
'label' => $this->label,
126-
'$message' => $this->message,
119+
'message' => $this->message,
127120
'r' => $this->returnAddress,
128121
]);
129122

src/SimpleSoftwareIO/QrCode/Generator.php

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,86 @@ class Generator
5656

5757
protected $gradient;
5858

59+
/**
60+
* Holds an image string that will be merged with the QrCode.
61+
*
62+
* @var null|string
63+
*/
64+
protected $imageMerge = null;
65+
66+
/**
67+
* The percentage that a merged image should take over the source image.
68+
*
69+
* @var float
70+
*/
71+
protected $imagePercentage = .2;
72+
73+
/**
74+
* Creates a new datatype object and then generates a QrCode.
75+
*
76+
* @param $method
77+
* @param $arguments
78+
*/
79+
public function __call($method, $arguments)
80+
{
81+
$dataType = $this->createClass($method);
82+
$dataType->create($arguments);
83+
84+
return $this->generate(strval($dataType));
85+
}
86+
5987
public function generate(string $text, string $filename = null)
6088
{
61-
$render = $this->getRenderer();
89+
$qrCode = $this->getWriter($this->getRenderer())->writeString($text, $this->encoding, $this->errorCorrection);
90+
91+
if ($this->imageMerge !== null && $this->format === 'png') {
92+
$merger = new ImageMerge(new Image($qrCode), new Image($this->imageMerge));
93+
$qrCode = $merger->merge($this->imagePercentage);
94+
}
95+
96+
if ($filename) {
97+
file_put_contents($filename, $qrCode);
98+
return;
99+
}
100+
101+
return $qrCode;
102+
}
103+
104+
/**
105+
* Merges an image with the center of the QrCode.
106+
*
107+
* @param $filepath string The filepath to an image
108+
* @param $percentage float The amount that the merged image should be placed over the qrcode.
109+
* @param $absolute boolean Whether to use an absolute filepath or not.
110+
*
111+
* @return $this
112+
*/
113+
public function merge($filepath, $percentage = .2, $absolute = false)
114+
{
115+
if (function_exists('base_path') && !$absolute) {
116+
$filepath = base_path().$filepath;
117+
}
118+
119+
$this->imageMerge = file_get_contents($filepath);
120+
$this->imagePercentage = $percentage;
62121

63-
return $this->getWriter($render)->writeString($text, $this->encoding, $this->errorCorrection);
122+
return $this;
123+
}
124+
125+
/**
126+
* Merges an image string with the center of the QrCode, does not check for correct format.
127+
*
128+
* @param $content string The string contents of an image.
129+
* @param $percentage float The amount that the merged image should be placed over the qrcode.
130+
*
131+
* @return $this
132+
*/
133+
public function mergeString($content, $percentage = .2)
134+
{
135+
$this->imageMerge = $content;
136+
$this->imagePercentage = $percentage;
137+
138+
return $this;
64139
}
65140

66141
public function size(int $pixels): self
@@ -240,4 +315,38 @@ protected function createColor(int $red, int $green, int $blue, ?int $alpha = nu
240315

241316
return new Alpha($alpha, new Rgb($red, $green, $blue));
242317
}
318+
319+
/**
320+
* Creates a new DataType class dynamically.
321+
*
322+
* @param string $method
323+
*
324+
* @return SimpleSoftwareIO\QrCode\DataTypes\DataTypeInterface
325+
*/
326+
protected function createClass($method)
327+
{
328+
$class = $this->formatClass($method);
329+
330+
if (!class_exists($class)) {
331+
throw new \BadMethodCallException();
332+
}
333+
334+
return new $class();
335+
}
336+
337+
/**
338+
* Formats the method name correctly.
339+
*
340+
* @param $method
341+
*
342+
* @return string
343+
*/
344+
protected function formatClass($method)
345+
{
346+
$method = ucfirst($method);
347+
348+
$class = "SimpleSoftwareIO\QrCode\DataTypes\\".$method;
349+
350+
return $class;
351+
}
243352
}

tests/BaconQrCodeGeneratorTest.php

Lines changed: 0 additions & 137 deletions
This file was deleted.

tests/DataTypes/BTCTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class BTCTest extends TestCase
77
{
8-
public function setUp()
8+
public function setUp(): void
99
{
1010
$this->btc = new BTC();
1111
}
@@ -40,7 +40,7 @@ public function test_it_generates_a_valid_btc_qrcode_with_an_address_amount_labe
4040
],
4141
]);
4242

43-
$properFormat = 'bitcoin:btcaddress?amount=0.0034&label=label&%24message=message&r='.urlencode('https://www.returnaddress.com');
43+
$properFormat = 'bitcoin:btcaddress?amount=0.0034&label=label&message=message&r='.urlencode('https://www.returnaddress.com');
4444

4545
$this->assertEquals($properFormat, strval($this->btc));
4646
}

tests/DataTypes/EmailTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class EmailTest extends TestCase
77
{
8-
public function setUp()
8+
public function setUp(): void
99
{
1010
$this->email = new Email();
1111
}
@@ -46,11 +46,10 @@ public function test_it_generates_the_proper_format_when_only_a_subject_is_provi
4646
$this->assertEquals($properFormat, strval($this->email));
4747
}
4848

49-
/**
50-
* @expectedException \InvalidArgumentException
51-
*/
5249
public function test_it_throws_an_exception_when_an_invalid_email_is_given()
5350
{
51+
$this->expectException(InvalidArgumentException::class);
52+
5453
$this->email->create(['foo']);
5554
}
5655
}

tests/DataTypes/SMSTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class SMSTest extends TestCase
77
{
8-
public function setUp()
8+
public function setUp(): void
99
{
1010
$this->sms = new SMS();
1111
}

tests/DataTypes/WiFiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class WiFiTest extends TestCase
77
{
8-
public function setUp()
8+
public function setUp(): void
99
{
1010
$this->wifi = new Wifi();
1111
}

0 commit comments

Comments
 (0)