Skip to content

Commit

Permalink
fixed launchoption bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritix committed Sep 5, 2024
1 parent 7b8471c commit 9028726
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ $converter->setOptions([
'headerTemplate' => '<p>I am a header</p>',
]);

$converter->setLaunchOptions((object)[
$converter->setLaunchOptions([
'ignoreHTTPSErrors' => true,
'headless' => true,
'executablePath' => '/usr/bin/google-chrome-stable',
Expand Down
2 changes: 1 addition & 1 deletion lib/Converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Converter

getLaunchOptions()
{
if(this.launchOptions === null) {
if(this.launchOptions.length === 0) {
return defaultLaunchOptions;
}
return this.launchOptions;
Expand Down
12 changes: 6 additions & 6 deletions src/Spiritix/Html2Pdf/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ class Converter
* @param InputInterface $input
* @param OutputInterface $output
* @param array $options Shortcut for setting multiple options
* @param array $launch_args Shortcut for setting puppeeter launch arguments
* @param array $launchOptions Shortcut for setting puppeeter launch arguments
*/
public function __construct(InputInterface $input, OutputInterface $output, array $options = [], array $launch_args = [])
public function __construct(InputInterface $input, OutputInterface $output, array $options = [], array $launchOptions = [])
{
$this->input = $input;
$this->output = $output;

if (!empty($options)) {
$this->setOptions($options);
}
if (!empty($launch_args)) {
$this->setLaunchOptions($launch_args);
if (!empty($launchOptions)) {
$this->setLaunchOptions($launchOptions);
}
}

Expand Down Expand Up @@ -209,13 +209,13 @@ public function setLaunchOption(string $key, $value): Converter
/**
* Set multiple launchOptions at once.
*
* @param object $launchOptions Multiple launchOptions
* @param array $launchOptions Multiple launchOptions
*
* @throws ConverterException If launchOptions are empty
*
* @return Converter
*/
public function setLaunchOptions(object $launchOptions): Converter
public function setLaunchOptions(array $launchOptions): Converter
{
if (empty($launchOptions)) {
throw new ConverterException('Provided launchOptions must not be empty');
Expand Down
25 changes: 25 additions & 0 deletions tests/php/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ public function testOptions()
], $options);
}

public function testLaunchOptions()
{
$this->converter->setLaunchOption('headless', 'new');
$this->converter->setLaunchOptions([
'ignoreHTTPSErrors' => true,
'executablePath' => '/usr/bin/google-chrome-stable',
]);

$value = $this->converter->getLaunchOption('headless');
$this->assertEquals('new', $value);

$value = $this->converter->getLaunchOption('ignoreHTTPSErrors');
$this->assertTrue($value);

$value = $this->converter->getLaunchOption('executablePath');
$this->assertEquals('/usr/bin/google-chrome-stable', $value);

$options = $this->converter->getLaunchOptions();
$this->assertEquals([
'headless' => 'new',
'ignoreHTTPSErrors' => true,
'executablePath' => '/usr/bin/google-chrome-stable',
], $options);
}

public function testNodePath()
{
$path = '/path/to/node';
Expand Down

0 comments on commit 9028726

Please sign in to comment.