Best Atoum code snippet using token.seek
FileTest.php
Source:FileTest.php
...130 $file->add($token);131 $this->assertEquals('T_OPEN_TAG T_CLOSE_TAG', (string) $file);132 }133 /**134 * @covers spriebsch\PHPca\File::seek135 * @covers spriebsch\PHPca\File::add136 */137 public function testSeek()138 {139 $file = new File('filename', 'sourcecode');140 $file->add(new Token(T_OPEN_TAG, '<?php'));141 $file->add(new Token(T_CLASS, 'class'));142 $file->add(new Token(T_FUNCTION, 'function'));143 $file->add(new Token(T_CLOSE_TAG, '?>'));144 $file->seek(2);145 $this->assertEquals('T_FUNCTION', $file->current()->getName());146 }147 /**148 * @covers spriebsch\PHPca\File::seekToken149 * @covers spriebsch\PHPca\File::add150 */151 public function testSeekToken()152 {153 $token = new Token(T_CLASS, 'class');154 $file = new File('filename', 'sourcecode');155 $file->add(new Token(T_OPEN_TAG, '<?php'));156 $file->add(new Token(T_FUNCTION, 'function'));157 $file->add($token);158 $file->add(new Token(T_CLOSE_TAG, '?>'));159 $file->seekToken($token);160 $this->assertSame($token, $file->current());161 }162 /**163 * @covers spriebsch\PHPca\File::seekTokenId164 * @covers spriebsch\PHPca\File::add165 */166 public function testSeekTokenId()167 {168 $file = new File('filename', 'sourcecode');169 $file->add(new Token(T_OPEN_TAG, '<?php'));170 $file->add(new Token(T_FUNCTION, 'function'));171 $file->add(new Token(T_CLASS, 'class'));172 $file->add(new Token(T_CLOSE_TAG, '?>'));173 $file->rewind();174 $file->seekTokenId(T_CLASS);175 $this->assertEquals('T_CLASS', $file->current()->getName());176 }177 /**178 * @covers spriebsch\PHPca\File::seekMatchingCurlyBrace179 * @expectedException spriebsch\PHPca\Exception180 */181 public function testSeekMatchingCurlyBraceThrowsExceptionOnNonCurlyBrace()182 {183 $file = new File('filename', 'sourcecode');184 $file->seekMatchingCurlyBrace(new Token(T_OPEN_TAG, '<?php'));185 }186 /**187 * @covers spriebsch\PHPca\File::seekMatchingCurlyBrace188 */189 public function testSeekMatchingCurlyBraceForFunction()190 {191 $file = Tokenizer::tokenize('test.php', file_get_contents(__DIR__ . '/_testdata/File/braces.php'));192 $file->rewind();193 $file->seekTokenId(T_FUNCTION);194 $file->seekTokenId(T_OPEN_CURLY);195 $openBrace = $file->current();196 $file->seekMatchingCurlyBrace($openBrace);197 $this->assertEquals('T_CLOSE_CURLY', $file->current()->getName());198 $this->assertEquals(24, $file->current()->getLine());199 $this->assertEquals($openBrace->getBlockLevel(), $file->current()->getBlockLevel());200 }201 /**202 * @covers spriebsch\PHPca\File::seekMatchingCurlyBrace203 */204 public function testSeekMatchingCurlyBraceForFunctionReverse()205 {206 $file = Tokenizer::tokenize('test.php', file_get_contents(__DIR__ . '/_testdata/File/braces.php'));207 $file->seek(sizeof($file) - 1);208 $file->prev();209 $file->prev();210 $file->prev();211 $file->prev();212 $closeBrace = $file->current();213 $file->seekMatchingCurlyBrace($closeBrace);214 $this->assertEquals('T_OPEN_CURLY', $file->current()->getName());215 $this->assertEquals(9, $file->current()->getLine());216 $this->assertEquals($closeBrace->getBlockLevel(), $file->current()->getBlockLevel());217 }218 /**219 * @covers spriebsch\PHPca\File::seekMatchingCurlyBrace220 */221 public function testSeekMatchingCurlyBraceForClass()222 {223 $file = Tokenizer::tokenize('test.php', file_get_contents(__DIR__ . '/_testdata/File/braces.php'));224 $file->rewind();225 $file->seekTokenId(T_CLASS);226 $file->seekTokenId(T_OPEN_CURLY);227 $openBrace = $file->current();228 $file->seekMatchingCurlyBrace($openBrace);229 $this->assertEquals('T_CLOSE_CURLY', $file->current()->getName());230 $this->assertEquals(25, $file->current()->getLine());231 $this->assertEquals($openBrace->getBlockLevel(), $file->current()->getBlockLevel());232 }233 /**234 * @covers spriebsch\PHPca\File::seekMatchingCurlyBrace235 */236 public function testSeekMatchingCurlyBraceForClassReverse()237 {238 $file = Tokenizer::tokenize('test.php', file_get_contents(__DIR__ . '/_testdata/File/braces.php'));239 $file->seek(sizeof($file) - 1);240 $file->prev();241 $file->prev();242 $closeBrace = $file->current();243 $file->seekMatchingCurlyBrace($closeBrace);244 $this->assertEquals('T_OPEN_CURLY', $file->current()->getName());245 $this->assertEquals(4, $file->current()->getLine());246 $this->assertEquals($closeBrace->getBlockLevel(), $file->current()->getBlockLevel());247 }248 /**249 * @covers spriebsch\PHPca\File::seekTokenId250 * @covers spriebsch\PHPca\File::add251 */252 public function testSeekTokenIdReturnsFalseWhenTokenDoesNotExist()253 {254 $file = new File('filename', 'sourcecode');255 $file->add(new Token(T_OPEN_TAG, '<?php'));256 $file->rewind();257 $this->assertFalse($file->seekTokenId(T_PUBLIC));258 }259 /**260 * @covers spriebsch\PHPca\File::seekToken261 * @covers spriebsch\PHPca\File::add262 * @expectedException spriebsch\PHPca\Exception263 */264 public function testSeekTokenThrowsExceptionWhenTokenDoesNotExist()265 {266 $file = new File('filename', 'sourcecode');267 $file->add(new Token(T_OPEN_TAG, '<?php'));268 $file->rewind();269 $file->seekToken(new Token(T_CLOSE_TAG, '?>'));270 }271 /**272 * @covers spriebsch\PHPca\File::seek273 * @expectedException \OutOfBoundsException274 */275 public function testSeekThrowsExceptionOnInvalidPosition()276 {277 $file = new File('filename', 'sourcecode');278 $file->seek(1);279 }280 /**281 * @covers spriebsch\PHPca\File::seekNamespace282 */283 public function testSeekNamespace()284 {285 $file = Tokenizer::tokenize('test.php', file_get_contents(__DIR__ . '/_testdata/File/blocks.php'));286 $file->rewind();287 $file->seekNamespace('B\\C');288 $this->assertEquals('T_OPEN_CURLY', $file->current()->getName());289 $this->assertEquals(18, $file->current()->getLine());290 $file->seekNamespace('A\\B');291 $this->assertEquals('T_OPEN_CURLY', $file->current()->getName());292 $this->assertEquals(4, $file->current()->getLine());293 }294// /**295// * @covers spriebsch\PHPca\File::seekClass296// */297// public function testSeekClass()298// {299// $file = Tokenizer::tokenize('test.php', file_get_contents(__DIR__ . '/_testdata/File/blocks.php'));300// $file->rewind();301//302// $file->seekClass('Test');303//304// $this->assertEquals('T_OPEN_CURLY', $file->current()->getName());305// $this->assertEquals(6, $file->current()->getLine());306// $this->assertEquals(5, $file->current()->getColumn());307// }308}309?>...
get.php
Source:get.php
...82 }83}else{84 $range = '';85}86list($seek_start, $seek_end) = explode('-', $range, 2);87$seek_end = (empty($seek_end)) ? ($size - 1) : min(abs(intval($seek_end)),($size - 1));88$seek_start = (empty($seek_start) || $seek_end < abs(intval($seek_start))) ? 0 : max(abs(intval($seek_start)),0);89if (isset($_SERVER['HTTP_RANGE'])){90 header('HTTP/1.1 206 Partial Content');91}92header("Content-Type: video/mpeg");93header('Content-Length: '.($seek_end - $seek_start + 1));94header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$size);95$offset = 0;96_log("Queue length: ".count($queue));97foreach ($queue as $item){98 _log("File: ".$item["filename"]);99 _log("Size: ".$item["size"]);100 _log("Start: ".$seek_start);101 _log("End: ".$seek_end);102 _log("From Byte: ".$item["from_byte"]);103 _log("To Byte: ".$item["to_byte"]);104 _log("Filesize: ".filesize($item["filename"]));105 _log("Offset: ".$offset);106 if (($offset + $item["from_byte"] + $seek_start) <= ($offset + filesize($item["filename"]))){107 $is_first_file = !isset($fp);108 $fp = fopen($item["filename"], 'rb');109 fseek($fp, $item["from_byte"] + $seek_start);110 if ($is_first_file && $seek_start == 0){ // seek to 0x47 for first file111 $skipped = 0;112 while (($char = fgetc($fp)) != 'G'){113 $skipped++;114 }115 header('Content-Length: '.($seek_end - $seek_start + 1 - $skipped));116 header('Content-Range: bytes '.$seek_start.'-'.($seek_end-$skipped).'/'.($size-$skipped));117 fseek($fp, ftell($fp)-1);118 }119 _log("Seek: ".($item["from_byte"] + $seek_start));120 }else{121 $offset += filesize($item["filename"]);122 $seek_start -= filesize($item["filename"]) - $item["from_byte"];123 continue;124 }125 set_time_limit(0);126 while(!feof($fp)){127 $buf_size = 1024*8;128 $pos = ftell($fp);129 if ($pos >= $item["to_byte"]){130 _log("File close: ".$item["filename"]." on pos: ".$pos);131 fclose($fp);132 break;133 }134 if ($pos + $buf_size > $item["to_byte"]){135 $buf_size = $item["to_byte"] - $pos;136 }137 if ($buf_size > 0){138 echo fread($fp, $buf_size);139 }140 flush();141 ob_flush();142 }143 144 if (is_resource($fp)){145 _log("Close file resource");146 fclose($fp);147 }148 //$offset += $item["size"];149 $offset += filesize($item["filename"]);150 $seek_start = 0;151} 152function get_next_file($file){153 $filename = basename($file);154 $filename = substr($filename, 0, strpos($filename, "."));155 $filedate = $filename.":00:00";156 $filedate = str_replace("-", " ", $filedate);157 $filedate = strtotime($filedate." +1 hour");158 return str_replace($filename, date("Ymd-H", $filedate), $file);159}160function file_in_current_hour($file){161 $filename = basename($file);162 $filename = substr($filename, 0, strpos($filename, "."));163 _log('file: '.$filename." - ".date("Ymd-H")." ".(date("Ymd-H") == $filename));164 return $filename == date("Ymd-H");...
TokenListIteratorTest.php
Source:TokenListIteratorTest.php
...29 * @expectedException \HippoPHP\Tokenizer\Exception\OutOfBoundsException30 */31 public function testSeekOutOfRange()32 {33 $this->tokenList->seek(999);34 }35 public function testSeekValid()36 {37 $this->tokenList->seek(1);38 $this->assertEquals(1, $this->tokenList->key());39 }40 public function testRewind()41 {42 $this->tokenList->next();43 $this->tokenList->rewind();44 $this->assertEquals(0, $this->tokenList->key());45 }46 public function testMoveAround()47 {48 $this->tokenList->next();49 $this->assertEquals(1, $this->tokenList->key());50 $this->tokenList->prev();51 $this->assertEquals(0, $this->tokenList->key());52 }53 /**54 * @expectedException \HippoPHP\Tokenizer\Exception\InvalidArgumentException55 */56 public function testMoveAroundInvalid()57 {58 $this->tokenList->move(3);59 }60 public function testIsValid()61 {62 $this->assertTrue($this->tokenList->valid());63 $this->tokenList->seek(count($this->tokenList) - 1);64 $this->tokenList->next();65 $this->assertFalse($this->tokenList->valid());66 }67 /**68 * @expectedException \HippoPHP\Tokenizer\Exception\OutOfBoundsException69 */70 public function testGetInvalid()71 {72 $this->tokenList->seek(count($this->tokenList) - 1);73 $this->tokenList->next();74 $this->tokenList->current();75 }76 public function testSeekToType()77 {78 $seekToken = new Token(T_WHITESPACE, "\t", 2, 1);79 $this->assertEquals($seekToken, $this->tokenList->seekToType(T_WHITESPACE)->current());80 }81 public function testSeekToTypeArray()82 {83 $seekToken = new Token(T_WHITESPACE, "\t", 2, 1);84 $this->assertEquals($seekToken, $this->tokenList->seekToType([T_WHITESPACE])->current());85 }86 public function testSeekBackwards()87 {88 $this->tokenList->seek(2);89 $actualToken = $this->tokenList->seekToType(T_WHITESPACE, TokenListIterator::DIR_BACKWARD)->current();90 $this->assertNotNull($actualToken);91 $this->assertEquals(T_WHITESPACE, $actualToken->getType());92 }93 /**94 * @expectedException \HippoPHP\Tokenizer\Exception\OutOfBoundsException95 */96 public function testSeekToNonExistingType()97 {98 $this->tokenList->seekToType(T_OPEN_TAG);99 }100 /**101 * @expectedException \HippoPHP\Tokenizer\Exception\OutOfBoundsException102 */103 public function testSeekToNonExistingTypeReset()104 {105 try {106 $this->tokenList->seekToType(T_OPEN_TAG);107 } catch (\Exception $e) {108 $this->assertEquals(0, $this->tokenList->key());109 throw $e;110 }111 }112 public function testSkipTypes()113 {114 $ignoreTokens = [115 T_OPEN_TAG,116 T_WHITESPACE,117 ];118 $expectedToken = new Token(T_VARIABLE, '$var', 2, 2);119 $this->assertEquals($expectedToken, $this->tokenList->skipTypes($ignoreTokens)->current());120 }...
seek
Using AI Code Generation
1$token = new Token();2$token->seek(3);3echo $token->current();4$token = new Token();5$token->seek(3);6echo $token->current();7$token = new Token();8$token->seek(3);9echo $token->current();10$token = new Token();11$token->seek(3);12echo $token->current();13$token = new Token();14$token->seek(3);15echo $token->current();16$token = new Token();17$token->seek(3);18echo $token->current();19$token = new Token();20$token->seek(3);21echo $token->current();22$token = new Token();23$token->seek(3);24echo $token->current();25$token = new Token();26$token->seek(3);27echo $token->current();28$token = new Token();29$token->seek(3);30echo $token->current();31$token = new Token();32$token->seek(3);33echo $token->current();34$token = new Token();35$token->seek(3);36echo $token->current();37$token = new Token();38$token->seek(3);39echo $token->current();40$token = new Token();41$token->seek(3);42echo $token->current();
seek
Using AI Code Generation
1$token->seek(0);2$token->seek(0);3$token->seek(0);4$token->seek(0);5$token->seek(0);6$token->seek(0);7$token->seek(0);8$token->seek(0);9$token->seek(0);10$token->seek(0);11$token->seek(0);12$token->seek(0);13$token->seek(0);14$token->seek(0);15$token->seek(0);
seek
Using AI Code Generation
1$tokens = token_get_all(file_get_contents('1.php'));2$tokens = new Token($tokens);3$tokens->seek(0);4while ($tokens->valid()) {5 $token = $tokens->current();6 if (is_array($token) && $token[0] == T_COMMENT) {7 echo $token[1];8 }9 $tokens->next();10}
seek
Using AI Code Generation
1require_once('Token.php');2$token = new Token();3require_once('Token.php');4$token = new Token();5require_once('Token.php');6$token = new Token();7require_once('Token.php');8$token = new Token();9require_once('Token.php');10$token = new Token();11require_once('Token.php');12$token = new Token();13require_once('Token.php');14$token = new Token();15require_once('Token.php');16$token = new Token();17require_once('Token.php');18$token = new Token();19require_once('Token.php');20$token = new Token();21require_once('Token.php');22$token = new Token();23require_once('Token.php');24$token = new Token();
seek
Using AI Code Generation
1require_once 'Token.php';2$token = new Token();3$token->seek(1, 1);4$token->seek(2, 2);5$token->seek(3, 3);6$token->seek(4, 4);7$token->seek(5, 5);8$token->seek(6, 6);9$token->seek(7, 7);10$token->seek(8, 8);11$token->seek(9, 9);12$token->seek(10, 10);13$token->seek(11, 11);14$token->seek(12, 12);15$token->seek(13, 13);16$token->seek(14, 14);17$token->seek(15, 15);18$token->seek(16, 16);19$token->seek(17, 17);20$token->seek(18, 18);21$token->seek(19, 19);22$token->seek(20, 20);23$token->seek(21, 21);24$token->seek(22, 22);25$token->seek(23, 23);26$token->seek(24, 24);27$token->seek(25, 25);28$token->seek(26, 26);29$token->seek(27, 27);30$token->seek(28, 28);31$token->seek(29, 29);32$token->seek(30, 30);33$token->seek(31, 31);34$token->seek(32, 32);35$token->seek(33, 33);36$token->seek(34, 34);37$token->seek(35, 35);38$token->seek(36, 36);39$token->seek(37, 37);40$token->seek(38, 38);41$token->seek(39, 39);42$token->seek(40, 40);43$token->seek(41, 41);44$token->seek(42, 42);45$token->seek(43, 43);46$token->seek(44, 44);47$token->seek(45, 45);48$token->seek(46, 46);49$token->seek(47, 47);50$token->seek(48, 48);51$token->seek(49
seek
Using AI Code Generation
1$token = new Token();2$token->seek(1);3echo $token->current();4Recommended Posts: PHP | next() Function5PHP | prev() Function6PHP | key() Function7PHP | current() Function8PHP | count_chars() Function9PHP | array_multisort() Function10PHP | array_pad() Function11PHP | array_pop() Function12PHP | array_product() Function13PHP | array_push() Function14PHP | array_rand() Function15PHP | array_reduce() Function16PHP | array_replace() Function17PHP | array_replace_recursive() Function18PHP | array_reverse() Function19PHP | array_search() Function20PHP | array_shift() Function21PHP | array_slice() Function22PHP | array_splice() Function23PHP | array_sum() Function24PHP | array_udiff() Function25PHP | array_udiff_assoc() Function26PHP | array_udiff_uassoc() Function27PHP | array_uintersect() Function28PHP | array_uintersect_assoc() Function29PHP | array_uintersect_uassoc() Function30PHP | array_unique() Function31PHP | array_unshift() Function32PHP | array_values() Function33PHP | array_walk() Function34PHP | array_walk_recursive() Function35PHP | array() Function36PHP | asort() Function37PHP | compact() Function38PHP | count() Function39PHP | current() Function40PHP | each() Function41PHP | end() Function42PHP | extract() Function43PHP | in_array() Function44PHP | key() Function45PHP | krsort() Function46PHP | ksort() Function47PHP | natcasesort() Function48PHP | natsort() Function49PHP | next() Function50PHP | pos() Function51PHP | prev() Function52PHP | range() Function53PHP | reset() Function54PHP | rsort() Function55PHP | shuffle() Function56PHP | sizeof() Function57PHP | sort() Function58PHP | uasort() Function59PHP | uksort() Function60PHP | usort() Function61PHP | current() Function62PHP | current() Function
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with seek on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!