Code Duplication    Length = 38-38 lines in 2 locations

eZ/Publish/Core/Repository/Tests/Service/Mock/RoleTest.php 2 locations

@@ 915-952 (lines=38) @@
912
     * @expectedException \Exception
913
     * @expectedExceptionMessage Handler threw an exception
914
     */
915
    public function testDeletePolicyWithRollback()
916
    {
917
        $repository = $this->getRepositoryMock();
918
        $roleServiceMock = $this->getPartlyMockedRoleService();
919
        $policyMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\Policy');
920
921
        $policyMock->expects($this->any())
922
            ->method('__get')
923
            ->will(
924
                $this->returnValueMap(
925
                    [
926
                        ['id', 42],
927
                    ]
928
                )
929
            );
930
931
        $repository->expects($this->once())
932
            ->method('hasAccess')
933
            ->with(
934
                $this->equalTo('role'),
935
                $this->equalTo('update')
936
            )->will($this->returnValue(true));
937
938
        $repository->expects($this->once())->method('beginTransaction');
939
940
        $userHandlerMock = $this->getPersistenceMockHandler('User\\Handler');
941
942
        $userHandlerMock->expects($this->once())
943
            ->method('deletePolicy')
944
            ->with(
945
                $this->equalTo(42)
946
            )->will($this->throwException(new \Exception('Handler threw an exception')));
947
948
        $repository->expects($this->once())->method('rollback');
949
950
        /* @var \eZ\Publish\API\Repository\Values\User\Policy $policyMock */
951
        $roleServiceMock->deletePolicy($policyMock);
952
    }
953
954
    /**
955
     * Test for the deletePolicy() method.
@@ 959-996 (lines=38) @@
956
     *
957
     * @covers \eZ\Publish\Core\Repository\RoleService::deletePolicy
958
     */
959
    public function testDeletePolicy()
960
    {
961
        $repository = $this->getRepositoryMock();
962
        $roleServiceMock = $this->getPartlyMockedRoleService();
963
        $policyMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\Policy');
964
965
        $policyMock->expects($this->any())
966
            ->method('__get')
967
            ->will(
968
                $this->returnValueMap(
969
                    [
970
                        ['id', 42],
971
                    ]
972
                )
973
            );
974
975
        $repository->expects($this->once())
976
            ->method('hasAccess')
977
            ->with(
978
                $this->equalTo('role'),
979
                $this->equalTo('update')
980
            )->will($this->returnValue(true));
981
982
        $repository->expects($this->once())->method('beginTransaction');
983
984
        $userHandlerMock = $this->getPersistenceMockHandler('User\\Handler');
985
986
        $userHandlerMock->expects($this->once())
987
            ->method('deletePolicy')
988
            ->with(
989
                $this->equalTo(42)
990
            );
991
992
        $repository->expects($this->once())->method('commit');
993
994
        /* @var \eZ\Publish\API\Repository\Values\User\Policy $policyMock */
995
        $roleServiceMock->deletePolicy($policyMock);
996
    }
997
998
    /**
999
     * Test for the removePolicy() method.