How to use Pickle class

Best Cucumber Common Library code snippet using Pickle

PythonPickle.php

Source:PythonPickle.php Github

copy

Full Screen

...17 * @see Phython3.1/Lib/pickle.py18 * @see Phython3.1/Modules/_pickle.c19 * @link http://pickle-js.googlecode.com20 */21class PythonPickle extends AbstractAdapter22{23 /**24 * Pickle opcodes. See pickletools.py for extensive docs.25 * @link http://hg.python.org/cpython/file/2.7/Lib/pickletools.py26 * The listing here is in kind-of alphabetical order of 1-character pickle code.27 * pickletools groups them by purpose.28 */29 const OP_MARK = '('; // push special markobject on stack30 const OP_STOP = '.'; // every pickle ends with STOP31 const OP_POP = '0'; // discard topmost stack item32 const OP_POP_MARK = '1'; // discard stack top through topmost markobject33 const OP_DUP = '2'; // duplicate top stack item34 const OP_FLOAT = 'F'; // push float object; decimal string argument35 const OP_INT = 'I'; // push integer or bool; decimal string argument36 const OP_BININT = 'J'; // push four-byte signed int37 const OP_BININT1 = 'K'; // push 1-byte unsigned int38 const OP_LONG = 'L'; // push long; decimal string argument39 const OP_BININT2 = 'M'; // push 2-byte unsigned int40 const OP_NONE = 'N'; // push None41 const OP_PERSID = 'P'; // push persistent object; id is taken from string arg42 const OP_BINPERSID = 'Q'; // " " " ; " " " " stack43 const OP_REDUCE = 'R'; // apply callable to argtuple, both on stack44 const OP_STRING = 'S'; // push string; NL-terminated string argument45 const OP_BINSTRING = 'T'; // push string; counted binary string argument46 const OP_SHORT_BINSTRING = 'U'; // " " ; " " " " < 256 bytes47 const OP_UNICODE = 'V'; // push Unicode string; raw-unicode-escaped'd argument48 const OP_BINUNICODE = 'X'; // " " " ; counted UTF-8 string argument49 const OP_APPEND = 'a'; // append stack top to list below it50 const OP_BUILD = 'b'; // call __setstate__ or __dict__.update()51 const OP_GLOBAL = 'c'; // push self.find_class(modname, name); 2 string args52 const OP_DICT = 'd'; // build a dict from stack items53 const OP_EMPTY_DICT = '}'; // push empty dict54 const OP_APPENDS = 'e'; // extend list on stack by topmost stack slice55 const OP_GET = 'g'; // push item from memo on stack; index is string arg56 const OP_BINGET = 'h'; // " " " " " " ; " " 1-byte arg57 const OP_INST = 'i'; // build & push class instance58 const OP_LONG_BINGET = 'j'; // push item from memo on stack; index is 4-byte arg59 const OP_LIST = 'l'; // build list from topmost stack items60 const OP_EMPTY_LIST = ']'; // push empty list61 const OP_OBJ = 'o'; // build & push class instance62 const OP_PUT = 'p'; // store stack top in memo; index is string arg63 const OP_BINPUT = 'q'; // " " " " " ; " " 1-byte arg64 const OP_LONG_BINPUT = 'r'; // " " " " " ; " " 4-byte arg65 const OP_SETITEM = 's'; // add key+value pair to dict66 const OP_TUPLE = 't'; // build tuple from topmost stack items67 const OP_EMPTY_TUPLE = ')'; // push empty tuple68 const OP_SETITEMS = 'u'; // modify dict by adding topmost key+value pairs69 const OP_BINFLOAT = 'G'; // push float; arg is 8-byte float encoding70 /* Protocol 2 */71 const OP_PROTO = "\x80"; // identify pickle protocol72 const OP_NEWOBJ = "\x81"; // build object by applying cls.__new__ to argtuple73 const OP_EXT1 = "\x82"; // push object from extension registry; 1-byte index74 const OP_EXT2 = "\x83"; // ditto, but 2-byte index75 const OP_EXT4 = "\x84"; // ditto, but 4-byte index76 const OP_TUPLE1 = "\x85"; // build 1-tuple from stack top77 const OP_TUPLE2 = "\x86"; // build 2-tuple from two topmost stack items78 const OP_TUPLE3 = "\x87"; // build 3-tuple from three topmost stack items79 const OP_NEWTRUE = "\x88"; // push True80 const OP_NEWFALSE = "\x89"; // push False81 const OP_LONG1 = "\x8a"; // push long from < 256 bytes82 const OP_LONG4 = "\x8b"; // push really big long83 /* Protocol 3 (Python 3.x) */84 const OP_BINBYTES = 'B'; // push bytes; counted binary string argument85 const OP_SHORT_BINBYTES = 'C'; // " " ; " " " " < 256 bytes86 /**87 * Whether or not the system is little-endian88 *89 * @var bool90 */91 protected static $isLittleEndian = null;92 /**93 * @var array Strings representing quotes94 */95 protected static $quoteString = [96 '\\' => '\\\\',97 "\x00" => '\\x00', "\x01" => '\\x01', "\x02" => '\\x02', "\x03" => '\\x03',98 "\x04" => '\\x04', "\x05" => '\\x05', "\x06" => '\\x06', "\x07" => '\\x07',99 "\x08" => '\\x08', "\x09" => '\\t', "\x0a" => '\\n', "\x0b" => '\\x0b',100 "\x0c" => '\\x0c', "\x0d" => '\\r', "\x0e" => '\\x0e', "\x0f" => '\\x0f',101 "\x10" => '\\x10', "\x11" => '\\x11', "\x12" => '\\x12', "\x13" => '\\x13',102 "\x14" => '\\x14', "\x15" => '\\x15', "\x16" => '\\x16', "\x17" => '\\x17',103 "\x18" => '\\x18', "\x19" => '\\x19', "\x1a" => '\\x1a', "\x1b" => '\\x1b',104 "\x1c" => '\\x1c', "\x1d" => '\\x1d', "\x1e" => '\\x1e', "\x1f" => '\\x1f',105 "\xff" => '\\xff'106 ];107 // process vars108 protected $protocol = null;109 protected $memo = [];110 protected $pickle = '';111 protected $pickleLen = 0;112 protected $pos = 0;113 protected $stack = [];114 protected $marker = null;115 /**116 * @var BigInteger\Adapter\AdapterInterface117 */118 protected $bigIntegerAdapter = null;119 /**120 * @var PythonPickleOptions121 */122 protected $options = null;123 /**124 * Constructor.125 *126 * @param array|Traversable|PythonPickleOptions $options Optional127 */128 public function __construct($options = null)129 {130 // init131 if (static::$isLittleEndian === null) {132 static::$isLittleEndian = (pack('l', 1) === "\x01\x00\x00\x00");133 }134 $this->marker = new stdClass();135 parent::__construct($options);136 }137 /**138 * Set options139 *140 * @param array|Traversable|PythonPickleOptions $options141 * @return PythonPickle142 */143 public function setOptions($options)144 {145 if (! $options instanceof PythonPickleOptions) {146 $options = new PythonPickleOptions($options);147 }148 $this->options = $options;149 return $this;150 }151 /**152 * Get options153 *154 * @return PythonPickleOptions155 */156 public function getOptions()157 {158 if ($this->options === null) {159 $this->options = new PythonPickleOptions();160 }161 return $this->options;162 }163 /* serialize */164 /**165 * Serialize PHP to PythonPickle format166 *167 * @param mixed $value168 * @return string169 */170 public function serialize($value)171 {172 $this->clearProcessVars();173 $this->protocol = $this->getOptions()->getProtocol();174 // write175 if ($this->protocol >= 2) {176 $this->writeProto($this->protocol);177 }178 $this->write($value);179 $this->writeStop();180 $pickle = $this->pickle;181 $this->clearProcessVars();182 return $pickle;183 }184 /**185 * Write a value186 *187 * @param mixed $value188 * @throws Exception\RuntimeException on invalid or unrecognized value type189 */190 protected function write($value)191 {192 if ($value === null) {193 $this->writeNull();194 } elseif (is_bool($value)) {195 $this->writeBool($value);196 } elseif (is_int($value)) {197 $this->writeInt($value);198 } elseif (is_float($value)) {199 $this->writeFloat($value);200 } elseif (is_string($value)) {201 // TODO: write unicode / binary202 $this->writeString($value);203 } elseif (is_array($value)) {204 if (ArrayUtils::isList($value)) {205 $this->writeArrayList($value);206 } else {207 $this->writeArrayDict($value);208 }209 } elseif (is_object($value)) {210 $this->writeObject($value);211 } else {212 throw new Exception\RuntimeException(sprintf(213 'PHP-Type "%s" can not be serialized by %s',214 gettype($value),215 get_class($this)216 ));217 }218 }219 /**220 * Write pickle protocol221 *222 * @param int $protocol223 */224 protected function writeProto($protocol)225 {226 $this->pickle .= self::OP_PROTO . $protocol;227 }228 /**229 * Write a get230 *231 * @param int $id Id of memo232 */233 protected function writeGet($id)234 {235 if ($this->protocol == 0) {236 $this->pickle .= self::OP_GET . $id . "\r\n";237 } elseif ($id <= 0xFF) {238 // BINGET + chr(i)239 $this->pickle .= self::OP_BINGET . chr($id);240 } else {241 // LONG_BINGET + pack("<i", i)242 $bin = pack('l', $id);243 if (static::$isLittleEndian === false) {244 $bin = strrev($bin);245 }246 $this->pickle .= self::OP_LONG_BINGET . $bin;247 }248 }249 /**250 * Write a put251 *252 * @param int $id Id of memo253 */254 protected function writePut($id)255 {256 if ($this->protocol == 0) {257 $this->pickle .= self::OP_PUT . $id . "\r\n";258 } elseif ($id <= 0xff) {259 // BINPUT + chr(i)260 $this->pickle .= self::OP_BINPUT . chr($id);261 } else {262 // LONG_BINPUT + pack("<i", i)263 $bin = pack('l', $id);264 if (static::$isLittleEndian === false) {265 $bin = strrev($bin);266 }267 $this->pickle .= self::OP_LONG_BINPUT . $bin;268 }269 }270 /**271 * Write a null as None272 *273 */274 protected function writeNull()275 {276 $this->pickle .= self::OP_NONE;277 }278 /**279 * Write boolean value280 *281 * @param bool $value282 */283 protected function writeBool($value)284 {285 if ($this->protocol >= 2) {286 $this->pickle .= ($value === true) ? self::OP_NEWTRUE : self::OP_NEWFALSE;287 } else {288 $this->pickle .= self::OP_INT . (($value === true) ? '01' : '00') . "\r\n";289 }290 }291 /**292 * Write an integer value293 *294 * @param int $value295 */296 protected function writeInt($value)297 {298 if ($this->protocol == 0) {299 $this->pickle .= self::OP_INT . $value . "\r\n";300 return;301 }302 if ($value >= 0) {303 if ($value <= 0xFF) {304 // self.write(BININT1 + chr(obj))305 $this->pickle .= self::OP_BININT1 . chr($value);306 } elseif ($value <= 0xFFFF) {307 // self.write("%c%c%c" % (BININT2, obj&0xff, obj>>8))308 $this->pickle .= self::OP_BININT2 . pack('v', $value);309 }310 return;311 }312 // Next check for 4-byte signed ints:313 $highBits = $value >> 31; // note that Python shift sign-extends314 if ($highBits == 0 || $highBits == -1) {315 // All high bits are copies of bit 2**31, so the value316 // fits in a 4-byte signed int.317 // self.write(BININT + pack("<i", obj))318 $bin = pack('l', $value);319 if (static::$isLittleEndian === false) {320 $bin = strrev($bin);321 }322 $this->pickle .= self::OP_BININT . $bin;323 return;324 }325 }326 /**327 * Write a float value328 *329 * @param float $value330 */331 protected function writeFloat($value)332 {333 if ($this->protocol == 0) {334 $this->pickle .= self::OP_FLOAT . $value . "\r\n";335 } else {336 // self.write(BINFLOAT + pack('>d', obj))337 $bin = pack('d', $value);338 if (static::$isLittleEndian === true) {339 $bin = strrev($bin);340 }341 $this->pickle .= self::OP_BINFLOAT . $bin;342 }343 }344 /**345 * Write a string value346 *347 * @param string $value348 */349 protected function writeString($value)350 {351 if (($id = $this->searchMemo($value)) !== false) {352 $this->writeGet($id);353 return;354 }355 if ($this->protocol == 0) {356 $this->pickle .= self::OP_STRING . $this->quoteString($value) . "\r\n";357 } else {358 $n = strlen($value);359 if ($n <= 0xFF) {360 // self.write(SHORT_BINSTRING + chr(n) + obj)361 $this->pickle .= self::OP_SHORT_BINSTRING . chr($n) . $value;362 } else {363 // self.write(BINSTRING + pack("<i", n) + obj)364 $binLen = pack('l', $n);365 if (static::$isLittleEndian === false) {366 $binLen = strrev($binLen);367 }368 $this->pickle .= self::OP_BINSTRING . $binLen . $value;369 }370 }371 $this->memorize($value);372 }373 /**374 * Write an associative array value as dictionary375 *376 * @param array|Traversable $value377 */378 protected function writeArrayDict($value)379 {380 if (($id = $this->searchMemo($value)) !== false) {381 $this->writeGet($id);382 return;383 }384 $this->pickle .= self::OP_MARK . self::OP_DICT;385 $this->memorize($value);386 foreach ($value as $k => $v) {387 $this->write($k);388 $this->write($v);389 $this->pickle .= self::OP_SETITEM;390 }391 }392 /**393 * Write a simple array value as list394 *395 * @param array $value396 */397 protected function writeArrayList(array $value)398 {399 if (($id = $this->searchMemo($value)) !== false) {400 $this->writeGet($id);401 return;402 }403 $this->pickle .= self::OP_MARK . self::OP_LIST;404 $this->memorize($value);405 foreach ($value as $v) {406 $this->write($v);407 $this->pickle .= self::OP_APPEND;408 }409 }410 /**411 * Write an object as a dictionary412 *413 * @param object $value414 */415 protected function writeObject($value)416 {417 // The main differences between a SplFixedArray and a normal PHP array is418 // that the SplFixedArray is of fixed length and allows only integers419 // within the range as indexes.420 if ($value instanceof \SplFixedArray) {421 $this->writeArrayList($value->toArray());422 // Use the object method toArray if available423 } elseif (method_exists($value, 'toArray')) {424 $this->writeArrayDict($value->toArray());425 // If the object is an iterator simply iterate it426 // and convert it to a dictionary427 } elseif ($value instanceof Traversable) {428 $this->writeArrayDict($value);429 // other objects are simply converted by using its properties430 } else {431 $this->writeArrayDict(get_object_vars($value));432 }433 }434 /**435 * Write stop436 */437 protected function writeStop()438 {439 $this->pickle .= self::OP_STOP;440 }441 /* serialize helper */442 /**443 * Add a value to the memo and write the id444 *445 * @param mixed $value446 */447 protected function memorize($value)448 {449 $id = count($this->memo);450 $this->memo[$id] = $value;451 $this->writePut($id);452 }453 /**454 * Search a value in the memo and return the id455 *456 * @param mixed $value457 * @return int|bool The id or false458 */459 protected function searchMemo($value)460 {461 return array_search($value, $this->memo, true);462 }463 /**464 * Quote/Escape a string465 *466 * @param string $str467 * @return string quoted string468 */469 protected function quoteString($str)470 {471 $quoteArr = static::$quoteString;472 if (($cntSingleQuote = substr_count($str, "'"))473 && ($cntDoubleQuote = substr_count($str, '"'))474 && ($cntSingleQuote < $cntDoubleQuote)475 ) {476 $quoteArr['"'] = '\\"';477 $enclosure = '"';478 } else {479 $quoteArr["'"] = "\\'";480 $enclosure = "'";481 }482 return $enclosure . strtr($str, $quoteArr) . $enclosure;483 }484 /* unserialize */485 /**486 * Unserialize from Python Pickle format to PHP487 *488 * @param string $pickle489 * @return mixed490 * @throws Exception\RuntimeException on invalid Pickle string491 */492 public function unserialize($pickle)493 {494 // init process vars495 $this->clearProcessVars();496 $this->pickle = $pickle;497 $this->pickleLen = strlen($this->pickle);498 // read pickle string499 while (($op = $this->read(1)) !== self::OP_STOP) {500 $this->load($op);501 }502 if (! count($this->stack)) {503 throw new Exception\RuntimeException('No data found');504 }505 $ret = array_pop($this->stack);506 // clear process vars507 $this->clearProcessVars();508 return $ret;509 }510 /**511 * Clear temp variables needed for processing512 */513 protected function clearProcessVars()514 {515 $this->pos = 0;516 $this->pickle = '';517 $this->pickleLen = 0;518 $this->memo = [];519 $this->stack = [];520 }521 /**522 * Load a pickle opcode523 *524 * @param string $op525 * @throws Exception\RuntimeException on invalid opcode526 */527 protected function load($op)528 {529 switch ($op) {530 case self::OP_PUT:531 $this->loadPut();532 break;533 case self::OP_BINPUT:534 $this->loadBinPut();535 break;536 case self::OP_LONG_BINPUT:537 $this->loadLongBinPut();538 break;539 case self::OP_GET:540 $this->loadGet();541 break;542 case self::OP_BINGET:543 $this->loadBinGet();544 break;545 case self::OP_LONG_BINGET:546 $this->loadLongBinGet();547 break;548 case self::OP_NONE:549 $this->loadNone();550 break;551 case self::OP_NEWTRUE:552 $this->loadNewTrue();553 break;554 case self::OP_NEWFALSE:555 $this->loadNewFalse();556 break;557 case self::OP_INT:558 $this->loadInt();559 break;560 case self::OP_BININT:561 $this->loadBinInt();562 break;563 case self::OP_BININT1:564 $this->loadBinInt1();565 break;566 case self::OP_BININT2:567 $this->loadBinInt2();568 break;569 case self::OP_LONG:570 $this->loadLong();571 break;572 case self::OP_LONG1:573 $this->loadLong1();574 break;575 case self::OP_LONG4:576 $this->loadLong4();577 break;578 case self::OP_FLOAT:579 $this->loadFloat();580 break;581 case self::OP_BINFLOAT:582 $this->loadBinFloat();583 break;584 case self::OP_STRING:585 $this->loadString();586 break;587 case self::OP_BINSTRING:588 $this->loadBinString();589 break;590 case self::OP_SHORT_BINSTRING:591 $this->loadShortBinString();592 break;593 case self::OP_BINBYTES:594 $this->loadBinBytes();595 break;596 case self::OP_SHORT_BINBYTES:597 $this->loadShortBinBytes();598 break;599 case self::OP_UNICODE:600 $this->loadUnicode();601 break;602 case self::OP_BINUNICODE:603 $this->loadBinUnicode();604 break;605 case self::OP_MARK:606 $this->loadMark();607 break;608 case self::OP_LIST:609 $this->loadList();610 break;611 case self::OP_EMPTY_LIST:612 $this->loadEmptyList();613 break;614 case self::OP_APPEND:615 $this->loadAppend();616 break;617 case self::OP_APPENDS:618 $this->loadAppends();619 break;620 case self::OP_DICT:621 $this->loadDict();622 break;623 case self::OP_EMPTY_DICT:624 $this->loadEmptyDict();625 break;626 case self::OP_SETITEM:627 $this->loadSetItem();628 break;629 case self::OP_SETITEMS:630 $this->loadSetItems();631 break;632 case self::OP_TUPLE:633 $this->loadTuple();634 break;635 case self::OP_TUPLE1:636 $this->loadTuple1();637 break;638 case self::OP_TUPLE2:639 $this->loadTuple2();640 break;641 case self::OP_TUPLE3:642 $this->loadTuple3();643 break;644 case self::OP_PROTO:645 $this->loadProto();646 break;647 default:648 throw new Exception\RuntimeException("Invalid or unknown opcode '{$op}'");649 }650 }651 /**652 * Load a PUT opcode653 *654 * @throws Exception\RuntimeException on missing stack655 */656 protected function loadPut()657 {658 $id = (int) $this->readline();659 $lastStack = count($this->stack) - 1;660 if (! isset($this->stack[$lastStack])) {661 throw new Exception\RuntimeException('No stack exist');662 }663 $this->memo[$id] =& $this->stack[$lastStack];664 }665 /**666 * Load a binary PUT667 *668 * @throws Exception\RuntimeException on missing stack669 */670 protected function loadBinPut()671 {672 $id = ord($this->read(1));673 $lastStack = count($this->stack) - 1;674 if (! isset($this->stack[$lastStack])) {675 throw new Exception\RuntimeException('No stack exist');676 }677 $this->memo[$id] =& $this->stack[$lastStack];678 }679 /**680 * Load a long binary PUT681 *682 * @throws Exception\RuntimeException on missing stack683 */684 protected function loadLongBinPut()685 {686 $bin = $this->read(4);687 if (static::$isLittleEndian === false) {688 $bin = strrev($bin);689 }690 list(, $id) = unpack('l', $bin);691 $lastStack = count($this->stack) - 1;692 if (! isset($this->stack[$lastStack])) {693 throw new Exception\RuntimeException('No stack exist');694 }695 $this->memo[$id] =& $this->stack[$lastStack];696 }697 /**698 * Load a GET operation699 *700 * @throws Exception\RuntimeException on missing GET identifier701 */702 protected function loadGet()703 {704 $id = (int) $this->readline();705 if (! array_key_exists($id, $this->memo)) {706 throw new Exception\RuntimeException('Get id "' . $id . '" not found in memo');707 }708 $this->stack[] =& $this->memo[$id];709 }710 /**711 * Load a binary GET operation712 *713 * @throws Exception\RuntimeException on missing GET identifier714 */715 protected function loadBinGet()716 {717 $id = ord($this->read(1));718 if (! array_key_exists($id, $this->memo)) {719 throw new Exception\RuntimeException('Get id "' . $id . '" not found in memo');720 }721 $this->stack[] =& $this->memo[$id];722 }723 /**724 * Load a long binary GET operation725 *726 * @throws Exception\RuntimeException on missing GET identifier727 */728 protected function loadLongBinGet()729 {730 $bin = $this->read(4);731 if (static::$isLittleEndian === false) {732 $bin = strrev($bin);733 }734 list(, $id) = unpack('l', $bin);735 if (! array_key_exists($id, $this->memo)) {736 throw new Exception\RuntimeException('Get id "' . $id . '" not found in memo');737 }738 $this->stack[] =& $this->memo[$id];739 }740 /**741 * Load a NONE operator742 */743 protected function loadNone()744 {745 $this->stack[] = null;746 }747 /**748 * Load a boolean TRUE operator749 */750 protected function loadNewTrue()751 {752 $this->stack[] = true;753 }754 /**755 * Load a boolean FALSE operator756 */757 protected function loadNewFalse()758 {759 $this->stack[] = false;760 }761 /**762 * Load an integer operator763 */764 protected function loadInt()765 {766 $line = $this->readline();767 if ($line === '01') {768 $this->stack[] = true;769 } elseif ($line === '00') {770 $this->stack[] = false;771 } else {772 $this->stack[] = (int) $line;773 }774 }775 /**776 * Load a binary integer operator777 */778 protected function loadBinInt()779 {780 $bin = $this->read(4);781 if (static::$isLittleEndian === false) {782 $bin = strrev($bin);783 }784 list(, $int) = unpack('l', $bin);785 $this->stack[] = $int;786 }787 /**788 * Load the first byte of a binary integer789 */790 protected function loadBinInt1()791 {792 $this->stack[] = ord($this->read(1));793 }794 /**795 * Load the second byte of a binary integer796 */797 protected function loadBinInt2()798 {799 $bin = $this->read(2);800 list(, $int) = unpack('v', $bin);801 $this->stack[] = $int;802 }803 /**804 * Load a long (float) operator805 */806 protected function loadLong()807 {808 $data = rtrim($this->readline(), 'L');809 if ($data === '') {810 $this->stack[] = 0;811 } else {812 $this->stack[] = $data;813 }814 }815 /**816 * Load a one byte long integer817 */818 protected function loadLong1()819 {820 $n = ord($this->read(1));821 $data = $this->read($n);822 $this->stack[] = $this->decodeBinLong($data);823 }824 /**825 * Load a 4 byte long integer826 *827 */828 protected function loadLong4()829 {830 $nBin = $this->read(4);831 if (static::$isLittleEndian === false) {832 $nBin = strrev($nBin);833 }834 list(, $n) = unpack('l', $nBin);835 $data = $this->read($n);836 $this->stack[] = $this->decodeBinLong($data);837 }838 /**839 * Load a float value840 *841 */842 protected function loadFloat()843 {844 $float = (float) $this->readline();845 $this->stack[] = $float;846 }847 /**848 * Load a binary float value849 *850 */851 protected function loadBinFloat()852 {853 $bin = $this->read(8);854 if (static::$isLittleEndian === true) {855 $bin = strrev($bin);856 }857 list(, $float) = unpack('d', $bin);858 $this->stack[] = $float;859 }860 /**861 * Load a string862 *863 */864 protected function loadString()865 {866 $this->stack[] = $this->unquoteString((string) $this->readline());867 }868 /**869 * Load a binary string870 *871 */872 protected function loadBinString()873 {874 $bin = $this->read(4);875 if (! static::$isLittleEndian) {876 $bin = strrev($bin);877 }878 list(, $len) = unpack('l', $bin);879 $this->stack[] = (string) $this->read($len);880 }881 /**882 * Load a short binary string883 *884 */885 protected function loadShortBinString()886 {887 $len = ord($this->read(1));888 $this->stack[] = (string) $this->read($len);889 }890 /**891 * Load arbitrary binary bytes892 */893 protected function loadBinBytes()894 {895 // read byte length896 $nBin = $this->read(4);897 if (static::$isLittleEndian === false) {898 $nBin = strrev($nBin);899 }900 list(, $n) = unpack('l', $nBin);901 $this->stack[] = $this->read($n);902 }903 /**904 * Load a single binary byte905 */906 protected function loadShortBinBytes()907 {908 $n = ord($this->read(1));909 $this->stack[] = $this->read($n);910 }911 /**912 * Load a unicode string913 */914 protected function loadUnicode()915 {916 $data = $this->readline();917 $pattern = '/\\\\u([a-fA-F0-9]{4})/u'; // \uXXXX918 $data = preg_replace_callback($pattern, [$this, 'convertMatchingUnicodeSequence2Utf8'], $data);919 $this->stack[] = $data;920 }921 /**922 * Convert a unicode sequence to UTF-8923 *924 * @param array $match925 * @return string926 */927 protected function convertMatchingUnicodeSequence2Utf8(array $match)928 {929 return $this->hex2Utf8($match[1]);930 }931 /**932 * Convert a hex string to a UTF-8 string933 *934 * @param string $hex935 * @return string936 * @throws Exception\RuntimeException on unmatched unicode sequence937 */938 protected function hex2Utf8($hex)939 {940 $uniCode = hexdec($hex);941 if ($uniCode < 0x80) { // 1Byte942 $utf8Char = chr($uniCode);943 } elseif ($uniCode < 0x800) { // 2Byte944 $utf8Char = chr(0xC0 | $uniCode >> 6)945 . chr(0x80 | $uniCode & 0x3F);946 } elseif ($uniCode < 0x10000) { // 3Byte947 $utf8Char = chr(0xE0 | $uniCode >> 12)948 . chr(0x80 | $uniCode >> 6 & 0x3F)949 . chr(0x80 | $uniCode & 0x3F);950 } elseif ($uniCode < 0x110000) { // 4Byte951 $utf8Char = chr(0xF0 | $uniCode >> 18)952 . chr(0x80 | $uniCode >> 12 & 0x3F)953 . chr(0x80 | $uniCode >> 6 & 0x3F)954 . chr(0x80 | $uniCode & 0x3F);955 } else {956 throw new Exception\RuntimeException(957 sprintf('Unsupported unicode character found "%s"', dechex($uniCode))958 );959 }960 return $utf8Char;961 }962 /**963 * Load binary unicode sequence964 */965 protected function loadBinUnicode()966 {967 // read byte length968 $n = $this->read(4);969 if (static::$isLittleEndian === false) {970 $n = strrev($n);971 }972 list(, $n) = unpack('l', $n);973 $data = $this->read($n);974 $this->stack[] = $data;975 }976 /**977 * Load a marker sequence978 */979 protected function loadMark()980 {981 $this->stack[] = $this->marker;982 }983 /**984 * Load an array (list)985 */986 protected function loadList()987 {988 $k = $this->lastMarker();989 $this->stack[$k] = [];990 // remove all elements after marker991 for ($i = $k + 1, $max = count($this->stack); $i < $max; $i++) {992 unset($this->stack[$i]);993 }994 }995 /**996 * Load an append (to list) sequence997 */998 protected function loadAppend()999 {1000 $value = array_pop($this->stack);1001 $list =& $this->stack[count($this->stack) - 1];1002 $list[] = $value;1003 }1004 /**1005 * Load an empty list sequence1006 */1007 protected function loadEmptyList()1008 {1009 $this->stack[] = [];1010 }1011 /**1012 * Load multiple append (to list) sequences at once1013 */1014 protected function loadAppends()1015 {1016 $k = $this->lastMarker();1017 $list =& $this->stack[$k - 1];1018 $max = count($this->stack);1019 for ($i = $k + 1; $i < $max; $i++) {1020 $list[] = $this->stack[$i];1021 unset($this->stack[$i]);1022 }1023 unset($this->stack[$k]);1024 }1025 /**1026 * Load an associative array (Python dictionary)1027 */1028 protected function loadDict()1029 {1030 $k = $this->lastMarker();1031 $this->stack[$k] = [];1032 // remove all elements after marker1033 $max = count($this->stack);1034 for ($i = $k + 1; $i < $max; $i++) {1035 unset($this->stack[$i]);1036 }1037 }1038 /**1039 * Load an item from a set1040 */1041 protected function loadSetItem()1042 {1043 $value = array_pop($this->stack);1044 $key = array_pop($this->stack);1045 $dict =& $this->stack[count($this->stack) - 1];1046 $dict[$key] = $value;1047 }1048 /**1049 * Load an empty dictionary1050 */1051 protected function loadEmptyDict()1052 {1053 $this->stack[] = [];1054 }1055 /**1056 * Load set items1057 */1058 protected function loadSetItems()1059 {1060 $k = $this->lastMarker();1061 $dict =& $this->stack[$k - 1];1062 $max = count($this->stack);1063 for ($i = $k + 1; $i < $max; $i += 2) {1064 $key = $this->stack[$i];1065 $value = $this->stack[$i + 1];1066 $dict[$key] = $value;1067 unset($this->stack[$i], $this->stack[$i + 1]);1068 }1069 unset($this->stack[$k]);1070 }1071 /**1072 * Load a tuple1073 */1074 protected function loadTuple()1075 {1076 $k = $this->lastMarker();1077 $this->stack[$k] = [];1078 $tuple =& $this->stack[$k];1079 $max = count($this->stack);1080 for ($i = $k + 1; $i < $max; $i++) {1081 $tuple[] = $this->stack[$i];1082 unset($this->stack[$i]);1083 }1084 }1085 /**1086 * Load single item tuple1087 */1088 protected function loadTuple1()1089 {1090 $value1 = array_pop($this->stack);1091 $this->stack[] = [$value1];1092 }1093 /**1094 * Load two item tuple1095 *1096 */1097 protected function loadTuple2()1098 {1099 $value2 = array_pop($this->stack);1100 $value1 = array_pop($this->stack);1101 $this->stack[] = [$value1, $value2];1102 }1103 /**1104 * Load three item tuple1105 *1106 */1107 protected function loadTuple3()1108 {1109 $value3 = array_pop($this->stack);1110 $value2 = array_pop($this->stack);1111 $value1 = array_pop($this->stack);1112 $this->stack[] = [$value1, $value2, $value3];1113 }1114 /**1115 * Load a proto value1116 *1117 * @throws Exception\RuntimeException if Pickle version does not support this feature1118 */1119 protected function loadProto()1120 {1121 $proto = ord($this->read(1));1122 if ($proto < 2 || $proto > 3) {1123 throw new Exception\RuntimeException(1124 "Invalid or unknown protocol version '{$proto}' detected"1125 );1126 }1127 $this->protocol = $proto;1128 }1129 /* unserialize helper */1130 /**1131 * Read a segment of the pickle...

