diff --git a/README.md b/README.md index 90619c7..316ff15 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ $converter->setOptions([ 'headerTemplate' => '

I am a header

', ]); -$converter->setLaunchOptions((object)[ +$converter->setLaunchOptions([ 'ignoreHTTPSErrors' => true, 'headless' => true, 'executablePath' => '/usr/bin/google-chrome-stable', diff --git a/lib/Converter.js b/lib/Converter.js index 1d15d6d..19530bb 100644 --- a/lib/Converter.js +++ b/lib/Converter.js @@ -44,7 +44,7 @@ class Converter getLaunchOptions() { - if(this.launchOptions === null) { + if(this.launchOptions.length === 0) { return defaultLaunchOptions; } return this.launchOptions; diff --git a/src/Spiritix/Html2Pdf/Converter.php b/src/Spiritix/Html2Pdf/Converter.php index 729fada..5154b5e 100644 --- a/src/Spiritix/Html2Pdf/Converter.php +++ b/src/Spiritix/Html2Pdf/Converter.php @@ -71,9 +71,9 @@ 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; @@ -81,8 +81,8 @@ public function __construct(InputInterface $input, OutputInterface $output, arra if (!empty($options)) { $this->setOptions($options); } - if (!empty($launch_args)) { - $this->setLaunchOptions($launch_args); + if (!empty($launchOptions)) { + $this->setLaunchOptions($launchOptions); } } @@ -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'); diff --git a/tests/php/ConverterTest.php b/tests/php/ConverterTest.php index 4a59a6f..ad32a2c 100644 --- a/tests/php/ConverterTest.php +++ b/tests/php/ConverterTest.php @@ -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';