Code Duplication    Length = 22-24 lines in 2 locations

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

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