Skip to content

Commit a87ea8b

Browse files
committed
Added toArray method / add test
1 parent ea11756 commit a87ea8b

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/Classes/PdfPrinterOption.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
class PdfPrinterOption {
77

88
public String $filename;
9-
public String $postBackUrl;
9+
public ?String $postBackUrl;
1010
public Array $postBackBody;
11-
public String $token;
11+
public ?String $token;
1212
public bool $autodelete = false;
1313

1414
public function __construct(String $filename, String $postBackUrl = null, Array $postBackBody = [], String $token = null, bool $autodelete = false) {
@@ -29,5 +29,14 @@ public function __construct(String $filename, String $postBackUrl = null, Array
2929
public function getPostBackBody(): String {
3030
return json_encode($this->postBackBody != null ? $this->postBackBody : []);
3131
}
32+
33+
/**
34+
* Returns the options as an array
35+
*
36+
* @return void
37+
*/
38+
public function toArray() {
39+
return (array) $this;
40+
}
3241

3342
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace AMBERSIVE\Tests\Unit\Classes;
4+
5+
use AMBERSIVE\Tests\TestCase;
6+
7+
use AMBERSIVE\PdfPrinter\Classes\PdfPrinterOption;
8+
9+
use Mockery;
10+
use Storage;
11+
use Str;
12+
13+
use GuzzleHttp\Client;
14+
use GuzzleHttp\Psr7\Response;
15+
use GuzzleHttp\Handler\MockHandler;
16+
use GuzzleHttp\HandlerStack;
17+
18+
class PdfPrinterOptionTest extends TestCase
19+
{
20+
21+
public PdfPrinterOption $options;
22+
23+
protected function setUp(): void
24+
{
25+
parent::setUp();
26+
$this->options = new PdfPrinterOption("test", null, [], null, false);
27+
}
28+
29+
public function testIfToArrayReturnsOptionsAsArray():void {
30+
31+
$data = $this->options->toArray();
32+
$this->assertTrue(is_array($data));
33+
34+
}
35+
36+
}

0 commit comments

Comments
 (0)