Full Screen

Full Screen

PickleCompiler.php

Source:PickleCompiler.php Github

copy

Full Screen

...5use Cucumber\Messages\DocString;6use Cucumber\Messages\Feature;7use Cucumber\Messages\GherkinDocument;8use Cucumber\Messages\Id\IdGenerator;9use Cucumber\Messages\Pickle;10use Cucumber\Messages\PickleDocString;11use Cucumber\Messages\PickleStep;12use Cucumber\Messages\PickleStepArgument;13use Cucumber\Messages\PickleTable;14use Cucumber\Messages\PickleTableCell;15use Cucumber\Messages\PickleTableRow;16use Cucumber\Messages\PickleTag;17use Cucumber\Messages\Rule;18use Cucumber\Messages\Scenario;19use Cucumber\Messages\Step;20use Cucumber\Messages\TableCell;21use Cucumber\Messages\TableRow;22use Cucumber\Messages\Tag;23use Generator;24final class PickleCompiler25{26 /** @var array<string, PickleStep\Type|null> */27 private array $pickleStepTypeFromKeyword = [];28 private Step\KeywordType $lastKeywordType = Step\KeywordType::UNKNOWN;29 public function __construct(30 private readonly IdGenerator $idGenerator,31 ) {32 $this->pickleStepTypeFromKeyword[Step\KeywordType::UNKNOWN->name] = PickleStep\Type::UNKNOWN;33 $this->pickleStepTypeFromKeyword[Step\KeywordType::CONTEXT->name] = PickleStep\Type::CONTEXT;34 $this->pickleStepTypeFromKeyword[Step\KeywordType::ACTION->name] = PickleStep\Type::ACTION;35 $this->pickleStepTypeFromKeyword[Step\KeywordType::OUTCOME->name] = PickleStep\Type::OUTCOME;36 $this->pickleStepTypeFromKeyword[Step\KeywordType::CONJUNCTION->name] = null;37 }38 /**39 * @return Generator<Pickle>40 */41 public function compile(GherkinDocument $gherkinDocument, string $uri): Generator42 {43 if (!$gherkinDocument->feature) {44 return;45 }46 $feature = $gherkinDocument->feature;47 $language = $feature->language;48 yield from $this->compileFeature($feature, $language, $uri);49 }50 /**51 * @return Generator<Pickle>52 */53 private function compileFeature(Feature $feature, string $language, string $uri): Generator54 {55 $tags = $feature->tags;56 $featureBackgroundSteps = [];57 foreach ($feature->children as $featureChild) {58 if ($featureChild->background) {59 $featureBackgroundSteps = [...$featureBackgroundSteps, ...$featureChild->background->steps];60 } elseif ($featureChild->rule) {61 yield from $this->compileRule($featureChild->rule, $tags, $featureBackgroundSteps, $language, $uri);62 } elseif ($featureChild->scenario) {63 if (!$featureChild->scenario->examples) {64 yield from $this->compileScenario($featureChild->scenario, $tags, $featureBackgroundSteps, $language, $uri);65 } else {66 yield from $this->compileScenarioOutline($featureChild->scenario, $tags, $featureBackgroundSteps, $language, $uri);67 }68 }69 }70 }71 /**72 * @param list<Tag> $parentTags73 * @param list<Step> $featureBackgroundSteps74 *75 * @return Generator<Pickle>76 */77 private function compileRule(Rule $rule, array $parentTags, array $featureBackgroundSteps, string $language, string $uri): Generator78 {79 $ruleBackgroundSteps = $featureBackgroundSteps;80 $ruleTags = [...$parentTags, ...$rule->tags];81 foreach ($rule->children as $ruleChild) {82 if ($ruleChild->background) {83 $ruleBackgroundSteps = [...$ruleBackgroundSteps, ...$ruleChild->background->steps];84 } elseif ($ruleChild->scenario && $ruleChild->scenario->examples) {85 yield from $this->compileScenarioOutline($ruleChild->scenario, $ruleTags, $ruleBackgroundSteps, $language, $uri);86 } elseif ($ruleChild->scenario) {87 yield from $this->compileScenario($ruleChild->scenario, $ruleTags, $ruleBackgroundSteps, $language, $uri);88 }89 }90 }91 /**92 * @param list<Tag> $parentTags93 * @param list<Step> $backgroundSteps94 *95 * @return Generator<Pickle>96 */97 private function compileScenario(Scenario $scenario, array $parentTags, array $backgroundSteps, string $language, string $uri): Generator98 {99 $steps = [100 ...($scenario->steps ? $this->pickleSteps($backgroundSteps) : []),101 ...array_map(fn ($s) => $this->pickleStep($s), $scenario->steps),102 ];103 $tags = [...$parentTags, ...$scenario->tags];104 $this->lastKeywordType = Step\KeywordType::UNKNOWN;105 yield new Pickle(106 id: $this->idGenerator->newId(),107 uri: $uri,108 name: $scenario->name,109 language: $language,110 steps: $steps,111 tags: $this->pickleTags($tags),112 astNodeIds: [$scenario->id],113 );114 }115 /**116 * @param list<Tag> $featureTags117 * @param list<Step> $backgroundSteps118 *119 * @return Generator<Pickle>120 */121 private function compileScenarioOutline(Scenario $scenario, array $featureTags, array $backgroundSteps, string $language, string $uri): Generator122 {123 foreach ($scenario->examples as $examples) {124 if (!$examples->tableHeader) {125 continue;126 }127 $variableCells = $examples->tableHeader->cells;128 foreach ($examples->tableBody as $valuesRow) {129 $valueCells = $valuesRow->cells;130 $steps = [131 ...($scenario->steps ? $this->pickleSteps($backgroundSteps) : []),132 ...array_map(fn ($s) => $this->pickleStep($s, $variableCells, $valuesRow), $scenario->steps),133 ];134 $tags = [...$featureTags, ...$scenario->tags, ...$examples->tags];135 $sourceIds = [$scenario->id, $valuesRow->id];136 yield new Pickle(137 id: $this->idGenerator->newId(),138 uri: $uri,139 name: $this->interpolate($scenario->name, $variableCells, $valueCells),140 language: $language,141 steps: $steps,142 tags: $this->pickleTags($tags),143 astNodeIds: $sourceIds,144 );145 }146 }147 }148 /**149 * @param list<Step> $steps150 * @return list<PickleStep>151 */152 private function pickleSteps(array $steps): array153 {154 return array_map(fn ($s) => $this->pickleStep($s), $steps);155 }156 /**157 * @param list<TableCell> $variableCells158 */159 private function pickleStep(Step $step, array $variableCells = [], ?TableRow $valuesRow = null): PickleStep160 {161 $valueCells = $valuesRow?->cells ?? [];162 $stepText = $this->interpolate($step->text, $variableCells, $valueCells);163 $astNodeIds = $valuesRow ? [$step->id, $valuesRow->id] : [$step->id];164 if ($step->dataTable) {165 $argument = new PickleStepArgument(dataTable: $this->pickleDataTable($step->dataTable, $variableCells, $valueCells));166 } elseif ($step->docString) {167 $argument = new PickleStepArgument(docString: $this->pickleDocString($step->docString, $variableCells, $valueCells));168 } else {169 $argument = null;170 }171 $this->lastKeywordType =172 $step->keywordType === Step\KeywordType::CONJUNCTION173 ? $this->lastKeywordType174 : ($step->keywordType ?? Step\KeywordType::UNKNOWN)175 ;176 return new PickleStep(177 argument: $argument,178 astNodeIds: $astNodeIds,179 id: $this->idGenerator->newId(),180 type: $this->pickleStepTypeFromKeyword[$this->lastKeywordType->name],181 text: $stepText,182 );183 }184 /**185 * @param list<TableCell> $variableCells186 * @param list<TableCell> $valueCells187 */188 private function interpolate(string $name, array $variableCells, array $valueCells): string189 {190 $variables = array_map(fn ($c) => '<'.$c->value.'>', $variableCells);191 $values = array_map(fn ($c) => $c->value, $valueCells);192 $replacements = array_combine($variables, $values);193 return StringUtils::replace($name, $replacements);194 }195 /**196 * @param list<TableCell> $variableCells197 * @param list<TableCell> $valueCells198 */199 private function pickleDataTable(DataTable $dataTable, array $variableCells, array $valueCells): PickleTable200 {201 return new PickleTable(202 rows: array_map(203 fn ($r) => new PickleTableRow(204 cells: array_map(205 fn ($c) => new PickleTableCell(206 $this->interpolate($c->value, $variableCells, $valueCells),207 ),208 $r->cells,209 ),210 ),211 $dataTable->rows,212 ),213 );214 }215 /**216 * @param list<TableCell> $variableCells217 * @param list<TableCell> $valueCells218 */219 private function pickleDocString(DocString $docstring, array $variableCells, array $valueCells): PickleDocString220 {221 return new PickleDocString(222 mediaType: $docstring->mediaType ? $this->interpolate($docstring->mediaType, $variableCells, $valueCells) : null,223 content: $this->interpolate($docstring->content, $variableCells, $valueCells),224 );225 }226 /**227 * @param list<Tag> $tags228 * @return list<PickleTag>229 */230 private function pickleTags(array $tags): array231 {232 return array_map(fn ($t) => $this->pickleTag($t), $tags);233 }234 private function pickleTag(Tag $tag): PickleTag235 {236 return new PickleTag($tag->name, $tag->id);237 }238}...

