Skip to content

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

Open
@AntoineMarques

Description

@AntoineMarques

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions