Skip to content

Commit 38d1a6a

Browse files
committed
Coverage Tweaks
1 parent 7d3e009 commit 38d1a6a

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

src/PhpWord/Writer/RTF/Element/PreserveText.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
namespace PhpOffice\PhpWord\Writer\RTF\Element;
2020

21+
use PhpOffice\PhpWord\Element\PreserveText as PreserveTextElement;
22+
2123
/**
2224
* Text element RTF writer.
2325
*
@@ -32,12 +34,11 @@ class PreserveText extends AbstractElement
3234
*/
3335
public function write()
3436
{
35-
/** @var \PhpOffice\PhpWord\Element\PreserveText $element Type hint */
36-
$element = $this->element;
37-
if (!$element instanceof \PhpOffice\PhpWord\Element\PreserveText) {
38-
return '';
39-
}
37+
return ($this->element instanceof PreserveTextElement) ? $this->writeElement($this->element) : '';
38+
}
4039

40+
private function writeElement(PreserveTextElement $element): string
41+
{
4142
$this->getStyles();
4243

4344
$content = '';

src/PhpWord/Writer/RTF/Style/Spacing.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace PhpOffice\PhpWord\Writer\RTF\Style;
2020

2121
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
22+
use PhpOffice\PhpWord\Style\Spacing as SpacingStyle;
2223

2324
/**
2425
* RTF Spacing style writer.
@@ -35,10 +36,12 @@ class Spacing extends AbstractStyle
3536
public function write()
3637
{
3738
$style = $this->getStyle();
38-
if (!$style instanceof \PhpOffice\PhpWord\Style\Spacing) {
39-
return '';
40-
}
4139

40+
return ($style instanceof SpacingStyle) ? $this->writeStyle($style) : '';
41+
}
42+
43+
private function writeStyle(SpacingStyle $style): string
44+
{
4245
$spacingRules = [
4346
LineSpacingRule::AUTO => '\slmult1',
4447
LineSpacingRule::EXACT => '\slmult0',
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* This file is part of PHPWord - A pure PHP library for reading and writing
5+
* word processing documents.
6+
*
7+
* PHPWord is free software distributed under the terms of the GNU Lesser
8+
* General Public License version 3 as published by the Free Software Foundation.
9+
*
10+
* For the full copyright and license information, please read the LICENSE
11+
* file that was distributed with this source code. For the full list of
12+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13+
*
14+
* @see https://github.com/PHPOffice/PHPWord
15+
*
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
namespace PhpOffice\PhpWordTests\Writer\RTF\Style;
20+
21+
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
22+
use PhpOffice\PhpWord\Style\Spacing as SpacingStyle;
23+
use PhpOffice\PhpWord\Writer\RTF;
24+
use PhpOffice\PhpWord\Writer\RTF\Style\Spacing as SpacingWriter;
25+
use PHPUnit\Framework\TestCase;
26+
27+
class SpacingTest extends TestCase
28+
{
29+
public function removeCr(SpacingWriter $field): string
30+
{
31+
return str_replace("\r\n", "\n", $field->write());
32+
}
33+
34+
public function testSpacing(): void
35+
{
36+
$parentWriter = new RTF();
37+
$style = new SpacingStyle();
38+
$writer = new SpacingWriter($style);
39+
$writer->setParentWriter($parentWriter);
40+
41+
$style->setLineRule(LineSpacingRule::EXACT);
42+
$style->setLine(5);
43+
$expect = '\sl-5\slmult0';
44+
self::assertEquals($expect, $this->removeCr($writer));
45+
}
46+
}

0 commit comments

Comments
 (0)