Code Duplication    Length = 34-38 lines in 3 locations

eZ/Publish/API/Repository/Tests/SectionServiceTest.php 1 location

@@ 740-776 (lines=37) @@
737
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection
738
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier
739
     */
740
    public function testCreateSectionInTransactionWithRollback()
741
    {
742
        $repository = $this->getRepository();
743
744
        /* BEGIN: Use Case */
745
        $sectionService = $repository->getSectionService();
746
747
        // Start a new transaction
748
        $repository->beginTransaction();
749
750
        try {
751
            // Get a create struct and set some properties
752
            $sectionCreate = $sectionService->newSectionCreateStruct();
753
            $sectionCreate->name = 'Test Section';
754
            $sectionCreate->identifier = 'uniqueKey';
755
756
            // Create a new section
757
            $sectionService->createSection($sectionCreate);
758
        } catch (Exception $e) {
759
            // Cleanup hanging transaction on error
760
            $repository->rollback();
761
            throw $e;
762
        }
763
764
        // Rollback all changes
765
        $repository->rollback();
766
767
        try {
768
            // This call will fail with a not found exception
769
            $sectionService->loadSectionByIdentifier('uniqueKey');
770
        } catch (NotFoundException $e) {
771
            // Expected execution path
772
        }
773
        /* END: Use Case */
774
775
        $this->assertTrue(isset($e), 'Can still load section after rollback.');
776
    }
777
778
    /**
779
     * Test for the createSection() method.

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

@@ 577-614 (lines=38) @@
574
     * @covers \eZ\Publish\API\Repository\LanguageService::createLanguage
575
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testCreateLanguage
576
     */
577
    public function testCreateLanguageInTransactionWithRollback()
578
    {
579
        $repository = $this->getRepository();
580
581
        /* BEGIN: Use Case */
582
        $languageService = $repository->getContentLanguageService();
583
584
        // Start a new transaction
585
        $repository->beginTransaction();
586
587
        try {
588
            // Get create struct and set properties
589
            $languageCreate = $languageService->newLanguageCreateStruct();
590
            $languageCreate->enabled = true;
591
            $languageCreate->name = 'English (New Zealand)';
592
            $languageCreate->languageCode = 'eng-NZ';
593
594
            // Create new language
595
            $languageService->createLanguage($languageCreate);
596
        } catch (Exception $e) {
597
            // Cleanup hanging transaction on error
598
            $repository->rollback();
599
            throw $e;
600
        }
601
602
        // Rollback all changes
603
        $repository->rollback();
604
605
        try {
606
            // This call will fail with a "NotFoundException"
607
            $languageService->loadLanguage('eng-NZ');
608
        } catch (NotFoundException $e) {
609
            // Expected execution path
610
        }
611
        /* END: Use Case */
612
613
        $this->assertTrue(isset($e), 'Can still load language after rollback');
614
    }
615
616
    /**
617
     * Test for the createLanguage() method.
@@ 622-655 (lines=34) @@
619
     * @covers \eZ\Publish\API\Repository\LanguageService::createLanguage
620
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testCreateLanguage
621
     */
622
    public function testCreateLanguageInTransactionWithCommit()
623
    {
624
        $repository = $this->getRepository();
625
626
        /* BEGIN: Use Case */
627
        $languageService = $repository->getContentLanguageService();
628
629
        // Start a new transaction
630
        $repository->beginTransaction();
631
632
        try {
633
            // Get create struct and set properties
634
            $languageCreate = $languageService->newLanguageCreateStruct();
635
            $languageCreate->enabled = true;
636
            $languageCreate->name = 'English (New Zealand)';
637
            $languageCreate->languageCode = 'eng-NZ';
638
639
            // Create new language
640
            $languageService->createLanguage($languageCreate);
641
642
            // Commit all changes
643
            $repository->commit();
644
        } catch (Exception $e) {
645
            // Cleanup hanging transaction on error
646
            $repository->rollback();
647
            throw $e;
648
        }
649
650
        // Load new language
651
        $language = $languageService->loadLanguage('eng-NZ');
652
        /* END: Use Case */
653
654
        $this->assertEquals('eng-NZ', $language->languageCode);
655
    }
656
657
    /**
658
     * Test for the updateLanguageName() method.