Code Duplication    Length = 24-26 lines in 2 locations

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 2 locations

@@ 1682-1705 (lines=24) @@
1679
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1680
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1681
     */
1682
    public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept()
1683
    {
1684
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
1685
1686
        $repository = $this->getRepository();
1687
1688
        $contentService = $repository->getContentService();
1689
1690
        /* BEGIN: Use Case */
1691
        $draft = $this->createContentDraftVersion1();
1692
1693
        // Now create an update struct and modify some fields
1694
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1695
        // The name field does not accept a stdClass object as its input
1696
        $contentUpdateStruct->setField('name', new \stdClass(), 'eng-US');
1697
1698
        // Throws an InvalidArgumentException, since the value for field "name"
1699
        // is not accepted
1700
        $contentService->updateContent(
1701
            $draft->getVersionInfo(),
1702
            $contentUpdateStruct
1703
        );
1704
        /* END: Use Case */
1705
    }
1706
1707
    /**
1708
     * Test for the updateContent() method.
@@ 1713-1738 (lines=26) @@
1710
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1711
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1712
     */
1713
    public function testUpdateContentWhenMandatoryFieldIsEmpty()
1714
    {
1715
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException::class);
1716
1717
        $repository = $this->getRepository();
1718
1719
        $contentService = $repository->getContentService();
1720
1721
        /* BEGIN: Use Case */
1722
        $draft = $this->createContentDraftVersion1();
1723
1724
        // Now create an update struct and set a mandatory field to null
1725
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1726
        $contentUpdateStruct->setField('name', null);
1727
1728
        // Don't set this, then the above call without languageCode will fail
1729
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1730
1731
        // This call will fail with a "ContentFieldValidationException", because the
1732
        // mandatory "name" field is empty.
1733
        $contentService->updateContent(
1734
            $draft->getVersionInfo(),
1735
            $contentUpdateStruct
1736
        );
1737
        /* END: Use Case */
1738
    }
1739
1740
    /**
1741
     * Test for the updateContent() method.