Code Duplication    Length = 34-38 lines in 3 locations

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

@@ 509-546 (lines=38) @@
506
     * @see \eZ\Publish\API\Repository\LanguageService::createLanguage()
507
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testCreateLanguage
508
     */
509
    public function testCreateLanguageInTransactionWithRollback()
510
    {
511
        $repository = $this->getRepository();
512
513
        /* BEGIN: Use Case */
514
        $languageService = $repository->getContentLanguageService();
515
516
        // Start a new transaction
517
        $repository->beginTransaction();
518
519
        try {
520
            // Get create struct and set properties
521
            $languageCreate = $languageService->newLanguageCreateStruct();
522
            $languageCreate->enabled = true;
523
            $languageCreate->name = 'English (New Zealand)';
524
            $languageCreate->languageCode = 'eng-NZ';
525
526
            // Create new language
527
            $languageService->createLanguage($languageCreate);
528
        } catch (Exception $e) {
529
            // Cleanup hanging transaction on error
530
            $repository->rollback();
531
            throw $e;
532
        }
533
534
        // Rollback all changes
535
        $repository->rollback();
536
537
        try {
538
            // This call will fail with a "NotFoundException"
539
            $languageService->loadLanguage('eng-NZ');
540
        } catch (NotFoundException $e) {
541
            // Expected execution path
542
        }
543
        /* END: Use Case */
544
545
        $this->assertTrue(isset($e), 'Can still load language after rollback');
546
    }
547
548
    /**
549
     * Test for the createLanguage() method.
@@ 554-587 (lines=34) @@
551
     * @see \eZ\Publish\API\Repository\LanguageService::createLanguage()
552
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testCreateLanguage
553
     */
554
    public function testCreateLanguageInTransactionWithCommit()
555
    {
556
        $repository = $this->getRepository();
557
558
        /* BEGIN: Use Case */
559
        $languageService = $repository->getContentLanguageService();
560
561
        // Start a new transaction
562
        $repository->beginTransaction();
563
564
        try {
565
            // Get create struct and set properties
566
            $languageCreate = $languageService->newLanguageCreateStruct();
567
            $languageCreate->enabled = true;
568
            $languageCreate->name = 'English (New Zealand)';
569
            $languageCreate->languageCode = 'eng-NZ';
570
571
            // Create new language
572
            $languageService->createLanguage($languageCreate);
573
574
            // Commit all changes
575
            $repository->commit();
576
        } catch (Exception $e) {
577
            // Cleanup hanging transaction on error
578
            $repository->rollback();
579
            throw $e;
580
        }
581
582
        // Load new language
583
        $language = $languageService->loadLanguage('eng-NZ');
584
        /* END: Use Case */
585
586
        $this->assertEquals('eng-NZ', $language->languageCode);
587
    }
588
589
    /**
590
     * Test for the updateLanguageName() method.

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

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