<commit_before><?php
require_once __DIR__.'/vendor/autoload.php';

use Symfony\Component\Finder\Finder;
use Robo\Task\Development\GenerateMarkdownDoc as Doc;

class RoboFile extends \Robo\Tasks
{
    const STABLE_BRANCH = '3.0';
    const REPO_BLOB_URL = 'https://github.com/Codeception/Codeception/blob';

    public function release()
    {
        $this->say("CODECEPTION RELEASE: ".\Codeception\Codecept::VERSION);
        $this->update();
        $this->buildDocs();
        $this->publishDocs();
        $this->buildPhar();
        $this->buildPhar5();
        $this->publishPhar();
        $this->publishGit();
        $this->publishBase(null, \Codeception\Codecept::VERSION);
        $this->versionBump();
        $this->update(); //update dependencies after release, because buildPhar5 set them to old versions
    }

    public function versionBump($version = '')
    {
        if (!$version) {
            $versionParts = explode('.', \Codeception\Codecept::VERSION);
            $versionParts[count($versionParts)-1]++;
            $version = implode('.', $versionParts);
        }
        $this->say("Bumping version to $version");
        $this->taskReplaceInFile('src/Codeception/Codecept.php')
            ->from(\Codeception\Codecept::VERSION)
            ->to($version)
            ->run();
    }

    public function update()
    {
        $this->clean();
        $this->taskComposerUpdate()->dir('tests/data/claypit')->run();
        $this->taskComposerUpdate()->run();
    }

    public function changed($change)
    {
        $this->taskChangelog()
            ->version(\Codeception\Codecept::VERSION)
            ->change($change)
            ->run();
    }

    protected function server()
    {
        $this->taskServer(8000)
            ->background()
            ->dir('tests/data/app')
            ->run();
    }

    public function testPhpbrowser($args = '', $opt = ['test|t' => null])
    {
        $test = $opt['test'] ? ':'.$opt['test'] : '';
        $this->server();
        $this->taskCodecept('./codecept')
            ->args($args)
            ->test('tests/unit/Codeception/Module/PhpBrowserTest.php'.$test)
            ->run();
    }

    public function testRestBrowser($args = '', $opt = ['test|t' => null])
    {
        $test = $opt['test'] ? ':'.$opt['test'] : '';
        $this->taskServer(8010)
            ->background()
            ->dir('tests/data')
            ->run();

        $this->taskCodecept('./codecept')
            ->test('tests/unit/Codeception/Module/PhpBrowserRestTest.php'.$test)
            ->args($args)
            ->run();
    }

    public function testCoverage()
    {
        $this->server();
        $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
            ->arg('suite', 'coverage')
            ->run();
    }

    public function testWebdriver($args = '', $opt = ['test|t' => null])
    {
        $test = $opt['test'] ? ':'.$opt['test'] : '';

        $this->taskServer(8000)
            ->dir('tests/data/app')
            ->background()
            ->host('0.0.0.0')
            ->run();

        $this->taskCodecept('./codecept')
            ->suite('web')
            ->args($args)
            ->run();
    }

    public function testLaunchServer()
    {
        $this->taskServer(8010)
            ->background()
            ->dir('tests/data/rest')
            ->run();
        $this->taskServer(8000)
            ->dir('tests/data/app')
            ->run();
    }

    public function testCli()
    {
        $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
            ->arg('suite', 'cli')
            ->run();

        $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
            ->arg('suite', 'tests/unit/Codeception/Command')
            ->run();
    }

    private function installDependenciesForPhp5()
    {
        $this->taskReplaceInFile('composer.json')
            ->regex('/"platform": \{.*?\}/')
            ->to('"platform": {"php": "5.6.0"}')
            ->run();

        $this->taskComposerUpdate()->run();
    }

    private function installDependenciesForPhp70()
    {
        $this->taskReplaceInFile('composer.json')
            ->regex('/"platform": \{.*?\}/')
            ->to('"platform": {"php": "7.0.0"}')
            ->run();

        $this->taskComposerUpdate()->run();
    }

    private function revertComposerJsonChanges()
    {
        $this->taskReplaceInFile('composer.json')
            ->regex('/"platform": \{.*?\}/')
            ->to('"platform": {}')
            ->run();
    }


    /**
     * @desc creates codecept.phar
     * @throws Exception
     */
    public function buildPhar()
    {
        $this->installDependenciesForPhp70();
        $this->packPhar('package/codecept.phar');
        $code = $this->taskExec('php codecept.phar')->dir('package')->run()->getExitCode();
        if ($code !== 0) {
            throw new Exception("There was problem compiling phar");
        }
        $this->revertComposerJsonChanges();
    }

