<commit_before><?php

namespace SMB\Screru\Traits;

use SMB\Screru\Wrapper\RemoteWebDriver;
use SMB\Screru\Factory\DesiredCapabilities;
use SMB\Screru\Exception\DisabledWebDriverException;
use SMB\Screru\Exception\NotSpecifiedWebDriverException;
use SMB\Screru\Screenshot\Screenshot;
use SMB\Screru\Elements\SpecPool;

use Facebook\WebDriver\WebDriverDimension;
use Facebook\WebDriver\Exception\TimeOutException;
use Facebook\WebDriver\Exception\NoSuchWindowException;

/**
 * Testable
 * 
 * \PHPUnit_Framework_TestCaseを継承したクラスでuseしてください
 * 
 * <code>
 *  class Base extends \PHPUnit_Framework_TestCase
 *  {
 *      // alias for function...
 *      use \SMB\Screru\Traits\Testable {
 *          setUp as protected traitSetUp;
 *          tearDown as protected traitTearDown;
 *      }
 *  }
 * </code>
 */
trait Testable
{
    /**
     * selenium server url
     * @var string
     */
    protected $seleniumServerUrl = '';

    /**
     * DesiredCapabilities
     * @var \Facebook\WebDriver\Remote\DesiredCapabilities
     */
    protected $capabilities;

    /**
     * Screenshot
     * @var \SMB\Screru\Screenshot\Screenshot
     */
    protected $screenshot;

    /**
     * テスト(assert)失敗時にキャプチャを撮るかどうか
     * @var boolean
     */
    protected $takeCaptureWhenAssertionFails = false;

    /**
     * Wrapper of RemoteWebDriver
     * @var \SMB\Screru\Wrapper\RemoteWebDriver
     */
    private $driver;

    /**
     * コンストラクタ
     */
    public function __construct()
    {
        if ($this->seleniumServerUrl === '') {
            $this->seleniumServerUrl = getenv('SELENIUM_SERVER_URL');
        }
    }

    /**
     * setUp
     */
    protected function setUp()
    {
        parent::setUp();
    }

    /**
     * tearDown
     */
    protected function tearDown()
    {
        parent::tearDown();

        // If you want to run closeDriver(), overwride tearDown()
        $this->quitDriver();
    }

    /**
     * driver quit
     * 
     * quit() will close all windows
     */
    protected function quitDriver()
    {
        if (!$this->isRunningDriver()) {
            return;
        }

        if ($this->takeCaptureWhenAssertionFails() === true) {
            $this->doTakeCaptureWhenAssertionFails();
        }

        try {
            $this->driver->quit();
        } catch (NoSuchWindowException $e) {
            // browser may have died
        }
        $this->driver = null;
    }

    /**
     * driver close
     * 
     * close() will close the current window
     */
    protected function closeDriver()
    {
        if (!$this->isRunningDriver()) {
            return;
        }

        if ($this->takeCaptureWhenAssertionFails() === true) {
            $this->doTakeCaptureWhenAssertionFails();
        }

        try {
            $this->driver->close();
        } catch (NoSuchWindowException $e) {
            // browser may have died
        }<commit_msg>Workaround for `Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http DELETE`.<commit_after><?php

namespace SMB\Screru\Traits;

use SMB\Screru\Wrapper\RemoteWebDriver;
use SMB\Screru\Factory\DesiredCapabilities;
use SMB\Screru\Exception\DisabledWebDriverException;
use SMB\Screru\Exception\NotSpecifiedWebDriverException;
use SMB\Screru\Screenshot\Screenshot;
use SMB\Screru\Elements\SpecPool;

use Facebook\WebDriver\WebDriverDimension;
use Facebook\WebDriver\Exception\TimeOutException;
use Facebook\WebDriver\Exception\NoSuchWindowException;
use Facebook\WebDriver\Exception\WebDriverCurlException;

/**
 * Testable
 * 
 * \PHPUnit_Framework_TestCaseを継承したクラスでuseしてください
 * 
 * <code>
 *  class Base extends \PHPUnit_Framework_TestCase
 *  {
 *      // alias for function...
 *      use \SMB\Screru\Traits\Testable {
 *          setUp as protected traitSetUp;
 *          tearDown as protected traitTearDown;
 *      }
 *  }
 * </code>
 */
trait Testable
{
    /**
     * selenium server url
     * @var string
     */
    protected $seleniumServerUrl = '';

    /**
     * DesiredCapabilities
     * @var \Facebook\WebDriver\Remote\DesiredCapabilities
     */
    protected $capabilities;

    /**
     * Screenshot
     * @var \SMB\Screru\Screenshot\Screenshot
     */
    protected $screenshot;

    /**
     * テスト(assert)失敗時にキャプチャを撮るかどうか
     * @var boolean
     */
    protected $takeCaptureWhenAssertionFails = false;

    /**
     * Wrapper of RemoteWebDriver
     * @var \SMB\Screru\Wrapper\RemoteWebDriver
     */
    private $driver;

    /**
     * コンストラクタ
     */
    public function __construct()
    {
        if ($this->seleniumServerUrl === '') {
            $this->seleniumServerUrl = getenv('SELENIUM_SERVER_URL');
        }
    }

    /**
     * setUp
     */
    protected function setUp()
    {
        parent::setUp();
    }

    /**
     * tearDown
     */
    protected function tearDown()
    {
        parent::tearDown();

        // If you want to run closeDriver(), overwride tearDown()
        $this->quitDriver();
    }

    /**
     * driver quit
     * 
     * quit() will close all windows
     */
    protected function quitDriver()
    {
        if (!$this->isRunningDriver()) {
            return;
        }

        if ($this->takeCaptureWhenAssertionFails() === true) {
            $this->doTakeCaptureWhenAssertionFails();
        }

        try {
            $this->driver->quit();
        } catch (NoSuchWindowException $e) {
            // browser may have died
        }
        $this->driver = null;
    }

    /**
     * driver close
     * 
     * close() will close the current window
     */
    protected function closeDriver()
    {
        if (!$this->isRunningDriver()) {
            return;
        }

        if ($this->takeCaptureWhenAssertionFails() === true) {
            $this->doTakeCaptureWhenAssertionFails();
        }

        try {
            $this->driver->close();
        } catch (NoSuchWindowException $e) {
            // browser may have died
        } catch (WebDriverCurlException $e) {
            // Workaround for `Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http DELETE`
        }

{'fraction_non_alphanumeric': 0.11858869650441033, 'fraction_numerical': 0.0, 'mean_word_length': 2.0971168437025796, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4704100', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1853, 'n_words': 334}