Skip to content

Commit 410fa3b

Browse files
committed
test: fix CI follow-ups for provider hardening
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 70a79a9 commit 410fa3b

3 files changed

Lines changed: 205 additions & 169 deletions

File tree

tests/Unit/Html/SubsetHtmlParserTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ public function testParseOnlyInheritsTextualStylesToDescendants(
130130
string $expectedChildStyle,
131131
string $expectedTextStyle,
132132
array $excludedFragments,
133-
): void
134-
{
133+
): void {
135134
$parser = new SubsetHtmlParser();
136135

137136
$nodes = $parser->parse($html);

tests/Unit/Integration/XObjectPlacementCalculatorTest.php

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ final class XObjectPlacementCalculatorTest extends TestCase
2020
* 0: string,
2121
* 1: array{0: float, 1: float, 2: float, 3: float},
2222
* 2: float,
23-
* 3: float,
24-
* 4: float,
25-
* 5: array{scaleX: float, scaleY: float, width: float, height: float, translateX: float, translateY: float},
26-
* 6?: string,
27-
* 7?: string
23+
* 3: ?array{x: float, y: float},
24+
* 4: array{scaleX: float, scaleY: float, width: float, height: float, translateX: float, translateY: float},
25+
* 5?: string,
26+
* 6?: string
2827
* }>
2928
*/
3029
public static function placementProvider(): iterable
@@ -33,8 +32,7 @@ public static function placementProvider(): iterable
3332
'fromWidth',
3433
[12.5, 4.0, 252.5, 88.0],
3534
120.0,
36-
20.0,
37-
30.0,
35+
['x' => 20.0, 'y' => 30.0],
3836
[
3937
'scaleX' => 0.5,
4038
'scaleY' => 0.5,
@@ -51,8 +49,7 @@ public static function placementProvider(): iterable
5149
'fromHeight',
5250
[0.0, 0.0, 240.0, 84.0],
5351
168.0,
54-
15.0,
55-
25.0,
52+
['x' => 15.0, 'y' => 25.0],
5653
[
5754
'scaleX' => 2.0,
5855
'scaleY' => 2.0,
@@ -67,8 +64,7 @@ public static function placementProvider(): iterable
6764
'fromWidth',
6865
[10.0, 20.0, 110.0, 70.0],
6966
50.0,
70-
0.0,
71-
0.0,
67+
null,
7268
[
7369
'scaleX' => 0.5,
7470
'scaleY' => 0.5,
@@ -83,8 +79,7 @@ public static function placementProvider(): iterable
8379
'fromHeight',
8480
[10.0, 20.0, 110.0, 70.0],
8581
25.0,
86-
0.0,
87-
0.0,
82+
null,
8883
[
8984
'scaleX' => 0.5,
9085
'scaleY' => 0.5,
@@ -99,8 +94,7 @@ public static function placementProvider(): iterable
9994
'fromScale',
10095
[10.0, 20.0, 110.0, 70.0],
10196
2.0,
102-
0.0,
103-
0.0,
97+
null,
10498
[
10599
'scaleX' => 2.0,
106100
'scaleY' => 2.0,
@@ -115,8 +109,7 @@ public static function placementProvider(): iterable
115109
'fromScale',
116110
[-10.0, -5.0, 90.0, 45.0],
117111
1.5,
118-
2.0,
119-
3.0,
112+
['x' => 2.0, 'y' => 3.0],
120113
[
121114
'scaleX' => 1.5,
122115
'scaleY' => 1.5,
@@ -188,19 +181,36 @@ public function testPlacementStrategiesReturnExpectedGeometry(
188181
string $strategy,
189182
array $bbox,
190183
float $targetValue,
191-
float $x,
192-
float $y,
184+
?array $coordinates,
193185
array $expectedPlacement,
194186
?string $pdfAlias = null,
195187
?string $expectedPdfCommand = null,
196188
): void {
197189
$calculator = new XObjectPlacementCalculator();
198190
$result = new CompileResult(contentStream: 'BT ET', resources: [], bbox: $bbox);
199191

200-
$placement = match ($strategy) {
201-
'fromWidth' => $calculator->fromWidth($result, $targetValue, $x, $y),
202-
'fromHeight' => $calculator->fromHeight($result, $targetValue, $x, $y),
203-
'fromScale' => $calculator->fromScale($result, $targetValue, $x, $y),
192+
$placement = match ([$strategy, $coordinates === null]) {
193+
['fromWidth', true] => $calculator->fromWidth($result, $targetValue),
194+
['fromHeight', true] => $calculator->fromHeight($result, $targetValue),
195+
['fromScale', true] => $calculator->fromScale($result, $targetValue),
196+
['fromWidth', false] => $calculator->fromWidth(
197+
$result,
198+
$targetValue,
199+
$coordinates['x'],
200+
$coordinates['y'],
201+
),
202+
['fromHeight', false] => $calculator->fromHeight(
203+
$result,
204+
$targetValue,
205+
$coordinates['x'],
206+
$coordinates['y'],
207+
),
208+
['fromScale', false] => $calculator->fromScale(
209+
$result,
210+
$targetValue,
211+
$coordinates['x'],
212+
$coordinates['y'],
213+
),
204214
default => throw new InvalidArgumentException('Unknown placement strategy.'),
205215
};
206216

0 commit comments

Comments
 (0)