Skip to content

Commit

Permalink
🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
willpower232 committed Apr 15, 2024
1 parent 1de1e96 commit 115c012
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^10.0",
"phpstan/phpstan": "^1.9"
},
"scripts": {
Expand Down
53 changes: 22 additions & 31 deletions test/BrowserlessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ClientException;

use GuzzleHttp\Middleware;
use SynergiTech\ChromePDF\Browserless;
use SynergiTech\ChromePDF\Browserless\APIException;
use SynergiTech\ChromePDF\Chrome;
Expand Down Expand Up @@ -85,37 +85,14 @@ public function test_timeout()

public function test_displayHeaderFooter()
{
$client = $this->getMockedClient();
$requests = [];

$client->expects($this->exactly(6))
->method('post')
->withConsecutive(
[
$this->anything(),
$this->logicalNot($this->hasKeyValue(['json', 'options', 'displayHeaderFooter']))
],
[
$this->anything(),
$this->hasKeyValue(['json', 'options', 'displayHeaderFooter'], $this->isTrue())
],
[
$this->anything(),
$this->hasKeyValue(['json', 'options', 'displayHeaderFooter'], $this->isFalse())
],
[
$this->anything(),
$this->hasKeyValue(['json', 'options', 'displayHeaderFooter'], $this->isTrue())
],
[
$this->anything(),
$this->hasKeyValue(['json', 'options', 'displayHeaderFooter'], $this->isTrue())
],
[
$this->anything(),
$this->hasKeyValue(['json', 'options', 'displayHeaderFooter'], $this->isFalse())
]
)
->willReturn(new Response());
$handlerStack = HandlerStack::create(new MockHandler(array_fill(0, 6, new Response())));
$handlerStack->push(Middleware::history($requests));

$client = new Client([
'handler' => $handlerStack,
]);

$bl = new Browserless(client: $client);
$bl->renderContent('test');
Expand All @@ -135,6 +112,20 @@ public function test_displayHeaderFooter()

$bl->setFooter(null);
$bl->renderContent('test');

$this->assertCount(6, $requests);

$requests = array_map(fn ($r) => json_decode((string) $r['request']->getBody(), true), $requests);

$options = array_column($requests, 'options');

$this->assertArrayNotHasKey('displayHeaderFooter', $options[0]);

$this->assertTrue($options[1]['displayHeaderFooter']);
$this->assertFalse($options[2]['displayHeaderFooter']);
$this->assertTrue($options[3]['displayHeaderFooter']);
$this->assertTrue($options[4]['displayHeaderFooter']);
$this->assertFalse($options[5]['displayHeaderFooter']);
}

public function test_header()
Expand Down
8 changes: 4 additions & 4 deletions test/ChromeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private function getMockedProcess()
private function getMockedPDF()
{
return $this->getMockBuilder(Chrome::class)
->setMethods(['createProcess'])
->onlyMethods(['createProcess'])
->getMock();
}

Expand All @@ -40,7 +40,7 @@ public function test_callsSpecifiedBinary()
{
$pdf = $this->getMockBuilder(Chrome::class)
->setConstructorArgs(['test-pdf-binary'])
->setMethods(['createProcess'])
->onlyMethods(['createProcess'])
->getMock();

$pdf->expects($this->once())
Expand Down Expand Up @@ -216,7 +216,7 @@ public function test_displayHeaderFooter()
public function test_header()
{
$pdfBuilder = $this->getMockBuilder(Chrome::class)
->setMethods(['createProcess']);
->onlyMethods(['createProcess']);

$pdf = $pdfBuilder->getMock();
$pdf->expects($this->exactly(2))
Expand Down Expand Up @@ -261,7 +261,7 @@ public function test_header()
public function test_footer()
{
$pdfBuilder = $this->getMockBuilder(Chrome::class)
->setMethods(['createProcess']);
->onlyMethods(['createProcess']);

$pdf = $pdfBuilder->getMock();
$pdf->expects($this->exactly(2))
Expand Down
2 changes: 1 addition & 1 deletion test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function hasKeyValue($key, $constraint = null)
protected function getMockedClient()
{
return $this->getMockBuilder(Chrome::class)
->setMethods(['post'])
->addMethods(['post'])
->getMock();
}
}

0 comments on commit 115c012

Please sign in to comment.