Full Screen

Full Screen

class-picklecalendar.php

Source:class-picklecalendar.php Github

copy

Full Screen

1<?php2/**3 * Main Pickle Calendar class4 *5 * @package PickleCalendar6 * @since 1.0.07 */8/**9 * Final PickleCalendar class.10 *11 * @final12 */13final class PickleCalendar {14 /**15 * Version16 *17 * @var string18 * @access public19 */20 public $version = '1.4.0';21 /**22 * Settings.23 *24 * (default value: '').25 *26 * @var string27 * @access public28 */29 public $settings = '';30 /**31 * Calendar.32 *33 * (default value: '').34 *35 * @var string36 * @access public37 */38 public $calendar = '';39 /**40 * Import/Export events.41 *42 * (default value: '').43 *44 * @var string45 * @access public46 */47 public $import_export_events = '';48 /**49 * Admin50 *51 * (default value: '')52 *53 * @var string54 * @access public55 */56 public $admin = '';57 /**58 * Construct function.59 *60 * @access public61 * @return void62 */63 public function __construct() {64 $this->define_constants();65 $this->includes();66 $this->init_hooks();67 $this->init();68 do_action( 'pickle_calendar_loaded' );69 }70 /**71 * Define constants function.72 *73 * @access private74 * @return void75 */76 private function define_constants() {77 $this->define( 'PICKLE_CALENDAR_PATH', plugin_dir_path( __FILE__ ) );78 $this->define( 'PICKLE_CALENDAR_URL', plugin_dir_url( __FILE__ ) );79 $this->define( 'PICKLE_CALENDAR_VERSION', $this->version );80 $this->define( 'PICKLE_CALENDAR_REQUIRES', '3.8' );81 $this->define( 'PICKLE_CALENDAR_TESTED', '4.9.5' );82 }83 /**84 * Define function.85 *86 * @access private87 * @param mixed $name (name).88 * @param mixed $value (value).89 * @return void90 */91 private function define( $name, $value ) {92 if ( ! defined( $name ) ) {93 define( $name, $value );94 }95 }96 /**97 * Includes function.98 *99 * @access public100 * @return void101 */102 public function includes() {103 include_once( PICKLE_CALENDAR_PATH . 'update-functions.php' );104 include_once( PICKLE_CALENDAR_PATH . 'class-pickle-calendar-install.php' );105 include_once( PICKLE_CALENDAR_PATH . 'templates.php' );106 include_once( PICKLE_CALENDAR_PATH . 'functions.php' );107 include_once( PICKLE_CALENDAR_PATH . 'admin/class-pickle-calendar-admin.php' );108 include_once( PICKLE_CALENDAR_PATH . 'admin/class-pickle-calendar-admin-functions.php' );109 include_once( PICKLE_CALENDAR_PATH . 'class-pickle-calendar.php' );110 include_once( PICKLE_CALENDAR_PATH . 'admin/class-pickle-calendar-event-details.php' );111 include_once( PICKLE_CALENDAR_PATH . 'class-pickle-calendar-post-types.php' );112 include_once( PICKLE_CALENDAR_PATH . 'class-pickle-calendar-import-export-events.php' );113 if ( is_admin() ) {114 $this->admin = new Pickle_Calendar_Admin_Functions();115 }116 }117 /**118 * Init hooks function.119 *120 * @access private121 * @return void122 */123 private function init_hooks() {124 register_activation_hook( PICKLE_CALENDAR_PLUGIN_FILE, array( 'Pickle_Calendar_Install', 'install' ) );125 }126 /**127 * Init function.128 *129 * @access public130 * @return void131 */132 public function init() {133 $this->settings = $this->settings();134 $this->calendar = new Pickle_Calendar();135 $this->import_export_events = new Pickle_Calendar_Import_Export_Events();136 do_action( 'pickle_calendar_init' );137 }138 /**139 * Settings function.140 *141 * @access public142 * @return array143 */144 public function settings() {145 $default_settings = array(146 'adminlabel' => 'Events',147 'cpt_single' => 'Event',148 'cpt_plural' => 'Events',149 'enable_editor' => false,150 'show_start_date' => true,151 'show_end_date' => true,152 'hide_weekends' => false,153 );154 $db_settings = get_option( 'pickle_calendar_settings', '' );155 $settings = $this->parse_args( $db_settings, $default_settings );156 $settings['taxonomies'] = get_option( 'pickle_calendar_taxonomies', '' );157 return $settings;158 }159 /**160 * Update settings function.161 *162 * @access public163 * @return void164 */165 public function update_settings() {166 $this->settings = $this->settings();167 }168 /**169 * Parse args function.170 *171 * @access public172 * @param mixed $a (array).173 * @param mixed $b (array).174 * @return array175 */176 public function parse_args( &$a, $b ) {177 $a = (array) $a;178 $b = (array) $b;179 $result = $b;180 foreach ( $a as $k => &$v ) {181 if ( is_array( $v ) && isset( $result[ $k ] ) ) {182 $result[ $k ] = $this->parse_args( $v, $result[ $k ] );183 } else {184 $result[ $k ] = $v;185 }186 }187 return $result;188 }189}190/**191 * Main function.192 *193 * @access public194 * @return class195 */196function picklecalendar() {197 return new PickleCalendar();198}199// Global for backwards compatibility.200$GLOBALS['picklecalendar'] = picklecalendar();...

