<commit_before><?php

namespace Oro\Bundle\WorkflowBundle\Tests\Unit\Processor\Transition;

use Oro\Bundle\WorkflowBundle\Processor\Context\TransitionContext;
use Oro\Bundle\WorkflowBundle\Processor\Transition\ErrorResponseProcessor;
use Symfony\Component\HttpFoundation\Response;

class ErrorResponseProcessorTest extends \PHPUnit_Framework_TestCase
{
    /** @var ErrorResponseProcessor */
    protected $processor;

    protected function setUp()
    {
        $this->processor = new ErrorResponseProcessor();
    }

    public function testBuildResponseFromDefinedFields()
    {
        /** @var TransitionContext|\PHPUnit_Framework_MockObject_MockObject $context */
        $context = $this->createMock(TransitionContext::class);
        $context->expects($this->once())
            ->method('hasError')
            ->willReturn(true);

        $context->expects($this->exactly(2))
            ->method('get')
            ->withConsecutive(['responseCode'], ['responseMessage'])
            ->willReturnOnConsecutiveCalls(418, 'message');

        $context->expects($this->once())->method('setResult')->willReturnCallback(
            function (Response $response) {
                $this->assertEquals(418, $response->getStatusCode());
                $this->assertAttributeEquals('message', 'statusText', $response);
            }
        );
        $context->expects($this->once())->method('setProcessed')->with(true);

        $this->processor->process($context);
    }

    public function testBuildResponseFromError()
    {
        $response = new Response();
        $response->setStatusCode(500, 'error message');

        /** @var TransitionContext|\PHPUnit_Framework_MockObject_MockObject $context */
        $context = $this->createMock(TransitionContext::class);
        $context->expects($this->once())
            ->method('hasError')
            ->willReturn(true);

        $context->expects($this->exactly(2))
            ->method('get')
            ->withConsecutive(['responseCode'], ['responseMessage'])
            ->willReturn(null);

        $context->expects($this->once())->method('getError')->willReturn(new \Exception('error message'));
        $context->expects($this->once())->method('setResult')->with($response);
        $context->expects($this->once())->method('setProcessed')->with(true);

        $this->processor->process($context);
    }

    public function testSkipHasNoErrors()
    {
        /** @var TransitionContext|\PHPUnit_Framework_MockObject_MockObject $context */
        $context = $this->createMock(TransitionContext::class);
        $context->expects($this->once())->method('hasError')->willReturn(false);
        $context->expects($this->never())->method('setResult');

        $this->processor->process($context);
    }
}<commit_msg> BAP-16334: Random unit test failures ErrorResponseProcessorTest::testBuildResponseFromDefinedFields (#16093)<commit_after><?php

namespace Oro\Bundle\WorkflowBundle\Tests\Unit\Processor\Transition;

use Oro\Bundle\WorkflowBundle\Processor\Context\TransitionContext;
use Oro\Bundle\WorkflowBundle\Processor\Transition\ErrorResponseProcessor;
use Symfony\Component\HttpFoundation\Response;

class ErrorResponseProcessorTest extends \PHPUnit_Framework_TestCase
{
    /** @var ErrorResponseProcessor */
    protected $processor;

    protected function setUp()
    {
        $this->processor = new ErrorResponseProcessor();
    }

    public function testBuildResponseFromDefinedFields()
    {
        /** @var TransitionContext|\PHPUnit_Framework_MockObject_MockObject $context */
        $context = $this->createMock(TransitionContext::class);
        $context->expects($this->once())
            ->method('hasError')
            ->willReturn(true);

        $context->expects($this->exactly(2))
            ->method('get')
            ->withConsecutive(['responseCode'], ['responseMessage'])
            ->willReturnOnConsecutiveCalls(418, 'message');

        $context->expects($this->once())->method('setResult')->willReturnCallback(
            function (Response $response) {
                $this->assertEquals(418, $response->getStatusCode());
                $this->assertAttributeEquals('message', 'statusText', $response);
            }
        );
        $context->expects($this->once())->method('setProcessed')->with(true);

        $this->processor->process($context);
    }

    public function testBuildResponseFromError()
    {
        /** @var TransitionContext|\PHPUnit_Framework_MockObject_MockObject $context */
        $context = $this->createMock(TransitionContext::class);
        $context->expects($this->once())
            ->method('hasError')
            ->willReturn(true);

        $context->expects($this->exactly(2))
            ->method('get')
            ->withConsecutive(['responseCode'], ['responseMessage'])
            ->willReturn(null);

        $context->expects($this->once())->method('getError')->willReturn(new \Exception('error message'));
        $context->expects($this->once())->method('setResult')->willReturnCallback(
            function (Response $response) {
                $this->assertEquals(500, $response->getStatusCode());
                $this->assertAttributeEquals('error message', 'statusText', $response);
            }
        );
        $context->expects($this->once())->method('setProcessed')->with(true);

        $this->processor->process($context);
    }

    public function testSkipHasNoErrors()
    {
        /** @var TransitionContext|\PHPUnit_Framework_MockObject_MockObject $context */
        $context = $this->createMock(TransitionContext::class);
        $context->expects($this->once())->method('hasError')->willReturn(false);
        $context->expects($this->never())->method('setResult');

        $this->processor->process($context);
    }
}
{'fraction_non_alphanumeric': 0.15929812489248238, 'fraction_numerical': 0.0055049028040598654, 'mean_word_length': 3.2971175166297115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3321183', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1488, 'n_words': 190}