Skip to content

AbstractElement::setNewStyle doesn't work with object #2764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks
AntoineMarques opened this issue Mar 10, 2025 · 0 comments
Open
2 tasks

AbstractElement::setNewStyle doesn't work with object #2764

AntoineMarques opened this issue Mar 10, 2025 · 0 comments

Comments

@AntoineMarques
Copy link

Describe the bug and add attachments

Passed style object to an element constructor isn't used resulting in bugs.
This is because method setNewStyle creates a new style object instead of using the given one.

Expected behavior

Passed object should set as element's style object

Steps to reproduce

<?php

namespace PhpOffice\PhpWordTests\Element;

use BadMethodCallException;
use PhpOffice\PhpWord\Element\Cell;
use PhpOffice\PhpWord\Style\Cell as CellStyle;
use PhpOffice\PhpWordTests\AbstractWebServerEmbedded;

/**
 * Test class for PhpOffice\PhpWord\Element\Cell.
 *
 * @runTestsInSeparateProcesses
 */
class CellTest extends AbstractWebServerEmbedded
{
    /**
     * New instance with object.
     */
    public function testConstructWithStyleObject(): void
    {
        $oStyle = (new CellStyle())->setWidth(17);
        $oCell = new Cell(null, $oStyle);

        self::assertNotNull($oCell->getStyle());
        self::assertInstanceOf(CellStyle::class, $oCell->getStyle());
        self::assertSame($oStyle, $oCell->getStyle());
        self::assertEquals(17, $oCell->getWidth());
    }
}

PHPWord version(s) where the bug happened

master

PHP version(s) where the bug happened

7.4

Priority

  • I want to crowdfund the bug fix (with @algora-io) and fund a community developer.
  • I want to pay the bug fix and fund a maintainer for that. (Contact @Progi1984)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant