<commit_before><?php
/**
 * (c) Spryker Systems GmbH copyright protected
 */

namespace YvesUnit\Pyz\Yves\Checkout\Process;

use Generated\Shared\Transfer\ItemTransfer;
use Generated\Shared\Transfer\QuoteTransfer;
use Pyz\Yves\Checkout\Form\FormCollectionHandlerInterface;
use Pyz\Yves\Checkout\Process\StepProcess;
use Pyz\Yves\Checkout\Process\Steps\StepInterface;
use Spryker\Client\Cart\CartClientInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class StepProcessTest extends \PHPUnit_Framework_TestCase
{

    /**
     * @return void
     */
    public function testStepProcessPreCheckShouldReturnRedirectResponseWhenPreconditionReturnsFalse()
    {
        $escapeRoute = 'escape_route';
        $stepMock = $this->createStepMock();
        $stepMock->expects($this->once())->method('preCondition')->willReturn(false);
        $stepMock->expects($this->once())->method('getEscapeRoute')->willReturn($escapeRoute);

        $stepProcess = $this->createStepProcess([$stepMock], new QuoteTransfer());
        $response = $stepProcess->process($this->createRequest());

        $this->assertInstanceOf(RedirectResponse::class, $response);
        $this->assertEquals($escapeRoute, $response->getTargetUrl());
    }

    /**
     * @return void
     */
    public function testStepProcessWhenRequireInputIsFalseShouldCallExecuteWithoutTriggeringFormHandling()
    {
        $stepRoute = 'test';
        $nextStepRoute = 'next_step_route';
        $quoteTransfer = new QuoteTransfer();

        $stepMock = $this->createStepMock();
        $stepMock->expects($this->once())->method('preCondition')->willReturn(true);
        $stepMock->expects($this->exactly(2))->method('postCondition')->willReturn(true);
        $stepMock->expects($this->exactly(4))->method('getStepRoute')->willReturn($stepRoute);
        $stepMock->expects($this->once())->method('requireInput')->willReturn(false);
        $stepMock->expects($this->once())->method('execute')->willReturnCallback(
            function (Request $request, QuoteTransfer $quoteTransfer) {<commit_msg>Fix spelling of PreCondition to be consistent with the rest of the framework.<commit_after><?php
/**
 * (c) Spryker Systems GmbH copyright protected
 */

namespace YvesUnit\Pyz\Yves\Checkout\Process;

use Generated\Shared\Transfer\ItemTransfer;
use Generated\Shared\Transfer\QuoteTransfer;
use Pyz\Yves\Checkout\Form\FormCollectionHandlerInterface;
use Pyz\Yves\Checkout\Process\StepProcess;
use Pyz\Yves\Checkout\Process\Steps\StepInterface;
use Spryker\Client\Cart\CartClientInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class StepProcessTest extends \PHPUnit_Framework_TestCase
{

    /**
     * @return void
     */
    public function testStepProcessPreCheckShouldReturnRedirectResponseWhenPreConditionReturnsFalse()
    {
        $escapeRoute = 'escape_route';
        $stepMock = $this->createStepMock();
        $stepMock->expects($this->once())->method('preCondition')->willReturn(false);
        $stepMock->expects($this->once())->method('getEscapeRoute')->willReturn($escapeRoute);

        $stepProcess = $this->createStepProcess([$stepMock], new QuoteTransfer());
        $response = $stepProcess->process($this->createRequest());

        $this->assertInstanceOf(RedirectResponse::class, $response);
        $this->assertEquals($escapeRoute, $response->getTargetUrl());
    }

    /**
     * @return void
     */
    public function testStepProcessWhenRequireInputIsFalseShouldCallExecuteWithoutTriggeringFormHandling()
    {
        $stepRoute = 'test';
        $nextStepRoute = 'next_step_route';
        $quoteTransfer = new QuoteTransfer();

        $stepMock = $this->createStepMock();
        $stepMock->expects($this->once())->method('preCondition')->willReturn(true);
        $stepMock->expects($this->exactly(2))->method('postCondition')->willReturn(true);
        $stepMock->expects($this->exactly(4))->method('getStepRoute')->willReturn($stepRoute);
        $stepMock->expects($this->once())->method('requireInput')->willReturn(false);
        $stepMock->expects($this->once())->method('execute')->willReturnCallback(
            function (Request $request, QuoteTransfer $quoteTransfer) {
{'fraction_non_alphanumeric': 0.14440993788819875, 'fraction_numerical': 0.0008873114463176575, 'mean_word_length': 4.722081218274112, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, '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': '3748736', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1239, 'n_words': 168}