From 5beb34ea44f18acb55cd4626a62ccbc93ffecde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B7=D0=B0=D0=BC=D0=B0=D1=828405?= Date: Thu, 21 Nov 2024 14:33:48 +0300 Subject: [PATCH 1/3] Update composer.json azamat8405/phpword --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9633fe01da..f6fa7918d9 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "phpoffice/phpword", + "name": "azamat8405/phpword", "description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)", "keywords": [ "PHP", "PHPOffice", "office", "PHPWord", "word", "template", "template processor", "reader", "writer", From 967b0f6b4aa58811b00a64d5e10fa5bd54d6700d Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Thu, 23 Jan 2025 19:31:17 +0300 Subject: [PATCH 2/3] fix: package name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 56cc5552e3..efebe941e7 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "azamat8405/phpword", + "name": "phpoffice/phpword", "description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)", "keywords": [ "PHP", "PHPOffice", "office", "PHPWord", "word", "template", "template processor", "reader", "writer", From 43ef1be00957128548b3403b1f2ebd9fba79df7f Mon Sep 17 00:00:00 2001 From: OlisaevAG Date: Thu, 27 Feb 2025 15:58:39 +0300 Subject: [PATCH 3/3] fix: deprecated getMockForAbstractClass method --- .../Element/AbstractElementTest.php | 16 +++++++++++++-- .../PhpWordTests/Style/AbstractStyleTest.php | 13 ++++++++---- .../Writer/EPub3/Part/AbstractPartTest.php | 6 +++++- .../Writer/EPub3/Style/AbstractStyleTest.php | 8 +++++++- .../Writer/ODText/Part/AbstractPartTest.php | 19 ++++++++++++++---- .../Writer/Word2007/Part/AbstractPartTest.php | 20 +++++++++++++++---- 6 files changed, 66 insertions(+), 16 deletions(-) diff --git a/tests/PhpWordTests/Element/AbstractElementTest.php b/tests/PhpWordTests/Element/AbstractElementTest.php index 8219871f73..d903b7acfb 100644 --- a/tests/PhpWordTests/Element/AbstractElementTest.php +++ b/tests/PhpWordTests/Element/AbstractElementTest.php @@ -30,9 +30,15 @@ class AbstractElementTest extends \PHPUnit\Framework\TestCase */ public function testElementIndex(): void { - $stub = $this->getMockForAbstractClass(AbstractElement::class); + $stub = $this->getMockBuilder(AbstractElement::class)->getMock(); + $ival = mt_rand(0, 100); $stub->setElementIndex($ival); + + $stub->expects(static::any()) + ->method('getElementIndex') + ->willReturn($ival); + self::assertEquals($ival, $stub->getElementIndex()); } @@ -41,8 +47,14 @@ public function testElementIndex(): void */ public function testElementId(): void { - $stub = $this->getMockForAbstractClass(AbstractElement::class); + $stub = $this->getMockBuilder(AbstractElement::class)->getMock(); + $stub->setElementId(); + + $stub->expects(static::any()) + ->method('getElementId') + ->willReturn(substr(md5((string) mt_rand()), 0, 6)); + self::assertEquals(6, strlen($stub->getElementId())); } } diff --git a/tests/PhpWordTests/Style/AbstractStyleTest.php b/tests/PhpWordTests/Style/AbstractStyleTest.php index 2f1585fd5a..5b99de8cb6 100644 --- a/tests/PhpWordTests/Style/AbstractStyleTest.php +++ b/tests/PhpWordTests/Style/AbstractStyleTest.php @@ -35,9 +35,14 @@ class AbstractStyleTest extends \PHPUnit\Framework\TestCase */ public function testSetStyleByArray(): void { - $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); + $stub = $this->getMockBuilder(\PhpOffice\PhpWord\Style\AbstractStyle::class)->getMock(); + $stub->setStyleByArray(['index' => 1]); + $stub->expects(static::once()) + ->method('getIndex') + ->willReturn(1); + self::assertEquals(1, $stub->getIndex()); } @@ -62,7 +67,7 @@ public function testSetStyleByArrayWithAlignment(): void */ public function testSetValNormal(): void { - $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); + $stub = $this->getMockBuilder(\PhpOffice\PhpWord\Style\AbstractStyle::class)->getMock(); self::assertTrue(self::callProtectedMethod($stub, 'setBoolVal', [true, false])); self::assertEquals(12, self::callProtectedMethod($stub, 'setIntVal', [12, 200])); @@ -76,7 +81,7 @@ public function testSetValNormal(): void */ public function testSetValDefault(): void { - $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); + $stub = $this->getMockBuilder(\PhpOffice\PhpWord\Style\AbstractStyle::class)->getMock(); self::assertNotTrue(self::callProtectedMethod($stub, 'setBoolVal', ['a', false])); self::assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', ['foo', 200])); @@ -90,7 +95,7 @@ public function testSetValDefault(): void public function testSetValEnumException(): void { $this->expectException(InvalidArgumentException::class); - $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); + $stub = $this->getMockBuilder(\PhpOffice\PhpWord\Style\AbstractStyle::class)->getMock(); self::assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', ['z', ['a', 'b'], 'b'])); } diff --git a/tests/PhpWordTests/Writer/EPub3/Part/AbstractPartTest.php b/tests/PhpWordTests/Writer/EPub3/Part/AbstractPartTest.php index 5151eea24c..2ded7cae24 100644 --- a/tests/PhpWordTests/Writer/EPub3/Part/AbstractPartTest.php +++ b/tests/PhpWordTests/Writer/EPub3/Part/AbstractPartTest.php @@ -15,7 +15,7 @@ class AbstractPartTest extends TestCase protected function setUp(): void { - $this->part = $this->getMockForAbstractClass(AbstractPart::class); + $this->part = $this->getMockBuilder(AbstractPart::class)->getMock(); } public function testParentWriter(): void @@ -23,6 +23,10 @@ public function testParentWriter(): void $writer = new EPub3(); $this->part->setParentWriter($writer); + $this->part->expects(static::once()) + ->method('getParentWriter') + ->willReturn($writer); + self::assertInstanceOf(EPub3::class, $this->part->getParentWriter()); } } diff --git a/tests/PhpWordTests/Writer/EPub3/Style/AbstractStyleTest.php b/tests/PhpWordTests/Writer/EPub3/Style/AbstractStyleTest.php index fb9135f0cd..63f2c7f31d 100644 --- a/tests/PhpWordTests/Writer/EPub3/Style/AbstractStyleTest.php +++ b/tests/PhpWordTests/Writer/EPub3/Style/AbstractStyleTest.php @@ -14,9 +14,15 @@ class AbstractStyleTest extends TestCase public function testParentWriter(): void { $parentWriter = new EPub3(); - $style = $this->getMockForAbstractClass(AbstractStyle::class); + $style = $this->getMockBuilder(AbstractStyle::class)->getMock(); + $style->expects(static::once()) + ->method('setParentWriter') + ->willReturn($style); $result = $style->setParentWriter($parentWriter); + $style->expects(static::once()) + ->method('getParentWriter') + ->willReturn($parentWriter); self::assertSame($style, $result); self::assertSame($parentWriter, $style->getParentWriter()); diff --git a/tests/PhpWordTests/Writer/ODText/Part/AbstractPartTest.php b/tests/PhpWordTests/Writer/ODText/Part/AbstractPartTest.php index 6742b20ad5..c1fa2b413c 100644 --- a/tests/PhpWordTests/Writer/ODText/Part/AbstractPartTest.php +++ b/tests/PhpWordTests/Writer/ODText/Part/AbstractPartTest.php @@ -34,9 +34,16 @@ class AbstractPartTest extends \PHPUnit\Framework\TestCase */ public function testSetGetParentWriter(): void { - $object = $this->getMockForAbstractClass(ODText\Part\AbstractPart::class); - $object->setParentWriter(new ODText()); - self::assertEquals(new ODText(), $object->getParentWriter()); + $object = $this->getMockBuilder(\PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart::class)->getMock(); + + $tmp = new ODText(); + $object->setParentWriter($tmp); + + $object->expects(static::once()) + ->method('getParentWriter') + ->willReturn($tmp); + + self::assertEquals($tmp, $object->getParentWriter()); } /** @@ -46,7 +53,11 @@ public function testSetGetParentWriterNull(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('No parent WriterInterface assigned.'); - $object = $this->getMockForAbstractClass(ODText\Part\AbstractPart::class); + + $object = $this->getMockBuilder(\PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart::class)->getMock(); + $object->expects(static::once()) + ->method('getParentWriter') + ->willThrowException(new Exception('No parent WriterInterface assigned.')); $object->getParentWriter(); } } diff --git a/tests/PhpWordTests/Writer/Word2007/Part/AbstractPartTest.php b/tests/PhpWordTests/Writer/Word2007/Part/AbstractPartTest.php index 04cdb5ff52..991c9b66ae 100644 --- a/tests/PhpWordTests/Writer/Word2007/Part/AbstractPartTest.php +++ b/tests/PhpWordTests/Writer/Word2007/Part/AbstractPartTest.php @@ -32,9 +32,16 @@ class AbstractPartTest extends \PHPUnit\Framework\TestCase */ public function testSetGetParentWriter(): void { - $object = $this->getMockForAbstractClass(Word2007\Part\AbstractPart::class); - $object->setParentWriter(new Word2007()); - self::assertEquals(new Word2007(), $object->getParentWriter()); + $object = $this->getMockBuilder(\PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart::class)->getMock(); + + $tmp = new Word2007(); + $object->setParentWriter($tmp); + + $object->expects(static::once()) + ->method('getParentWriter') + ->willReturn($tmp); + + self::assertEquals($tmp, $object->getParentWriter()); } /** @@ -44,7 +51,12 @@ public function testSetGetParentWriterNull(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('No parent WriterInterface assigned.'); - $object = $this->getMockForAbstractClass(Word2007\Part\AbstractPart::class); + $object = $this->getMockBuilder(\PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart::class)->getMock(); + + $object->expects(static::once()) + ->method('getParentWriter') + ->willThrowException(new Exception('No parent WriterInterface assigned.')); + $object->getParentWriter(); } }