    /**
     * @desc creates codecept.phar with Guzzle 5.3 and Symfony 2.8
     * @throws Exception
     */
    public function buildPhar5()
    {
        if (!file_exists('package/php54')) {
            mkdir('package/php54');
        }
        $this->installDependenciesForPhp5();
        $this->packPhar('package/codecept5.phar');
        $this->_copy('package/codecept5.phar', 'package/php54/codecept.phar');
        $code = $this->taskExec('php codecept.phar')->dir('package/php54')->run()->getExitCode();
        if ($code !== 0) {
            throw new Exception("There was problem compiling phar");
        }<commit_msg>Separate build:phar from build:phar7 (#5650)<commit_after><?php
require_once __DIR__.'/vendor/autoload.php';

use Symfony\Component\Finder\Finder;
use Robo\Task\Development\GenerateMarkdownDoc as Doc;

class RoboFile extends \Robo\Tasks
{
    const STABLE_BRANCH = '3.0';
    const REPO_BLOB_URL = 'https://github.com/Codeception/Codeception/blob';

    public function release()
    {
        $this->say("CODECEPTION RELEASE: ".\Codeception\Codecept::VERSION);
        $this->update();
        $this->buildDocs();
        $this->publishDocs();
        $this->buildPhar7();
        $this->buildPhar5();
        $this->publishPhar();
        $this->publishGit();
        $this->publishBase(null, \Codeception\Codecept::VERSION);
        $this->versionBump();
        $this->update(); //update dependencies after release, because buildPhar5 set them to old versions
    }

    public function versionBump($version = '')
    {
        if (!$version) {
            $versionParts = explode('.', \Codeception\Codecept::VERSION);
            $versionParts[count($versionParts)-1]++;
            $version = implode('.', $versionParts);
        }
        $this->say("Bumping version to $version");
        $this->taskReplaceInFile('src/Codeception/Codecept.php')
            ->from(\Codeception\Codecept::VERSION)
            ->to($version)
            ->run();
    }

    public function update()
    {
        $this->clean();
        $this->taskComposerUpdate()->dir('tests/data/claypit')->run();
        $this->taskComposerUpdate()->run();
    }

    public function changed($change)
    {
        $this->taskChangelog()
            ->version(\Codeception\Codecept::VERSION)
            ->change($change)
            ->run();
    }

    protected function server()
    {
        $this->taskServer(8000)
            ->background()
            ->dir('tests/data/app')
            ->run();
    }

    public function testPhpbrowser($args = '', $opt = ['test|t' => null])
    {
        $test = $opt['test'] ? ':'.$opt['test'] : '';
        $this->server();
        $this->taskCodecept('./codecept')
            ->args($args)
            ->test('tests/unit/Codeception/Module/PhpBrowserTest.php'.$test)
            ->run();
    }

    public function testRestBrowser($args = '', $opt = ['test|t' => null])
    {
        $test = $opt['test'] ? ':'.$opt['test'] : '';
        $this->taskServer(8010)
            ->background()
            ->dir('tests/data')
            ->run();

        $this->taskCodecept('./codecept')
            ->test('tests/unit/Codeception/Module/PhpBrowserRestTest.php'.$test)
            ->args($args)
            ->run();
    }

    public function testCoverage()
    {
        $this->server();
        $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
            ->arg('suite', 'coverage')
            ->run();
    }

    public function testWebdriver($args = '', $opt = ['test|t' => null])
    {
        $test = $opt['test'] ? ':'.$opt['test'] : '';

        $this->taskServer(8000)
            ->dir('tests/data/app')
            ->background()
            ->host('0.0.0.0')
            ->run();

        $this->taskCodecept('./codecept')
            ->suite('web')
            ->args($args)
            ->run();
    }

    public function testLaunchServer()
    {
        $this->taskServer(8010)
            ->background()
            ->dir('tests/data/rest')
            ->run();
        $this->taskServer(8000)
            ->dir('tests/data/app')
            ->run();
    }

    public function testCli()
    {
        $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
            ->arg('suite', 'cli')
            ->run();

        $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
            ->arg('suite', 'tests/unit/Codeception/Command')
            ->run();
    }

    private function installDependenciesForPhp5()
    {
        $this->taskReplaceInFile('composer.json')
            ->regex('/"platform": \{.*?\}/')
            ->to('"platform": {"php": "5.6.0"}')
            ->run();

        $this->taskComposerUpdate()->run();
    }

    private function installDependenciesForPhp70()
    {
        $this->taskReplaceInFile('composer.json')
            ->regex('/"platform": \{.*?\}/')
            ->to('"platform": {"php": "7.0.0"}')
            ->run();

        $this->taskComposerUpdate()->run();
    }

    private function revertComposerJsonChanges()
    {
        $this->taskReplaceInFile('composer.json')
            ->regex('/"platform": \{.*?\}/')
            ->to('"platform": {}')
            ->run();
    }


    /**
     * @desc creates codecept.phar
     * @throws Exception
     */
    public function buildPhar()
    {
        $this->packPhar('package/codecept.phar');
        $code = $this->taskExec('php codecept.phar')->dir('package')->run()->getExitCode();
        if ($code !== 0) {
            throw new Exception("There was problem compiling phar");
        }
    }


    /**
     * @desc creates codecept.phar for PHP 7.0
     * @throws Exception
     */
    public function buildPhar7()
    {
        $this->installDependenciesForPhp70();
        $this->buildPhar();
        $this->revertComposerJsonChanges();
    }

    /**
     * @desc creates codecept.phar for PHP 5.6 with Guzzle 5.3 and Symfony 2.8
     * @throws Exception
     */
    public function buildPhar5()
    {
        if (!file_exists('package/php54')) {
            mkdir('package/php54');
        }
        $this->installDependenciesForPhp5();
        $this->packPhar('package/codecept5.phar');
        $this->_copy('package/codecept5.phar', 'package/php54/codecept.phar');
        $code = $this->taskExec('php codecept.phar')->dir('package/php54')->run()->getExitCode();
        if ($code !== 0) {
            throw new Exception("There was problem compiling phar");
        }
{'fraction_non_alphanumeric': 0.1855786815292171, 'fraction_numerical': 0.011059827571192197, 'mean_word_length': 2.013382314353188, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 208, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7503471', 'n_tokens_mistral': 3502, 'n_tokens_neox': 3379, 'n_words': 525}