<commit_before><?php

namespace Lmc\Steward\Test;

/**
 * This is a workaround for the order in which PHPUnit executes addFailure on listeners and tearDown
 * If taking screenshot using addFailure, tearDown was already called and the browser closed
 */
class WebdriverListener extends \PHPUnit_Framework_BaseTestListener
{
    public function startTest(\PHPUnit_Framework_Test $test)
    {
        if (!$test instanceof AbstractTestCase) {
            throw new \InvalidArgumentException('Test case must be descendant of Lmc\Steward\Test\AbstractTestCase');
        }

        $test->log('Initializing "%s" webdriver for "%s::%s"', BROWSER_NAME, get_class($test), $test->getName());

        $capabilities = [
            \WebDriverCapabilityType::BROWSER_NAME => BROWSER_NAME,
        ];

        if (BROWSER_NAME == 'internet explorer') {
            // When set to true, this capability clears the cache, cookies, history, and saved form data.
            $capabilities['ie.ensureCleanSession'] = true;
        }

        $test->wd = \RemoteWebDriver::create(SERVER_URL .  '/wd/hub', $capabilities, $timeoutInMs = 2*60*1000);
    }

    public function endTest(\PHPUnit_Framework_Test $test, $time)
    {
        if (!$test instanceof AbstractTestCase) {
            throw new \InvalidArgumentException('Test case must be descendant of Lmc\Steward\Test\AbstractTestCase');
        }

        if ($test->wd instanceof \RemoteWebDriver) {
            $test->log(
                'Destroying "%s" webdriver for "%s::%s" (session %s)',
                BROWSER_NAME,
                get_class($test),
                $test->getName(),
                $test->wd->getSessionID()
            );

            // Necessary for phantomjs - see https://github.com/detro/ghostdriver/issues/343
            $test->wd->getCommandExecutor()->execute('deleteAllCookies');

            $test->wd->close();
            $test->wd->quit();
        }
    }
}<commit_msg>Predefine PhantomJS screensize, so it won't use some weird magic default<commit_after><?php

namespace Lmc\Steward\Test;

/**
 * This is a workaround for the order in which PHPUnit executes addFailure on listeners and tearDown
 * If taking screenshot using addFailure, tearDown was already called and the browser closed
 */
class WebdriverListener extends \PHPUnit_Framework_BaseTestListener
{
    public function startTest(\PHPUnit_Framework_Test $test)
    {
        if (!$test instanceof AbstractTestCase) {
            throw new \InvalidArgumentException('Test case must be descendant of Lmc\Steward\Test\AbstractTestCase');
        }

        $test->log('Initializing "%s" webdriver for "%s::%s"', BROWSER_NAME, get_class($test), $test->getName());

        $capabilities = [
            \WebDriverCapabilityType::BROWSER_NAME => BROWSER_NAME,
        ];

        if (BROWSER_NAME == 'internet explorer') {
            // When set to true, this capability clears the cache, cookies, history, and saved form data.
            $capabilities['ie.ensureCleanSession'] = true;
        }

        $test->wd = \RemoteWebDriver::create(SERVER_URL .  '/wd/hub', $capabilities, $timeoutInMs = 2*60*1000);

        // Force screen resolution for Phantom, otherwise it uses some weird unchangeable defaults
        if (BROWSER_NAME == 'phantomjs') {
            $test->wd->manage()->window()->setSize(new \WebDriverDimension(1280, 1024));
        }
    }

    public function endTest(\PHPUnit_Framework_Test $test, $time)
    {
        if (!$test instanceof AbstractTestCase) {
            throw new \InvalidArgumentException('Test case must be descendant of Lmc\Steward\Test\AbstractTestCase');
        }

        if ($test->wd instanceof \RemoteWebDriver) {
            $test->log(
                'Destroying "%s" webdriver for "%s::%s" (session %s)',
                BROWSER_NAME,
                get_class($test),
                $test->getName(),
                $test->wd->getSessionID()
            );

            // Necessary for phantomjs - see https://github.com/detro/ghostdriver/issues/343
            $test->wd->getCommandExecutor()->execute('deleteAllCookies');

            $test->wd->close();
            $test->wd->quit();
        }
    }
}
{'fraction_non_alphanumeric': 0.11967642160361647, 'fraction_numerical': 0.006661908160837497, 'mean_word_length': 2.517991631799163, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 2, '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': '5977143', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1129, 'n_words': 294}