Skip to content

Commit 81af60f

Browse files
committed
add 3-parameter setMargin calls
1 parent 59ceac6 commit 81af60f

4 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/AbstractPDF.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,26 @@ public function setFormat(string $format): self
116116
* @return self
117117
*/
118118
public function setMargin(
119-
?string $top = null,
119+
?string $top,
120120
?string $right = null,
121121
?string $bottom = null,
122122
?string $left = null
123123
): self {
124-
if ($top !== null and $right === null and $bottom === null and $left === null) {
124+
if (func_num_args() === 1) {
125125
$this->marginTop = $top;
126126
$this->marginRight = $top;
127127
$this->marginBottom = $top;
128128
$this->marginLeft = $top;
129-
} elseif ($top !== null and $right !== null and $bottom === null and $left === null) {
129+
} elseif (func_num_args() === 2) {
130130
$this->marginTop = $top;
131131
$this->marginRight = $right;
132132
$this->marginBottom = $top;
133133
$this->marginLeft = $right;
134+
} elseif (func_num_args() === 3) {
135+
$this->marginTop = $top;
136+
$this->marginRight = $right;
137+
$this->marginBottom = $bottom;
138+
$this->marginLeft = $right;
134139
} else {
135140
$this->marginTop = $top;
136141
$this->marginRight = $right;

test/AbstractPDFTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public function test_margin()
4848
$this->assertSame('30px', $mock->getMarginRight());
4949
$this->assertSame('30px', $mock->getMarginBottom());
5050
$this->assertSame('30px', $mock->getMarginLeft());
51+
52+
$mock->setMargin('1px', '2px', '3px');
53+
$this->assertSame('1px', $mock->getMarginTop());
54+
$this->assertSame('2px', $mock->getMarginRight());
55+
$this->assertSame('3px', $mock->getMarginBottom());
56+
$this->assertSame('2px', $mock->getMarginLeft());
5157
}
5258

5359
public function test_waitUntil()

test/BrowserlessTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public function test_margin()
320320
{
321321
$client = $this->getMockedClient();
322322

323-
$client->expects($this->exactly(5))
323+
$client->expects($this->exactly(6))
324324
->method('post')
325325
->withConsecutive(
326326
[
@@ -351,6 +351,18 @@ public function test_margin()
351351
])
352352
)
353353
],
354+
[
355+
$this->anything(),
356+
$this->hasKeyValue(
357+
['json', 'options', 'margin'],
358+
$this->equalTo([
359+
'top' => '5px',
360+
'right' => '6px',
361+
'bottom' => '7px',
362+
'left' => '6px',
363+
])
364+
)
365+
],
354366
[
355367
$this->anything(),
356368
$this->hasKeyValue(
@@ -379,6 +391,9 @@ public function test_margin()
379391
$bl->setMargin('1px', '2px');
380392
$bl->renderContent('test');
381393

394+
$bl->setMargin('5px', '6px', '7px');
395+
$bl->renderContent('test');
396+
382397
$bl->setMargin('1', '2', '3', '4');
383398
$bl->renderContent('test');
384399

test/ChromeTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public function test_margins()
473473
{
474474
$pdf = $this->getMockedPDF();
475475

476-
$pdf->expects($this->exactly(5))
476+
$pdf->expects($this->exactly(6))
477477
->method('createProcess')
478478
->withConsecutive(
479479
[ $this->logicalNot($this->contains('--margin')) ],
@@ -495,6 +495,12 @@ public function test_margins()
495495
$this->contains('1px,2px,1px,2px')
496496
)
497497
],
498+
[
499+
$this->logicalAnd(
500+
$this->contains('--margin'),
501+
$this->contains('5px,6px,7px,6px')
502+
)
503+
],
498504
[ $this->logicalNot($this->contains('--margin')) ]
499505
)
500506
->will($this->returnCallback(function () { return $this->getMockedProcess(); }));
@@ -510,6 +516,9 @@ public function test_margins()
510516
$pdf->setMargin('1px', '2px');
511517
$pdf->renderContent('test');
512518

519+
$pdf->setMargin('5px', '6px', '7px');
520+
$pdf->renderContent('test');
521+
513522
$pdf->setMargin(null);
514523
$pdf->renderContent('test');
515524
}

0 commit comments

Comments
 (0)