/** * * @param Client $client * @param string $type */ public function __construct(Client $client, $type) { parent::__construct($client); $this->type = $type; $this->val = array(); $this->counter = 0; }
public static function on($times) { \Arg::_($times, 'Times')->is_int(); $instance = new static(); $instance->times = $times; return $instance; }
public static function instance($class) { \Arg::_($class, 'Class name')->is_string()->assert(class_exists($class), 'Class to getMock must be defined'); $instance = new self(); $instance->class = $class; return $instance; }
public static function instance($class) { \Arg::_($class, 'Class name')->is_string()->assert(class_exists($class) || interface_exists($class) || trait_exists($class), 'Class must be a defined one'); $instance = new self(); $instance->requestClassName = $class; $instance->isStaticMethod = false; $instance->isInstanceMethod = true; $instance->isFunction = false; $instance->isMethod = true; $instance->methodName = ''; return $instance; }
public static function make($times) { \Arg::_($times, 'Times')->is_int()->_or()->is_string(); if (is_numeric($times)) { $times = (int) $times; return EqualMatchingStrategy::on($times); } $matches = array(); if (!preg_match("/(>|>=|<|<=|==|!=)*(\\d)+/uU", $times, $matches)) { throw new \InvalidArgumentException('If times is a string it must follow the pattern [==|!=|<=|<|>=|>]*\\d+'); } $prefix = $matches[1]; $times = (int) $matches[2]; switch ($prefix) { case '>': $matchingStrategy = GreaterThanMatchingStrategy::on($times); break; case '>=': $matchingStrategy = AtLeastMatchingStrategy::on($times); break; case '==': $matchingStrategy = EqualMatchingStrategy::on($times); break; case '<': $matchingStrategy = LessThanMatchingStrategy::on($times); break; case '<=': $matchingStrategy = AtMostMatchingStrategy::on($times); break; case '!=': $matchingStrategy = NotEqualMatchingStrategy::on($times); break; default: $matchingStrategy = EqualMatchingStrategy::on($times); break; } return $matchingStrategy; }
public static function fromName($functionName) { if (!self::$systemFunctions) { self::$systemFunctions = get_defined_functions()['internal']; } $condition = !in_array($functionName, self::$systemFunctions); \Arg::_($functionName)->assert($condition, 'Function must not be an internal one.'); $instance = new self(); $instance->isEvalCreated = false; $instance->functionName = $functionName; $isMethod = preg_match("/^[\\w\\d_\\\\]+::[\\w\\d_]+\$/", $functionName); if (!$isMethod && !function_exists($functionName)) { $namespace = self::hasNamespace($functionName) ? 'namespace ' . self::getNamespaceFrom($functionName) . ";" : ''; $functionName = self::hasNamespace($functionName) ? self::getFunctionNameFrom($functionName) : $functionName; $code = sprintf('%sfunction %s(){return null;}', $namespace, $functionName); $ok = eval($code); if ($ok === false) { throw new \Exception("Could not eval code {$code} for function {$functionName}"); } $instance->isEvalCreated = true; } return $instance; }
public function doesMatch_should_work_with_generic_AnyMatcher() { $this->sut->setArguments(array(Arg::any())); $this->assertTrue($this->sut->doesMatchArgs(array(NULL))); $this->assertTrue($this->sut->doesMatchArgs(array('test'))); $this->assertTrue($this->sut->doesMatchArgs(array(42))); $this->assertTrue($this->sut->doesMatchArgs(array(new Object()))); }
/** * 构造方法 * * @param int $total 总数 * @param int $page 第几页 * @param int $count 每页多少项 * @param int $last_page 上一次请页的页面 * @param int $next_since_id 当前请求最后一个ID * @param int $prev_since_id 当前请求第一个ID */ public function __construct($total, $count = 20, $page = false, $last_page = false, $next_since_id = false, $prev_since_id = false) { $this->total = $total; $this->page = $page; $this->last_page = $last_page; $this->count = $count; $this->next_since_id = $next_since_id; $this->prev_since_id = $prev_since_id; if ($this->page === false) { $this->page = Arg::get('p', FILTER_VALIDATE_INT, ['min_range' => 1]) ?: 1; } if ($this->next_since_id === false) { $this->next_since_id = Arg::get('next_since_id', FILTER_VALIDATE_INT) ?: 0; } if ($this->prev_since_id === false) { $this->next_since_id = Arg::get('prev_since_id', FILTER_VALIDATE_INT) ?: 0; } if (!$this->last_page === false) { $this->last_page = Arg::get('last_page', FILTER_VALIDATE_INT, ['min_range' => 1]) ?: 0; } $this->page_total = ceil($this->total / $this->count); }
public static function reset_exception() { self::$exception = null; }
/** * @test * it should fail if array has not all the values */ public function it_should_fail_if_array_has_not_all_the_values() { $this->setExpectedException('InvalidArgumentException'); $array = ['foo' => 23, 'format' => 11]; Arg::_($array)->has_value(13, 23); }
public function mock_repository_should_work_with() { $mockery = new MockRepository(); $interface = $mockery->createMock('net.xp_framework.unittest.tests.mock.IComplexInterface'); $interface->fooWithTypeHint(Arg::anyOfType('net.xp_framework.unittest.tests.mock.IEmptyInterface')); }
/** * * @param Arg $arg * @throws JavaException */ public function apply($arg) { $name = $arg->p; $object = $arg->v; $ob = $object == null ? $name : array(&$object, $name); $isAsync = $this->isAsync; $methodCache = $this->methodCache; $currentArgumentsFormat = $this->currentArgumentsFormat; try { $res = $arg->getResult(true); if ($object == null && !function_exists($name) || !($object == null) && !method_exists($object, $name)) { throw new Exception\JavaException("java.lang.NoSuchMethodError", "{$name}"); } $res = call_user_func_array($ob, $res); if (is_object($res) && !$res instanceof JavaType) { trigger_error("object returned from {$name}() is not a Java object", E_USER_WARNING); $this->protocol->invokeBegin(0, "makeClosure"); $this->protocol->writeULong($this->globalRef->add($res)); $this->protocol->invokeEnd(); $res = $this->getResult(); } $this->protocol->resultBegin(); $this->writeArg($res); $this->protocol->resultEnd(); } catch (Exception\JavaException $e) { $trace = $e->getTraceAsString(); $this->protocol->resultBegin(); $this->protocol->writeException($e->__java, $trace); $this->protocol->resultEnd(); } catch (\Exception $ex) { error_log($ex->__toString()); trigger_error("Unchecked exception detected in callback", E_USER_ERROR); die(1); } $this->isAsync = $isAsync; $this->methodCache = $methodCache; $this->currentArgumentsFormat = $currentArgumentsFormat; }
/** * @param string $functionName * * @return LoggerInterface */ public static function make($functionName) { \Arg::_($functionName, 'Function name')->is_string(); $invocation = new SpyCallLogger(); return $invocation; }
public static function normalizePathFrag($path) { \Arg::_($path, 'Path')->is_string(); return trim(trim($path), '/'); }
<?php require_once "../config/conf.php"; require_once '../model/Model.php'; require_once '../model/Prop.php'; $propClass = new Prop(); require_once '../model/Arg.php'; $argClass = new Arg(); require_once '../model/Debat.php'; $debatClass = new Debat(); require_once '../model/Log.php'; $logClass = new Log(); require_once '../model/User_histo.php'; $user_histoClass = new User_histo(); session_start(); // On démarre la session AVANT toute chose if (isset($_SESSION["ip"])) { $user_ip = $_SESSION["ip"]; } if (isset($_SESSION["user_mail"])) { $user_mail = $_SESSION["user_mail"]; } if (isset($_POST['vote']) and isset($_POST['vote_id']) and isset($_POST['vote_type'])) { $vote = $_POST['vote']; $vote_id = $_POST['vote_id']; $vote_type = $_POST['vote_type']; $messageUpdate = "Erreur technique lors de la mise à jour de la donnée."; if ($vote_type == "arg") { // $logClass->setNewLog($vote." ".$vote_id." ".$vote_type,$user_ip); $args = $argClass->getArgById($vote_id); $arg_id = $args[0]->arg_id;
public function setOriginalClassName($className) { \Arg::_($className, "Original class name")->is_string()->assert(class_exists($className) || interface_exists($className) || trait_exists($className), 'Original class, interface or trait must be defined'); $this->originalClassName = $className; }
static function __static() { self::$any = new AnyMatcher(); }
public function typeof_date_should_not_match_primitives() { $this->assertFalse(Arg::anyOfType('util.Date')->matches(1)); }
/** * Sets a global value restoring the state after the test ran. * * @param string $globalHandle The key the value will be associated to in the $GLOBALS array. * @param mixed $replacement The value that will be set in the $GLOBALS array. * * @return mixed The object that's been set in the $GLOBALS array. */ public static function setGlobal($globalHandle, $replacement = null) { \Arg::_($globalHandle, 'Global var key')->is_string(); self::backupGlobal($globalHandle); $GLOBALS[$globalHandle] = $replacement; return $replacement; }
public function arg_any_accepts_all_arguments() { $object = $this->fixture->createMock('net.xp_framework.unittest.tests.mock.IComplexInterface'); $expect = 'c1'; $object->bar(Arg::any(), Arg::any())->returns($expect)->repeatAny(); $this->fixture->replayAll(); $this->assertEquals($expect, $object->bar(NULL, NULL)); $this->assertEquals($expect, $object->bar(34, 'foo')); $this->assertEquals($expect, $object->bar(23.0, new Object())); }
public static function on($mockRequest) { \Arg::_($mockRequest, 'Function or method name')->is_string(); $type = self::getType($mockRequest); return self::getInstanceForTypeAndRequest($type, $mockRequest); }