Beispiel #1
0
 /**
  * @param ThreadableInterface $Threadable
  * @dataProvider threadableProvider
  */
 public function testGetScreenlistMatches(ThreadableInterface $Threadable)
 {
     $this->setClass(new ProcessControl());
     ProcessControl::killAllThreads();
     $this->myTestForEmptyScreenlist();
     $Threadable->spawnThread();
     $RawScreenList = $this->getPrivateMethod('getRawScreenlist');
     $this->assertInternalType('string', $RawScreenList);
     $this->assertStringStartsWith('There is a screen on', $RawScreenList);
     $this->assertStringEndsWith("\n", $RawScreenList);
     $ScreenlistMatches = $this->getPrivateMethod('getScreenlistMatches');
     $this->assertRegexMatchesFormat($ScreenlistMatches, 1);
     $RegexMatch = $ScreenlistMatches[0][0];
     $ProcessId = $ScreenlistMatches[1][0];
     $ThreadKey = $ScreenlistMatches[2][0];
     $this->assertContains($Threadable->getThreadKey(), $RegexMatch);
     $this->assertInternalType('string', $ProcessId);
     $this->assertGreaterThan(1, $ProcessId);
     $this->assertEquals($Threadable->getThreadKey(), $ThreadKey);
     $this->assertTrue(CommandParse::isThreadkeyValid($ThreadKey));
     $Threadable->killThread();
     $this->myTestForEmptyScreenlist();
 }
Beispiel #2
0
 /**
  * @param $Value
  * @dataProvider invalidThreadKeyProvider
  * @expectedException Axvf\Threadable\Exceptions\InvalidThreadKeyException
  */
 public function testThreadKeyInvalid($Value)
 {
     $this->assertFalse(CommandParse::isThreadkeyValid($Value));
     CommandParse::validateThreadkey($Value);
 }
Beispiel #3
0
 /**
  * @param string $ThreadKey
  * @throws InvalidThreadKeyException
  * @return void
  */
 public final function setThreadKey($ThreadKey)
 {
     CommandParse::validateThreadkey($ThreadKey);
     $this->ThreadKey = $ThreadKey;
 }
Beispiel #4
0
<?php

namespace Axvf\Threadable;

use Axvf\Redis\Redis;
use Axvf\Threadable\Exceptions\NoSuchThreadableObjectException;
$Autoloader = dirname(__FILE__) . '/../../../autoload.php';
require_once $Autoloader;
/**
 * @var ThreadableInterface $ThreadableObject
 */
$ThreadableObject = Redis::client()->get(CommandParse::getCurrentThreadKey());
/**
 * Try a second time to get the object from redis if
 *  the object isn't an instance of ThreadableInterface
 */
if (!$ThreadableObject instanceof ThreadableInterface) {
    sleep(1);
    $ThreadableObject = Redis::client()->get(CommandParse::getCurrentThreadKey());
    if (!$ThreadableObject instanceof ThreadableInterface) {
        throw new NoSuchThreadableObjectException($ThreadableObject);
    }
}
$ThreadableObject->start();