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

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