How to use testClass method of hash class

Best Atoum code snippet using hash.testClass

MethodInvocationTest.class.php

Source:MethodInvocationTest.class.php Github

copy

Full Screen

1<?php2/* This class is part of the XP framework3 *4 * $Id$5 */6 7 uses(8 'unittest.TestCase', 9 'util.Date',10 'util.DateUtil',11 'TestClass'12 );13 /**14 * Tests method invocations15 *16 * @purpose Unit Test17 */18 class MethodInvocationTest extends TestCase {19 var20 $fixture= NULL;21 /**22 * Setup method23 *24 * @access public25 */26 function setUp() {27 $this->fixture= &XPClass::forName('TestClass');28 }29 30 /**31 * Verify type / argument match32 *33 * @access protected34 * @param string type35 * @param &mixed arg36 * @return bool37 */38 function verifyType($type, &$arg) {39 40 // Handle "mixed"41 if (0 == strncmp('mixed', $type, 5)) return TRUE;42 43 // Handle types arrays44 if ('[]' == substr($type, -2)) {45 $componentType= substr($type, 0, -2);46 for ($i= 0, $s= sizeof($arg); $i < $s; $i++) {47 if (!$this->verifyType($componentType, $arg[$i])) return FALSE;48 }49 return TRUE;50 }51 52 // Handle generic arrays53 if (1 == sscanf($type, 'array<%[^>]>', $componentsDeclaration)) {54 $componentTypes= explode(', ', str_replace('&', '', $componentsDeclaration));55 foreach (array_keys($arg) as $k) {56 if (!$this->verifyType($componentTypes[0], $k)) return FALSE;57 if (!$this->verifyType($componentTypes[1], $arg[$k])) return FALSE;58 }59 return TRUE;60 }61 62 // Handle other types63 switch ($type) {64 case 'int': return is_int($arg);65 case 'bool': return is_bool($arg);66 case 'float': return is_float($arg);67 case 'string': return is_string($arg);68 case 'array': return is_array($args);69 default: return NULL === $arg || is($type, $arg);70 }71 }72 73 /**74 * Helper method75 *76 * @access protected77 * @param string name78 * @param mixed[] args79 */80 function invoke($name, $args= array()) {81 $method= &$this->fixture->getMethod($name);82 $arguments= $method->getArguments();83 84 // Check how many arguments are required85 $required= sizeof($arguments);86 $numargs= sizeof($args);87 $success= $required == $numargs;88 foreach ($arguments as $pos => $arg) {89 if ('*' == substr($arg->getType(), -1)) {90 $success= $numargs >= $pos;91 break;92 }93 }94 95 // Check number of arguments96 if (!$success) {97 return throw(new IllegalArgumentException(98 'Incorrect number of arguments to '.$name.'(): '.$numargs99 ));100 }101 102 // Check types103 foreach ($arguments as $pos => $arg) {104 if ($this->verifyType($arg->getType(), $args[$pos])) continue;105 return throw(new IllegalArgumentException(106 'Argument #'.$pos.': '.xp::typeOf($args[$pos]).' does not match '.$arg->getType()107 ));108 }109 $method->invoke($this->fixture->newInstance(), $args);110 }111 /**112 * Tests invoking a method without arguments113 *114 * @access public115 */116 #[@test]117 function noArgsMethod() {118 $this->invoke('toString');119 }120 /**121 * Tests invoking a method without arguments122 *123 * @access public124 */125 #[@test, @expect('lang.IllegalArgumentException')]126 function noArgsMethodWithArgument() {127 $this->invoke('toString', array('arg0'));128 }129 /**130 * Tests invoking TestClass::setDate() with a Date instance131 *132 * @access public133 */134 #[@test]135 function setDateWithDateInstance() {136 $this->invoke('setDate', array(new Date()));137 }138 /**139 * Tests invoking TestClass::setDate() with NULL140 *141 * @access public142 */143 #[@test]144 function setDateWithNull() {145 $this->invoke('setDate', array(NULL));146 }147 /**148 * Tests invoking TestClass::setDate() with an Object instance149 *150 * @access public151 */152 #[@test, @expect('lang.IllegalArgumentException')]153 function setDateWithObjectInstance() {154 $this->invoke('setDate', array(new Object()));155 }156 /**157 * Tests invoking TestClass::setDate() with a primitive158 *159 * @access public160 */161 #[@test, @expect('lang.IllegalArgumentException')]162 function setDateWithPrimitive() {163 $this->invoke('setDate', array('2007-07-07'));164 }165 /**166 * Tests invoking TestClass::add() with two ints167 *168 * @access public169 */170 #[@test]171 function addWithInts() {172 $this->invoke('add', array(1, 2));173 }174 /**175 * Tests invoking TestClass::add() with two floats176 *177 * @access public178 */179 #[@test, @expect('lang.IllegalArgumentException')]180 function addWithFloats() {181 $this->invoke('add', array(1.0, 2.0));182 }183 /**184 * Tests invoking TestClass::add() with two objects185 *186 * @access public187 */188 #[@test, @expect('lang.IllegalArgumentException')]189 function addWithObjects() {190 $this->invoke('add', array(new Date(), new Object()));191 }192 /**193 * Tests invoking TestClass::add() with NULLs194 *195 * @access public196 */197 #[@test, @expect('lang.IllegalArgumentException')]198 function addWithNulls() {199 $this->invoke('add', array(NULL, NULL));200 }201 /**202 * Tests invoking TestClass::add() with only argument203 *204 * @access public205 */206 #[@test, @expect('lang.IllegalArgumentException')]207 function addWithOnlyOneArgument() {208 $this->invoke('add', array(1));209 }210 /**211 * Tests invoking TestClass::add() with too many arguments212 *213 * @access public214 */215 #[@test, @expect('lang.IllegalArgumentException')]216 function addWithTooManyArguments() {217 $this->invoke('add', array(1, 2, 3));218 }219 220 /**221 * Tests invoking TestClass::setNames() with an array of strings222 *223 * @access public224 */225 #[@test]226 function setNamesWithStringArray() {227 $this->invoke('setNames', array(array('Timm', 'Alex')));228 }229 /**230 * Tests invoking TestClass::setNames() with an empty array231 *232 * @access public233 */234 #[@test]235 function setNamesWithEmptyArray() {236 $this->invoke('setNames', array(array()));237 }238 /**239 * Tests invoking TestClass::setNames() with a mixed array240 *241 * @access public242 */243 #[@test, @expect('lang.IllegalArgumentException')]244 function setNamesWithMixedArray() {245 $this->invoke('setNames', array(array('Timm', FALSE)));246 }247 /**248 * Tests invoking TestClass::setNames() with an associative array249 *250 * @access public251 */252 #[@test, @expect('lang.IllegalArgumentException')]253 function setNamesWithAssociativeArray() {254 $this->invoke('setNames', array(array('name' => 'Timm', 'lastname' => 'Friebe')));255 }256 /**257 * Tests invoking TestClass::filter() with an hash258 *259 * @access public260 */261 #[@test]262 function filterWithEmptyHash() {263 $this->invoke('filter', array(264 array(),265 'isBefore',266 Date::now()267 ));268 }269 /**270 * Tests invoking TestClass::filter() with an hash271 *272 * @access public273 */274 #[@test]275 function filterWithStringDateHash() {276 $this->invoke('filter', array(277 array(278 'now' => Date::now(),279 'tomorrow' => DateUtil::addDays(Date::now(), 1),280 'yesterday' => DateUtil::addDays(Date::now(), -1)281 ),282 'isBefore',283 Date::now()284 ));285 }286 /**287 * Tests invoking TestClass::filter() with an hash288 *289 * @access public290 */291 #[@test, @expect('lang.IllegalArgumentException')]292 function filterWithMixedHash() {293 $this->invoke('filter', array(294 array(295 'now' => Date::now(),296 'tomorrow' => FALSE297 ),298 'isBefore',299 Date::now()300 ));301 }302 303 /**304 * Tests invoking TestClass::format() with only one argument305 *306 * @access public307 */308 #[@test]309 function formatWithOneArgument() {310 $this->invoke('format', array('Needs no formatting'));311 }312 /**313 * Tests invoking TestClass::format() with two arguments314 *315 * @access public316 */317 #[@test]318 function formatWithTwoArguments() {319 $this->invoke('format', array('Hello %s', 'World'));320 }321 /**322 * Tests invoking TestClass::format() with only one argument323 *324 * @access public325 */326 #[@test]327 function formatWithLotsArguments() {328 $this->invoke('format', array('%s: %s %d %s', 'Hello', 'Timm', 42, 'is the answer'));329 }330 /**331 * Tests invoking TestClass::format() with no arguments332 *333 * @access public334 */335 #[@test, @expect('lang.IllegalArgumentException')]336 function formatWithNoArguments() {337 $this->invoke('format');338 }339 }340?>...

Full Screen

Full Screen

Result.php

Source:Result.php Github

copy

Full Screen

...40 {41 return $this->data;42 }43 /**44 * @param $testClass45 * @param $hash46 * @param $line47 * @param null $message48 */49 public function addError($testClass, $hash, $line, $message = null)50 {51 $this->data['errors'][$testClass]['message'] = $message;52 if (!empty($this->data['errors'][$testClass]['files'][$hash])) {53 $this->data['errors'][$testClass]['files'][$hash]54 = $this->data['errors'][$testClass]['files'][$hash] . ',' . $line;55 return;56 }57 $this->data['errors'][$testClass]['files'][$hash] = $line;58 }59 /**60 * @return mixed61 */62 public function getErrors()63 {64 return $this->data['errors'];65 }66 /**67 * @return bool68 */69 public function hasError() : bool70 {71 if (!empty($this->data['errors'])) {...

Full Screen

Full Screen

testContainer.php

Source:testContainer.php Github

copy

Full Screen

1<?php2require __DIR__ . '/../vendor/autoload.php';3$app = new Illuminate\Foundation\Application(4 dirname(__DIR__)5);6class TestClass7{8 public function fun1($instance, $app)9 {10 var_dump('fun1 ' . get_class($instance) . ' ' . get_class($app));11 }12 public function fun2()13 {14 var_dump( sha1(spl_object_hash($this)) . " fun2");15 }16 public static function static1()17 {18 var_dump("static1");19 }20 public function __invoke(...$arg)21 {22 var_dump( sha1(spl_object_hash($this)) . " __invoke");23 }24}25$app->bindMethod(["TestClass", "fun1"], function ($instance, $app) {26 var_dump('fun1 ' . get_class($instance) . ' ' . get_class($app));27});28$instance = new TestClass();29$app->callMethodBinding('TestClass@fun1', $instance);30$app->call([$instance, "fun1"]);31function simpleFunction()32{33 var_dump("simpleFunction");34}35$app->call('simpleFunction');36$app->call("TestClass@fun1");37$app->call("TestClass@fun2");38$app->call($instance);39$app->call([$instance, "fun2"]);40$app->call([$instance, "static1"]);41$app->call(["TestClass", "static1"]);42$app->call("TestClass::static1");...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger testClass code on LambdaTest Cloud Grid

Execute automation tests with testClass on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful