<commit_before><?php

namespace Tests\ShopwarePlugins\Connect\Component;

class ConnectFactoryTest extends \Tests\ShopwarePlugins\Connect\ConnectTestHelper
{

    private $connectFactory;
    private $configMock;
    private $localProductQuery;

    public function setUp()
    {
        parent::setUp();

        $this->connectFactory = $this->getMockBuilder('ShopwarePlugins\Connect\Components\ConnectFactory')
            ->setMethods(array('getConfigComponent', 'getLocalProductQuery', 'getRemoteProductQuery'))
            ->getMock();

        $this->configMock = $this->getMockBuilder('\ShopwarePlugins\Connect\Components\Config')
            ->setConstructorArgs([Shopware()->Models()])
            ->setMethods(['getConfig'])
            ->getMock();

        $this->localProductQuery = $this->getMockBuilder('ShopwarePlugins\Connect\Components\ProductQuery\LocalProductQuery')
            ->disableOriginalConstructor()
            ->getMock();

        $this->connectFactory->method('getConfigComponent')->willReturn($this->configMock);
        $this->connectFactory->method('getLocalProductQuery')->willReturn($this->localProductQuery);

    }

    public function testCreateSDKDefaultLocal()
    {
        $this->configMock->method('getConfig')->willReturn('sn.connect.local');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.connect.local', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKSemLocal()
    {
        putenv("_TRANSACTION_HOST");

        $this->configMock->method('getConfig')->willReturn('semdemo.connect.local');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.connect.local', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKRandomLocal()
    {
        putenv("_TRANSACTION_HOST");
        $prefix = $this->generateRandomString();
        $this->configMock->method('getConfig')->willReturn($prefix . '.connect.local');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.connect.local', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKDefaultStaging()
    {
        putenv("_TRANSACTION_HOST");
        $this->configMock->method('getConfig')->willReturn('sn.stage.connect.shopware.com');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.stage.connect.shopware.com', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKSemStaging()
    {
        putenv("_TRANSACTION_HOST");
        $this->configMock->method('getConfig')->willReturn('sn.sem.stage.connect.shopware.com');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.stage.connect.shopware.com', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKMarketplaceStaging()
    {
        putenv("_TRANSACTION_HOST");
        $prefix = $this->generateRandomString();
        $this->configMock->method('getConfig')->willReturn($prefix . '.stage.connect.shopware.com');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.stage.connect.shopware.com', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKMarketplaceStagingWithMultipleStagings()
    {
        putenv("_TRANSACTION_HOST");
        $prefix = $this->generateRandomString();
        $suffix = '.stage'.rand(0, 9).'.connect.shopware.com';
        $this->configMock->method('getConfig')->willReturn($prefix . $suffix);
        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction' . $suffix, getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKLive()
    {
        putenv("_TRANSACTION_HOST");
        //everything that is "unknown" defaults to live (the default value of transactionHost in the DependencyResolver)
        $prefix = $this->generateRandomString(20);
        $this->configMock->method('getConfig')->willReturn($prefix);

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertFalse(getenv('_TRANSACTION_HOST'));<commit_msg>CON-4147 Fix for the random breaking of the tests<commit_after><?php

namespace Tests\ShopwarePlugins\Connect\Component;

class ConnectFactoryTest extends \Tests\ShopwarePlugins\Connect\ConnectTestHelper
{

    private $connectFactory;
    private $configMock;
    private $localProductQuery;

    public function setUp()
    {
        parent::setUp();

        $this->connectFactory = $this->getMockBuilder('ShopwarePlugins\Connect\Components\ConnectFactory')
            ->setMethods(array('getConfigComponent', 'getLocalProductQuery', 'getRemoteProductQuery'))
            ->getMock();

        $this->configMock = $this->getMockBuilder('\ShopwarePlugins\Connect\Components\Config')
            ->setConstructorArgs([Shopware()->Models()])
            ->setMethods(['getConfig'])
            ->getMock();

        $this->localProductQuery = $this->getMockBuilder('ShopwarePlugins\Connect\Components\ProductQuery\LocalProductQuery')
            ->disableOriginalConstructor()
            ->getMock();

        $this->connectFactory->method('getConfigComponent')->willReturn($this->configMock);
        $this->connectFactory->method('getLocalProductQuery')->willReturn($this->localProductQuery);

    }

    public function testCreateSDKDefaultLocal()
    {
        $this->configMock->method('getConfig')->willReturn('sn.connect.local');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.connect.local', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKSemLocal()
    {
        putenv("_TRANSACTION_HOST");

        $this->configMock->method('getConfig')->willReturn('semdemo.connect.local');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.connect.local', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKRandomLocal()
    {
        putenv("_TRANSACTION_HOST");
        $prefix = $this->generateRandomString();
        $this->configMock->method('getConfig')->willReturn($prefix . '.connect.local');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.connect.local', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKDefaultStaging()
    {
        putenv("_TRANSACTION_HOST");
        $this->configMock->method('getConfig')->willReturn('sn.stage.connect.shopware.com');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.stage.connect.shopware.com', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKSemStaging()
    {
        putenv("_TRANSACTION_HOST");
        $this->configMock->method('getConfig')->willReturn('sn.sem.stage.connect.shopware.com');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.stage.connect.shopware.com', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKMarketplaceStaging()
    {
        putenv("_TRANSACTION_HOST");
        $prefix = $this->generateRandomString();
        $this->configMock->method('getConfig')->willReturn($prefix . '.stage.connect.shopware.com');

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction.stage.connect.shopware.com', getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKMarketplaceStagingWithMultipleStagings()
    {
        putenv("_TRANSACTION_HOST");
        $prefix = $this->generateRandomString();
        $suffix = '.stage'.rand(1, 9).'.connect.shopware.com';
        $this->configMock->method('getConfig')->willReturn($prefix . $suffix);
        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertEquals('transaction' . $suffix, getenv('_TRANSACTION_HOST'));
    }

    public function testCreateSDKLive()
    {
        putenv("_TRANSACTION_HOST");
        //everything that is "unknown" defaults to live (the default value of transactionHost in the DependencyResolver)
        $prefix = $this->generateRandomString(20);
        $this->configMock->method('getConfig')->willReturn($prefix);

        $this->assertEquals(null, getenv('_TRANSACTION_HOST'));
        $this->connectFactory->createSDK();

        $this->assertFalse(getenv('_TRANSACTION_HOST'));
{'fraction_non_alphanumeric': 0.15315217391304348, 'fraction_numerical': 0.0013043478260869566, 'mean_word_length': 3.762422360248447, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 167, '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': '3223180', 'n_tokens_mistral': 2590, 'n_tokens_neox': 2479, 'n_words': 291}