Full Screen

Full Screen

Pickle

Using AI Code Generation

copy

Full Screen

1require_once('cucumber_common_lib.php');2$Pickle = new Pickle();3$Pickle->eat();4$Pickle->make();5$Pickle->store();6class Pickle{7 function eat(){8 echo "Eating Pickle";9 }10 function make(){11 echo "Making Pickle";12 }13 function store(){14 echo "Storing Pickle";15 }16}17require_once('cucumber_common_lib.php');18$Pickle = new Pickle();19$Pickle->eat();20$Pickle->make();21$Pickle->store();22require_once('cucumber_common_lib.php');23$Pickle = new Pickle();24$Pickle->eat();25$Pickle->make();26$Pickle->store();

Full Screen

Full Screen

Pickle

Using AI Code Generation

copy

Full Screen

1require_once 'Cucumber/Common/Pickle.php';2$pickle = new Pickle();3$pickle->pickleMe();4require_once 'Cucumber/Common/Pickle.php';5$pickle = new Pickle();6$pickle->pickleMe();7require_once 'Cucumber/Common/Pickle.php';8$pickle = new Pickle();9$pickle->pickleMe();10require_once 'Cucumber/Common/Pickle.php';11$pickle = new Pickle();12$pickle->pickleMe();13require_once 'Cucumber/Common/Pickle.php';14$pickle = new Pickle();15$pickle->pickleMe();16require_once 'Cucumber/Common/Pickle.php';17$pickle = new Pickle();18$pickle->pickleMe();19require_once 'Cucumber/Common/Pickle.php';20$pickle = new Pickle();21$pickle->pickleMe();22require_once 'Cucumber/Common/Pickle.php';23$pickle = new Pickle();

