Skip to content

Commit 9028726

Browse files
committed
fixed launchoption bugs
1 parent 7b8471c commit 9028726

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ $converter->setOptions([
6666
'headerTemplate' => '<p>I am a header</p>',
6767
]);
6868

69-
$converter->setLaunchOptions((object)[
69+
$converter->setLaunchOptions([
7070
'ignoreHTTPSErrors' => true,
7171
'headless' => true,
7272
'executablePath' => '/usr/bin/google-chrome-stable',

lib/Converter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Converter
4444

4545
getLaunchOptions()
4646
{
47-
if(this.launchOptions === null) {
47+
if(this.launchOptions.length === 0) {
4848
return defaultLaunchOptions;
4949
}
5050
return this.launchOptions;

src/Spiritix/Html2Pdf/Converter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ class Converter
7171
* @param InputInterface $input
7272
* @param OutputInterface $output
7373
* @param array $options Shortcut for setting multiple options
74-
* @param array $launch_args Shortcut for setting puppeeter launch arguments
74+
* @param array $launchOptions Shortcut for setting puppeeter launch arguments
7575
*/
76-
public function __construct(InputInterface $input, OutputInterface $output, array $options = [], array $launch_args = [])
76+
public function __construct(InputInterface $input, OutputInterface $output, array $options = [], array $launchOptions = [])
7777
{
7878
$this->input = $input;
7979
$this->output = $output;
8080

8181
if (!empty($options)) {
8282
$this->setOptions($options);
8383
}
84-
if (!empty($launch_args)) {
85-
$this->setLaunchOptions($launch_args);
84+
if (!empty($launchOptions)) {
85+
$this->setLaunchOptions($launchOptions);
8686
}
8787
}
8888

@@ -209,13 +209,13 @@ public function setLaunchOption(string $key, $value): Converter
209209
/**
210210
* Set multiple launchOptions at once.
211211
*
212-
* @param object $launchOptions Multiple launchOptions
212+
* @param array $launchOptions Multiple launchOptions
213213
*
214214
* @throws ConverterException If launchOptions are empty
215215
*
216216
* @return Converter
217217
*/
218-
public function setLaunchOptions(object $launchOptions): Converter
218+
public function setLaunchOptions(array $launchOptions): Converter
219219
{
220220
if (empty($launchOptions)) {
221221
throw new ConverterException('Provided launchOptions must not be empty');

tests/php/ConverterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ public function testOptions()
4848
], $options);
4949
}
5050

51+
public function testLaunchOptions()
52+
{
53+
$this->converter->setLaunchOption('headless', 'new');
54+
$this->converter->setLaunchOptions([
55+
'ignoreHTTPSErrors' => true,
56+
'executablePath' => '/usr/bin/google-chrome-stable',
57+
]);
58+
59+
$value = $this->converter->getLaunchOption('headless');
60+
$this->assertEquals('new', $value);
61+
62+
$value = $this->converter->getLaunchOption('ignoreHTTPSErrors');
63+
$this->assertTrue($value);
64+
65+
$value = $this->converter->getLaunchOption('executablePath');
66+
$this->assertEquals('/usr/bin/google-chrome-stable', $value);
67+
68+
$options = $this->converter->getLaunchOptions();
69+
$this->assertEquals([
70+
'headless' => 'new',
71+
'ignoreHTTPSErrors' => true,
72+
'executablePath' => '/usr/bin/google-chrome-stable',
73+
], $options);
74+
}
75+
5176
public function testNodePath()
5277
{
5378
$path = '/path/to/node';

0 commit comments

Comments
 (0)