Skip to content

Commit 52d1f18

Browse files
committed
Fix: Code convention errors for EPub3 Unit tests
1 parent 6b58664 commit 52d1f18

File tree

19 files changed

+106
-91
lines changed

19 files changed

+106
-91
lines changed

src/PhpWord/Writer/EPub3/Element/AbstractElement.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,20 @@
2828
abstract class AbstractElement extends Word2007AbstractElement
2929
{
3030
/**
31-
* Get class name of writer element based on read element
31+
* Get class name of writer element based on read element.
3232
*
3333
* @param \PhpOffice\PhpWord\Element\AbstractElement $element
34+
*
3435
* @return string
35-
* @throws \PhpOffice\PhpWord\Exception\Exception
3636
*/
3737
public static function getElementClass($element)
3838
{
3939
$elementClass = str_replace('PhpOffice\\PhpWord\\Element\\', '', get_class($element));
4040
$writerClass = 'PhpOffice\\PhpWord\\Writer\\EPub3\\Element\\' . $elementClass;
41-
4241
if (!class_exists($writerClass)) {
4342
throw new \PhpOffice\PhpWord\Exception\Exception("Writer element class {$writerClass} not found.");
4443
}
45-
44+
4645
return $writerClass;
4746
}
4847
}

src/PhpWord/Writer/EPub3/Element/Text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ private function writeTrackChanges(?TrackChange $trackChange, bool $isStart): vo
8080
}
8181
}
8282
}
83-
}
83+
}

src/PhpWord/Writer/EPub3/Part.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@
2121
use PhpOffice\PhpWord\Exception\Exception;
2222

2323
/**
24-
* Factory class for EPub3 parts
24+
* Factory class for EPub3 parts.
2525
*/
2626
class Part
2727
{
2828
/**
29-
* Get the fully qualified class name for a specific part type
29+
* Get the fully qualified class name for a specific part type.
3030
*
3131
* @param string $type The type of part (Content, Manifest, Meta, Mimetype)
32+
*
3233
* @return string The fully qualified class name
33-
* @throws Exception If the part type is invalid
3434
*/
3535
public static function getPartClass(string $type): string
3636
{
3737
$class = 'PhpOffice\\PhpWord\\Writer\\EPub3\\Part\\' . $type;
38-
38+
3939
if (!class_exists($class)) {
4040
throw new Exception("Invalid part type: {$type}");
4141
}
42-
42+
4343
return $class;
4444
}
4545
}