Full Screen

Full Screen

Pickle

Using AI Code Generation

copy

Full Screen

1include_once("CucumberCommonLibrary/Pickle.php");2$Pickle = new Pickle();3$Pickle->get_file_contents("1.php");4$Pickle->get_file_contents("2.php");5$Pickle->get_file_contents("3.php");6$Pickle->get_file_contents("4.php");7$Pickle->get_file_contents("5.php");8$Pickle->get_file_contents("6.php");9$Pickle->get_file_contents("7.php");10$Pickle->get_file_contents("8.php");11$Pickle->get_file_contents("9.php");12$Pickle->get_file_contents("10.php");13$Pickle->get_file_contents("11.php");14$Pickle->get_file_contents("12.php");15$Pickle->get_file_contents("13.php");16$Pickle->get_file_contents("14.php");17$Pickle->get_file_contents("15.php");18$Pickle->get_file_contents("16.php");19$Pickle->get_file_contents("17.php");20$Pickle->get_file_contents("18.php");21$Pickle->get_file_contents("19.php");22$Pickle->get_file_contents("20.php");

Full Screen

Full Screen

Pickle

Using AI Code Generation

copy

Full Screen

1require_once('cucumber_common_library.php');2$Pickle = new Pickle();3$Pickle->runTestCase("2.feature");4class Pickle {5 public $feature;6 public $scenario;7 public $steps;8 public $step;9 public $stepNumber;10 public $stepCount;11 public $stepResult;12 public $stepResultMessage;13 public $stepResultColor;14 public $stepResultTime;15 public $stepResultTimeColor;16 public $stepResultTimeColor;17 public $stepResultTimeColor;18 public $stepResultTimeColor;19 public $featureResult;20 public $featureResultMessage;21 public $featureResultColor;22 public $featureResultTime;23 public $featureResultTimeColor;24 public $scenarioResult;25 public $scenarioResultMessage;26 public $scenarioResultColor;27 public $scenarioResultTime;28 public $scenarioResultTimeColor;29 public $totalResult;30 public $totalResultMessage;31 public $totalResultColor;32 public $totalResultTime;

Full Screen

Full Screen

Pickle

Using AI Code Generation

copy

Full Screen

1require_once("cucumber.php");2$Pickle = new Pickle();3$Pickle->parse("2.html");4$Pickle->set("name", "John Doe");5$Pickle->set("address", "123 Main Street");6$Pickle->set("city", "New York");7$Pickle->set("state", "NY");8$Pickle->set("zip", "10001");9$Pickle->set("phone", "212-555-1212");10$Pickle->set("email", "

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 Cucumber Common Library automation tests on LambdaTest cloud grid

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

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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