<commit_before><?php

namespace yTools;

/**
 * Test class for ProcessGuard.
 * Generated by PHPUnit on 2011-08-10 at 01:38:25.
 */
class ProcessGuardTest extends \PHPUnit_Framework_TestCase {

    /**
     * @var ProcessGuard
     */
    protected $object;
    protected $tmpDirectory = 'ProcessGuardTest';
    public $multiProcessesLockPrefix = 'MultiProcess';
    public $multiProcessesLockDir = 'MultiProcess';

    public function __construct($name = NULL, array $data = array(), $dataName = '') {
        parent::__construct($name, $data, $dataName);
        $this->tmpDirectory =
            \TestConfiguration::getInstance()->getTemporaryDirectory() .
            '/' . $this->tmpDirectory;
        $this->multiProcessesLockDir = $this->tmpDirectory . '/' . $this->multiProcessesLockDir;
    }

    public function setUp() {
        if (file_exists($this->tmpDirectory)) {
            \TestHelper::remove($this->tmpDirectory);
        }
        mkdir($this->tmpDirectory, 0770, true);
    }
    
    protected function getDefaultProcessGuard($lockDir = null, $lockPrefix = null, $processNumber = null) {
        $object = new ProcessGuard($lockDir ? : $this->tmpDirectory);
        $object->setLockPrefix($lockPrefix ? : 'ProcessGuardTest');
        $object->setProcMaxNumber($processNumber ? : 1);
        return $object;
    }

    public function testConstruct() {
        $this->assertInstanceOf(__NAMESPACE__ . '\\ProcessGuard', new ProcessGuard($this->tmpDirectory));
        try {
            new ProcessGuard($this->tmpDirectory . '/xyz');
            $this->fail('The expected exception has not been raised.');
        } catch (\InvalidArgumentException $expected) {}
        $testConstructorDir = $this->tmpDirectory . '/TestConstruct';
        mkdir($testConstructorDir, 0550);
        try {
            new ProcessGuard($testConstructorDir);
            $this->fail('The expected exception has not been raised.');
        } catch (\InvalidArgumentException $expected) {}
    }

    public function testLockPrefix() {
        $object = $this->getDefaultProcessGuard();
        $object->setLockPrefix('TestLockPrefixŚĆĄ');
        $this->assertEquals('TestLockPrefix_', $object->getLockPrefix());
        $object->setLockPrefix('TestLockPrefix123%%%456_');
        $this->assertEquals('TestLockPrefix123_456_', $object->getLockPrefix());
        $object->setLockPrefix('TestLockPrefix');
        $this->assertEquals('TestLockPrefix', $object->getLockPrefix());
        echo $lockFile = $this->tmpDirectory . '/TestLockPrefix-001-001.flock';
        $isExists = $object->run(
            function($lockFile) {
                return is_file($lockFile);
            }, array($lockFile)<commit_msg>Deleted echo function form test class.<commit_after><?php

namespace yTools;

/**
 * Test class for ProcessGuard.
 * Generated by PHPUnit on 2011-08-10 at 01:38:25.
 */
class ProcessGuardTest extends \PHPUnit_Framework_TestCase {

    /**
     * @var ProcessGuard
     */
    protected $object;
    protected $tmpDirectory = 'ProcessGuardTest';
    public $multiProcessesLockPrefix = 'MultiProcess';
    public $multiProcessesLockDir = 'MultiProcess';

    public function __construct($name = NULL, array $data = array(), $dataName = '') {
        parent::__construct($name, $data, $dataName);
        $this->tmpDirectory =
            \TestConfiguration::getInstance()->getTemporaryDirectory() .
            '/' . $this->tmpDirectory;
        $this->multiProcessesLockDir = $this->tmpDirectory . '/' . $this->multiProcessesLockDir;
    }

    public function setUp() {
        if (file_exists($this->tmpDirectory)) {
            \TestHelper::remove($this->tmpDirectory);
        }
        mkdir($this->tmpDirectory, 0770, true);
    }
    
    protected function getDefaultProcessGuard($lockDir = null, $lockPrefix = null, $processNumber = null) {
        $object = new ProcessGuard($lockDir ? : $this->tmpDirectory);
        $object->setLockPrefix($lockPrefix ? : 'ProcessGuardTest');
        $object->setProcMaxNumber($processNumber ? : 1);
        return $object;
    }

    public function testConstruct() {
        $this->assertInstanceOf(__NAMESPACE__ . '\\ProcessGuard', new ProcessGuard($this->tmpDirectory));
        try {
            new ProcessGuard($this->tmpDirectory . '/xyz');
            $this->fail('The expected exception has not been raised.');
        } catch (\InvalidArgumentException $expected) {}
        $testConstructorDir = $this->tmpDirectory . '/TestConstruct';
        mkdir($testConstructorDir, 0550);
        try {
            new ProcessGuard($testConstructorDir);
            $this->fail('The expected exception has not been raised.');
        } catch (\InvalidArgumentException $expected) {}
    }

    public function testLockPrefix() {
        $object = $this->getDefaultProcessGuard();
        $object->setLockPrefix('TestLockPrefixŚĆĄ');
        $this->assertEquals('TestLockPrefix_', $object->getLockPrefix());
        $object->setLockPrefix('TestLockPrefix123%%%456_');
        $this->assertEquals('TestLockPrefix123_456_', $object->getLockPrefix());
        $object->setLockPrefix('TestLockPrefix');
        $this->assertEquals('TestLockPrefix', $object->getLockPrefix());
        $lockFile = $this->tmpDirectory . '/TestLockPrefix-001-001.flock';
        $isExists = $object->run(
            function($lockFile) {
                return is_file($lockFile);
            }, array($lockFile)
{'fraction_non_alphanumeric': 0.13973558575100992, 'fraction_numerical': 0.015056922511935366, 'mean_word_length': 3.0288461538461537, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '4933801', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1438, 'n_words': 279}