src/PhpWord/Writer/EPub3/Part/Meta.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
class Meta extends AbstractPart
2727
{
2828
/**
29-
* Get XML Writer
29+
* Get XML Writer.
3030
*
31-
* @return \PhpOffice\PhpWord\Shared\XMLWriter
31+
* @return XMLWriter
3232
*/
3333
protected function getXmlWriter()
3434
{
@@ -41,8 +41,6 @@ protected function getXmlWriter()
4141

4242
/**
4343
* Write part content.
44-
*
45-
* @return string
4644
*/
4745
public function write(): string
4846
{
@@ -61,10 +59,8 @@ public function write(): string
6159

6260
// Write document info if available
6361
$docInfo = $this->getParentWriter()->getPhpWord()->getDocInfo();
64-
if ($docInfo) {
65-
if ($docInfo->getCreator()) {
66-
$xmlWriter->writeElement('dc:creator', $docInfo->getCreator());
67-
}
62+
if ($docInfo->getCreator()) {
63+
$xmlWriter->writeElement('dc:creator', $docInfo->getCreator());
6864
}
6965

7066
// Write modification date

src/PhpWord/Writer/EPub3/Style/AbstractStyle.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace PhpOffice\PhpWord\Writer\EPub3\Style;
2020

21+
use PhpOffice\PhpWord\Shared\XMLWriter;
2122
use PhpOffice\PhpWord\Writer\AbstractWriter;
2223

2324
/**
@@ -32,6 +33,13 @@ abstract class AbstractStyle
3233
*/
3334
protected $parentWriter;
3435

36+
/**
37+
* XML Writer.
38+
*
39+
* @var XMLWriter
40+
*/
41+
protected $xmlWriter;
42+
3543
/**
3644
* Set parent writer.
3745
*
@@ -44,6 +52,18 @@ public function setParentWriter(AbstractWriter $writer)
4452
return $this;
4553
}
4654

55+
/**
56+
* Set XML Writer.
57+
*
58+
* @return self
59+
*/
60+
public function setXmlWriter(XMLWriter $writer)
61+
{
62+
$this->xmlWriter = $writer;
63+
64+
return $this;
65+
}
66+
4767
/**
4868
* Get parent writer.
4969
*

tests/PhpWordTests/Writer/EPub3/Element/ImageTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace PhpOffice\PhpWordTests\Writer\EPub3\Element;
44

55
use PhpOffice\PhpWord\Element\Image;
6+
use PhpOffice\PhpWord\Shared\XMLWriter;
67
use PhpOffice\PhpWord\Style\Image as ImageStyle;
78
use PhpOffice\PhpWord\Writer\EPub3\Element\Image as ImageWriter;
89
use PHPUnit\Framework\TestCase;
9-
use PhpOffice\PhpWord\Shared\XMLWriter;
1010

1111
class ImageTest extends TestCase
1212
{
@@ -40,7 +40,7 @@ public function testWrite(): void
4040
$this->writer->write();
4141

4242
$expected = '<p><img src="media/image.jpg" style="width:500px;height:500px;"/></p>';
43-
$this->assertEquals($expected, $this->xmlWriter->getData());
43+
self::assertEquals($expected, $this->xmlWriter->getData());
4444
}
4545

4646
public function testWriteWithoutP(): void
@@ -54,7 +54,7 @@ public function testWriteWithoutP(): void
5454
$this->writer->write();
5555

5656
$expected = '<img src="media/image.jpg" style="width:500px;height:500px;"/>';
57-
$this->assertEquals($expected, $this->xmlWriter->getData());
57+
self::assertEquals($expected, $this->xmlWriter->getData());
5858
}
5959

6060
public function testWriteWithInvalidElement(): void
@@ -64,6 +64,6 @@ public function testWriteWithInvalidElement(): void
6464

6565
$writer->write();
6666

67-
$this->assertEquals('', $this->xmlWriter->getData());
67+
self::assertEquals('', $this->xmlWriter->getData());
6868
}
6969
}

tests/PhpWordTests/Writer/EPub3/Element/TextTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace PhpOffice\PhpWordTests\Writer\EPub3\Element;
44

55
use PhpOffice\PhpWord\Element\Text;
6-
use PhpOffice\PhpWord\Element\TrackChange;
6+
use PhpOffice\PhpWord\Shared\XMLWriter;
77
use PhpOffice\PhpWord\Writer\EPub3\Element\Text as TextWriter;
88
use PHPUnit\Framework\TestCase;
9-
use PhpOffice\PhpWord\Shared\XMLWriter;
109

1110
class TextTest extends TestCase
1211
{
@@ -37,7 +36,7 @@ public function testWrite(): void
3736
$this->writer->write();
3837

3938
$expected = "<p>\n <span>Sample Text</span>\n</p>\n";
40-
$this->assertEquals($expected, $this->xmlWriter->getData());
39+
self::assertEquals($expected, $this->xmlWriter->getData());
4140
}
4241

4342
public function testWriteWithFontStyle(): void
@@ -47,7 +46,7 @@ public function testWriteWithFontStyle(): void
4746
$this->writer->write();
4847

4948
$expected = "<p>\n <span class=\"customStyle\">Sample Text</span>\n</p>\n";
50-
$this->assertEquals($expected, $this->xmlWriter->getData());
49+
self::assertEquals($expected, $this->xmlWriter->getData());
5150
}
5251

5352
public function testWriteWithParagraphStyle(): void
@@ -57,7 +56,7 @@ public function testWriteWithParagraphStyle(): void
5756
$this->writer->write();
5857

5958
$expected = "<p class=\"paragraphStyle\">\n <span>Sample Text</span>\n</p>\n";
60-
$this->assertEquals($expected, $this->xmlWriter->getData());
59+
self::assertEquals($expected, $this->xmlWriter->getData());
6160
}
6261

6362
public function testWriteWithoutP(): void
@@ -69,7 +68,7 @@ public function testWriteWithoutP(): void
6968
$this->writer->write();
7069

7170
$expected = "<span>Sample Text</span>\n";
72-
$this->assertEquals($expected, $xmlWriter->getData());
71+
self::assertEquals($expected, $xmlWriter->getData());
7372
}
7473

7574
public function testWriteWithInvalidElement(): void
@@ -79,6 +78,6 @@ public function testWriteWithInvalidElement(): void
7978

8079
$writer->write();
8180

82-
$this->assertEquals('', $this->xmlWriter->getData());
81+
self::assertEquals('', $this->xmlWriter->getData());
8382
}
84-
}
83+
}

tests/PhpWordTests/Writer/EPub3/ElementTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
namespace PhpOffice\PhpWordTests\Writer\EPub3;
44

5+
use PhpOffice\PhpWord\Element\AbstractElement;
56
use PhpOffice\PhpWord\Element\Text;
6-
use PhpOffice\PhpWord\Writer\EPub3\Element\AbstractElement;
7+
use PhpOffice\PhpWord\Writer\EPub3\Element\AbstractElement as WriterElement;
78
use PHPUnit\Framework\TestCase;
89

910
class ElementTest extends TestCase
1011
{
1112
public function testGetElementClass(): void
1213
{
1314
$element = new Text('test');
14-
$class = AbstractElement::getElementClass($element);
15-
16-
$this->assertEquals('PhpOffice\\PhpWord\\Writer\\EPub3\\Element\\Text', $class);
15+
$class = WriterElement::getElementClass($element);
16+
self::assertEquals('PhpOffice\\PhpWord\\Writer\\EPub3\\Element\\Text', $class);
1717
}
1818

1919
public function testGetElementClassWithInvalidElement(): void
2020
{
2121
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
22-
23-
$element = new \stdClass();
24-
AbstractElement::getElementClass($element);
22+
23+
$element = $this->createMock(AbstractElement::class);
24+
WriterElement::getElementClass($element);
2525
}
2626
}

tests/PhpWordTests/Writer/EPub3/Part/AbstractPartTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testParentWriter(): void
2222
{
2323
$writer = new EPub3();
2424
$this->part->setParentWriter($writer);
25-
26-
$this->assertInstanceOf(EPub3::class, $this->part->getParentWriter());
25+
26+
self::assertInstanceOf(EPub3::class, $this->part->getParentWriter());
2727
}
2828
}

tests/PhpWordTests/Writer/EPub3/Part/ContentTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ protected function setUp(): void
2020
$phpWord = new PhpWord();
2121
$section = $phpWord->addSection();
2222
$section->addText('Test content');
23-
23+
2424
$writer = new EPub3($phpWord);
2525
$this->content->setParentWriter($writer);
2626
}
2727

2828
public function testWrite(): void
2929
{
3030
$result = $this->content->write();
31-
32-
$this->assertIsString($result);
33-
$this->assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $result);
34-
$this->assertStringContainsString('<package', $result);
35-
$this->assertStringContainsString('<manifest>', $result);
36-
$this->assertStringContainsString('<spine>', $result);
31+
32+
self::assertIsString($result);
33+
self::assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $result);
34+
self::assertStringContainsString('<package', $result);
35+
self::assertStringContainsString('<manifest>', $result);
36+
self::assertStringContainsString('<spine>', $result);
3737
}
3838
}

tests/PhpWordTests/Writer/EPub3/Part/ManifestTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ protected function setUp(): void
2525
public function testWrite(): void
2626
{
2727
$result = $this->manifest->write();
28-
29-
$this->assertIsString($result);
30-
$this->assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $result);
31-
$this->assertStringContainsString('<container version="1.0"', $result);
32-
$this->assertStringContainsString('<rootfiles>', $result);
33-
$this->assertStringContainsString('<rootfile full-path="content.opf"', $result);
28+
29+
self::assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $result);
30+
self::assertIsString($result);
31+
self::assertStringContainsString('<container version="1.0"', $result);
32+
self::assertStringContainsString('<rootfiles>', $result);
33+
self::assertStringContainsString('<rootfile full-path="content.opf"', $result);
3434
}
3535
}

tests/PhpWordTests/Writer/EPub3/Part/MetaTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ protected function setUp(): void
2525
public function testWrite(): void
2626
{
2727
$result = $this->meta->write();
28-
29-
$this->assertIsString($result);
30-
$this->assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $result);
31-
$this->assertStringContainsString('<metadata', $result);
32-
$this->assertStringContainsString('xmlns:dc="http://purl.org/dc/elements/1.1/"', $result);
28+
29+
self::assertIsString($result);
30+
self::assertStringContainsString('<?xml version="1.0" encoding="UTF-8"?>', $result);
31+
self::assertStringContainsString('<metadata', $result);
32+
self::assertStringContainsString('xmlns:dc="http://purl.org/dc/elements/1.1/"', $result);
3333
}
3434

3535
public function testWriteWithDocInfo(): void
@@ -39,15 +39,15 @@ public function testWriteWithDocInfo(): void
3939
$properties->setCreator('PHPWord');
4040
$properties->setTitle('Test Title');
4141
$properties->setKeywords('test, keywords');
42-
42+
4343
$writer = new EPub3($phpWord);
4444
$this->meta->setParentWriter($writer);
45-
45+
4646
$expected = '<?xml version="1.0" encoding="UTF-8"?>\n<metadata xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:title>Test Title</dc:title><dc:language>en</dc:language><dc:identifier>urn:uuid:12345</dc:identifier><dc:creator>PHPWord</dc:creator><meta property="dcterms:modified">2023-01-01T00:00:00Z</meta></metadata>';
47-
47+
4848
$result = $this->meta->write();
49-
50-
$this->assertStringContainsString('<dc:creator>PHPWord</dc:creator>', $result);
51-
$this->assertStringContainsString('<dc:title>Test Title</dc:title>', $result);
49+
50+
self::assertStringContainsString('<dc:creator>PHPWord</dc:creator>', $result);
51+
self::assertStringContainsString('<dc:title>Test Title</dc:title>', $result);
5252
}
5353
}

tests/PhpWordTests/Writer/EPub3/Part/MimetypeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ protected function setUp(): void
2525
public function testWrite(): void
2626
{
2727
$result = $this->mimetype->write();
28-
29-
$this->assertIsString($result);
30-
$this->assertEquals('application/epub+zip', $result);
28+
29+
self::assertIsString($result);
30+
self::assertEquals('application/epub+zip', $result);
3131
}
3232
}

tests/PhpWordTests/Writer/EPub3/PartTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ class PartTest extends TestCase
1010
public function testGetPartClass(): void
1111
{
1212
$types = ['Content', 'Manifest', 'Meta', 'Mimetype'];
13-
13+
1414
foreach ($types as $type) {
1515
$class = Part::getPartClass($type);
1616
$expectedClass = 'PhpOffice\\PhpWord\\Writer\\EPub3\\Part\\' . $type;
17-
18-
$this->assertEquals($expectedClass, $class);
17+
18+
self::assertEquals($expectedClass, $class);
1919
}
2020
}
2121

2222
public function testGetPartClassWithInvalidType(): void
2323
{
2424
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
25-
25+
2626
Part::getPartClass('InvalidType');
2727
}
2828
}

0 commit comments

Comments
 (0)