How to use fromArray method of Examples class

Best Cucumber Common Library code snippet using Examples.fromArray

ArrayHelperTest.php

Source:ArrayHelperTest.php Github

copy

Full Screen

...31 [['a', 'b', 'c'], 1, [2, 3]],32 ['a', 'b', 'c', 1, 2, 3]33 ],34 'traversable' => [35 [TestArrayIterator::fromArray([1, 2, 3]), [4, 5, 6]],36 [1, 2, 3, 4, 5, 6]37 ]38 ];39 }40 /**41 * @test42 * @dataProvider concatExamples43 */44 public function concatWorks($arguments, $expected)45 {46 $helper = new ArrayHelper();47 $result = $helper->concat(...$arguments);48 self::assertEquals($expected, $result);49 }50 public function joinExamples()51 {52 return [53 'words with default separator' => [['a', 'b', 'c'], null, 'a,b,c'],54 'words with custom separator' => [['a', 'b', 'c'], ', ', 'a, b, c'],55 'empty array' => [[], ', ', ''],56 'traversable' => [TestArrayIterator::fromArray(['a', 'b', 'c']), ', ', 'a, b, c'],57 ];58 }59 /**60 * @test61 * @dataProvider joinExamples62 */63 public function joinWorks($array, $separator, $expected)64 {65 $helper = new ArrayHelper();66 if ($separator !== null) {67 $result = $helper->join($array, $separator);68 } else {69 $result = $helper->join($array);70 }71 self::assertEquals($expected, $result);72 }73 public function sliceExamples()74 {75 return [76 'positive begin without end' => [['a', 'b', 'c', 'd', 'e'], 2, null, ['c', 'd', 'e']],77 'negative begin without end' => [['a', 'b', 'c', 'd', 'e'], -2, null, ['d', 'e']],78 'positive begin and end' => [['a', 'b', 'c', 'd', 'e'], 1, 3, ['b', 'c']],79 'positive begin with negative end' => [['a', 'b', 'c', 'd', 'e'], 1, -2, ['b', 'c']],80 'zero begin with negative end' => [['a', 'b', 'c', 'd', 'e'], 0, -1, ['a', 'b', 'c', 'd']],81 'empty array' => [[], 1, -2, []],82 'traversable' => [TestArrayIterator::fromArray(['a', 'b', 'c']), 2, null, ['c']],83 ];84 }85 /**86 * @test87 * @dataProvider sliceExamples88 */89 public function sliceWorks($array, $begin, $end, $expected)90 {91 $helper = new ArrayHelper();92 if ($end !== null) {93 $result = $helper->slice($array, $begin, $end);94 } else {95 $result = $helper->slice($array, $begin);96 }97 self::assertEquals($expected, $result);98 }99 public function reverseExamples()100 {101 return [102 'empty array' => [[], []],103 'numeric indices' => [['a', 'b', 'c'], ['c', 'b', 'a']],104 'string keys' => [['foo' => 'bar', 'bar' => 'baz'], ['bar' => 'baz', 'foo' => 'bar']],105 'traversable' => [TestArrayIterator::fromArray(['a' => 1, 'b' => 2, 'c' => 3]), ['c' => 3, 'b' => 2, 'a' => 1]],106 ];107 }108 /**109 * @test110 * @dataProvider reverseExamples111 */112 public function reverseWorks($array, $expected)113 {114 $helper = new ArrayHelper();115 $result = $helper->reverse($array);116 self::assertEquals($expected, $result);117 }118 public function keysExamples()119 {120 return [121 'empty array' => [[], []],122 'numeric indices' => [['a', 'b', 'c'], [0, 1, 2]],123 'string keys' => [['foo' => 'bar', 'bar' => 'baz'], ['foo', 'bar']],124 'traversable' => [TestArrayIterator::fromArray(['foo' => 'bar', 'bar' => 'baz']), ['foo', 'bar']],125 ];126 }127 /**128 * @test129 * @dataProvider keysExamples130 */131 public function keysWorks($array, $expected)132 {133 $helper = new ArrayHelper();134 $result = $helper->keys($array);135 self::assertEquals($expected, $result);136 }137 public function lengthExamples()138 {139 return [140 'empty array' => [[], 0],141 'array with values' => [['a', 'b', 'c'], 3],142 'traversable' => [TestArrayIterator::fromArray(['a', 'b', 'c']), 3],143 ];144 }145 /**146 * @test147 * @dataProvider lengthExamples148 */149 public function lengthWorks($array, $expected)150 {151 $helper = new ArrayHelper();152 $result = $helper->length($array);153 self::assertEquals($expected, $result);154 }155 public function indexOfExamples()156 {157 return [158 'empty array' => [[], 42, null, -1],159 'array with values' => [['a', 'b', 'c', 'b'], 'b', null, 1],160 'with offset' => [['a', 'b', 'c', 'b'], 'b', 2, 3],161 'associative' => [['a' => 'el1', 'b' => 'el2'], 'el2', null, 1],162 'associative with offset' => [['a' => 'el1', 'b' => 'el2'], 'el2', 1, 1],163 'traversable' => [TestArrayIterator::fromArray(['a', 'b', 'c', 'b']), 'b', null, 1] ];164 }165 /**166 * @test167 * @dataProvider indexOfExamples168 */169 public function indexOfWorks($array, $searchElement, $fromIndex, $expected)170 {171 $helper = new ArrayHelper();172 if ($fromIndex !== null) {173 $result = $helper->indexOf($array, $searchElement, $fromIndex);174 } else {175 $result = $helper->indexOf($array, $searchElement);176 }177 self::assertEquals($expected, $result);178 }179 public function isEmptyExamples()180 {181 return [182 'empty array' => [[], true],183 'array with values' => [['a', 'b', 'c'], false],184 'traversable' => [TestArrayIterator::fromArray(['a', 'b', 'c']), false],185 ];186 }187 /**188 * @test189 * @dataProvider isEmptyExamples190 */191 public function isEmptyWorks($array, $expected)192 {193 $helper = new ArrayHelper();194 $result = $helper->isEmpty($array);195 self::assertEquals($expected, $result);196 }197 public function firstExamples()198 {199 return [200 'empty array' => [[], false],201 'numeric indices' => [['a', 'b', 'c'], 'a'],202 'string keys' => [['foo' => 'bar', 'bar' => 'baz'], 'bar'],203 'traversable' => [TestArrayIterator::fromArray(['foo' => 'bar', 'bar' => 'baz']), 'bar'],204 'empty traversable' => [TestArrayIterator::fromArray([]), false],205 ];206 }207 /**208 * @test209 * @dataProvider firstExamples210 */211 public function firstWorks($array, $expected)212 {213 $helper = new ArrayHelper();214 $result = $helper->first($array);215 self::assertEquals($expected, $result);216 }217 public function lastExamples()218 {219 return [220 'empty array' => [[], false],221 'numeric indices' => [['a', 'b', 'c'], 'c'],222 'string keys' => [['foo' => 'bar', 'bar' => 'baz'], 'baz'],223 'traversable' => [TestArrayIterator::fromArray(['foo' => 'bar', 'bar' => 'baz']), 'baz'],224 'empty traversable' => [TestArrayIterator::fromArray([]), false],225 ];226 }227 /**228 * @test229 * @dataProvider lastExamples230 */231 public function lastWorks($array, $expected)232 {233 $helper = new ArrayHelper();234 $result = $helper->last($array);235 self::assertEquals($expected, $result);236 }237 public function randomExamples()238 {239 return [240 'empty array' => [[], false],241 'numeric indices' => [['a', 'b', 'c'], true],242 'string keys' => [['foo' => 'bar', 'bar' => 'baz'], true],243 'traversable' => [TestArrayIterator::fromArray(['foo' => 'bar', 'bar' => 'baz']), true],244 ];245 }246 /**247 * @test248 * @dataProvider randomExamples249 */250 public function randomWorks($array, $expected)251 {252 $helper = new ArrayHelper();253 $result = $helper->random($array);254 if ($array instanceof \Traversable) {255 $array = iterator_to_array($array);256 }257 self::assertEquals($expected, in_array($result, $array));258 }259 public function sortExamples()260 {261 return [262 'empty array' => [[], []],263 'numeric indices' => [['z', '7d', 'i', '7', 'm', 8, 3, 'q'], [3, '7', '7d', 8, 'i', 'm', 'q', 'z']],264 'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz'], ['foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo']],265 'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53], ['k' => 53, 76, '84216', 'bar', 'foo', 'i' => 181.84, 'foo' => 'abc']],266 'traversable' => [TestArrayIterator::fromArray([4, 2, 3, 1]), [1, 2, 3, 4]],267 ];268 }269 /**270 * @test271 * @dataProvider sortExamples272 */273 public function sortWorks($array, $expected)274 {275 $helper = new ArrayHelper();276 $sortedArray = $helper->sort($array);277 self::assertEquals($expected, $sortedArray);278 }279 public function ksortExamples()280 {281 return [282 'no keys' => [['z', '7d', 'i', '7', 'm', 8, 3, 'q'], ['z', '7d', 'i', '7', 'm', 8, 3, 'q']],283 'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz'], ['bar' => 'baz', 'baz' => 'foo', 'foo' => 'bar']],284 'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53], ['0' => 'bar', '24' => 'foo', '25' => '84216', '26' => 76, 'foo' => 'abc', 'i' => 181.84, 'k' => 53]],285 'traversable' => [TestArrayIterator::fromArray(['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz']), ['bar' => 'baz', 'baz' => 'foo', 'foo' => 'bar']],286 ];287 }288 /**289 * @test290 * @dataProvider ksortExamples291 */292 public function ksortWorks($array, $expected)293 {294 $helper = new ArrayHelper();295 $sortedArray = $helper->ksort($array);296 self::assertEquals($expected, $sortedArray);297 }298 public function shuffleExamples()299 {300 return [301 'empty array' => [[]],302 'numeric indices' => [['z', '7d', 'i', '7', 'm', 8, 3, 'q']],303 'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz']],304 'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53]],305 'traversable' => [TestArrayIterator::fromArray([1, 2, 3, 4])],306 ];307 }308 /**309 * @test310 * @dataProvider shuffleExamples311 */312 public function shuffleWorks($array)313 {314 $helper = new ArrayHelper();315 $shuffledArray = $helper->shuffle($array);316 if ($array instanceof \Traversable) {317 $array = iterator_to_array($array);318 }319 self::assertEquals($array, $shuffledArray);320 }321 public function uniqueExamples()322 {323 return [324 'numeric indices' => [325 ['bar', 12, 'two', 'bar', 13, 12, false, 0, null],326 [0 => 'bar', 1 => 12, 2 => 'two', 4 => 13, 6 => false, 7 => 0]327 ],328 'string keys' => [329 ['foo' => 'bar', 'baz' => 'foo', 'foo' => 'bar2', 'bar' => false, 'foonull' => null],330 ['foo' => 'bar2', 'baz' => 'foo', 'bar' => false]331 ],332 'mixed keys' => [333 ['bar', '24' => 'bar', 'i' => 181.84, 'foo' => 'abc', 'foo2' => 'abc', 76],334 [0 => 'bar', 'i' => 181.84, 'foo' => 'abc', 25 => 76]335 ],336 'traversable' => [337 TestArrayIterator::fromArray(['a', 'a', 'b']),338 [0 => 'a', 2 => 'b']339 ],340 ];341 }342 /**343 * @test344 * @dataProvider uniqueExamples345 */346 public function uniqueWorks($array, $expected)347 {348 $helper = new ArrayHelper();349 $uniqueddArray = $helper->unique($array);350 self::assertEquals($expected, $uniqueddArray);351 }352 public function popExamples()353 {354 return [355 'empty array' => [[], []],356 'numeric indices' => [['z', '7d', 'i', '7'], ['z', '7d', 'i']],357 'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz'], ['foo' => 'bar', 'baz' => 'foo']],358 'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53], ['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76]],359 'traversable' => [TestArrayIterator::fromArray(['z', '7d', 'i', '7']), ['z', '7d', 'i']],360 ];361 }362 /**363 * @test364 * @dataProvider popExamples365 */366 public function popWorks($array, $expected)367 {368 $helper = new ArrayHelper();369 $poppedArray = $helper->pop($array);370 self::assertEquals($expected, $poppedArray);371 }372 public function pushExamples()373 {374 return [375 'empty array' => [[], 42, 'foo', [42, 'foo']],376 'numeric indices' => [['z', '7d', 'i', '7'], 42, 'foo', ['z', '7d', 'i', '7', 42, 'foo']],377 'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz'], 42, 'foo', ['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz', 42, 'foo']],378 'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53], 42, 'foo', ['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53, 42, 'foo']],379 'traversable' => [TestArrayIterator::fromArray(['a']), 'b', 'c', ['a', 'b', 'c']],380 ];381 }382 /**383 * @test384 * @dataProvider pushExamples385 */386 public function pushWorks($array, $element1, $element2, $expected)387 {388 $helper = new ArrayHelper();389 $pushedArray = $helper->push($array, $element1, $element2);390 self::assertEquals($expected, $pushedArray);391 }392 public function shiftExamples()393 {394 return [395 'empty array' => [[], []],396 'numeric indices' => [['z', '7d', 'i', '7'], ['7d', 'i', '7']],397 'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz'], ['baz' => 'foo', 'bar' => 'baz']],398 'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53], ['foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53]],399 'traversable' => [TestArrayIterator::fromArray(['z', '7d', 'i', '7']), ['7d', 'i', '7']],400 ];401 }402 /**403 * @test404 * @dataProvider shiftExamples405 */406 public function shiftWorks($array, $expected)407 {408 $helper = new ArrayHelper();409 $shiftedArray = $helper->shift($array);410 self::assertEquals($expected, $shiftedArray);411 }412 public function unshiftExamples()413 {414 return [415 'empty array' => [[], 'abc', 42, [42, 'abc']],416 'numeric indices' => [['z', '7d', 'i', '7'], 'abc', 42, [42, 'abc', 'z', '7d', 'i', '7']],417 'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz'], 'abc', 42, [42, 'abc', 'foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz']],418 'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53], 'abc', 42, [42, 'abc', 'bar', 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53]],419 'traversable' => [TestArrayIterator::fromArray(['z', '7d', 'i', '7']), 'a', 42, [42, 'a', 'z', '7d', 'i', '7']],420 ];421 }422 /**423 * @test424 * @dataProvider unshiftExamples425 */426 public function unshiftWorks($array, $element1, $element2, $expected)427 {428 $helper = new ArrayHelper();429 $unshiftedArray = $helper->unshift($array, $element1, $element2);430 self::assertEquals($expected, $unshiftedArray);431 }432 public function spliceExamples()433 {434 return [435 'empty array' => [[], [42, 'abc', 'Neos'], 2, 2, 42, 'abc', 'Neos'],436 'numeric indices' => [['z', '7d', 'i', '7'], ['z', '7d', 42, 'abc', 'Neos'], 2, 2, 42, 'abc', 'Neos'],437 'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz'], ['foo' => 'bar', 'baz' => 'foo', 42, 'abc', 'Neos'], 2, 2, 42, 'abc', 'Neos'],438 'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53], ['bar', 'foo', 42, 'abc', 'Neos', '84216', 76, 'k' => 53], 2, 2, 42, 'abc', 'Neos'],439 'traversable' => [TestArrayIterator::fromArray(['z', '7d', 'i', '7']), ['z', '7d', 42, 'abc', 'Neos'], 2, 2, 42, 'abc', 'Neos'],440 ];441 }442 /**443 * @test444 * @dataProvider spliceExamples445 */446 public function spliceWorks($array, $expected, $offset, $length, $element1, $element2, $element3)447 {448 $helper = new ArrayHelper();449 $splicedArray = $helper->splice($array, $offset, $length, $element1, $element2, $element3);450 self::assertEquals($expected, $splicedArray);451 }452 /**453 * @test454 */455 public function spliceNoReplacements()456 {457 $helper = new ArrayHelper();458 $splicedArray = $helper->splice([0, 1, 2, 3, 4, 5], 2, 2);459 self::assertEquals([0, 1, 4, 5], $splicedArray);460 }461 public function flipExamples()462 {463 return [464 'array with values' => [['a', 'b', 'c'], ['a' => 0, 'b' => 1, 'c' => 2]],465 'array with key and values' => [['foo' => 'bar', 24 => 42, 'i' => 181, 42 => 'Neos'], ['bar' => 'foo', 42 => 24, 181 => 'i', 'Neos' => 42]],466 'traversable' => [TestArrayIterator::fromArray(['a', 'b', 'c']), ['a' => 0, 'b' => 1, 'c' => 2]],467 ];468 }469 /**470 * @test471 * @dataProvider flipExamples472 */473 public function flipWorks($array, $expected)474 {475 $helper = new ArrayHelper();476 $result = $helper->flip($array);477 self::assertEquals($expected, $result);478 }479 public function rangeExamples()480 {481 return [482 'array from one to three' => [483 [1, 3],484 [1, 2, 3]485 ],486 'array from one to seven in steps of two' => [487 [1, 7, 2],488 [1, 3, 5, 7]489 ],490 'array of characters' => [491 ['c', 'g'],492 ['c', 'd', 'e', 'f', 'g']493 ]494 ];495 }496 /**497 * @test498 * @dataProvider rangeExamples499 */500 public function rangeWorks($arguments, $expected)501 {502 $helper = new ArrayHelper();503 $result = $helper->range(...$arguments);504 self::assertEquals($expected, $result);505 }506 public function setExamples()507 {508 return [509 'add key in empty array' => [510 [[], 'foo', 'bar'],511 ['foo' => 'bar']512 ],513 'add key to array' => [514 [['bar' => 'baz'], 'foo', 'bar'],515 ['bar' => 'baz', 'foo' => 'bar']516 ],517 'override value in array' => [518 [['foo' => 'bar'], 'foo', 'baz'],519 ['foo' => 'baz']520 ],521 'traversable' => [522 [TestArrayIterator::fromArray(['bar' => 'baz']), 'foo', 'bar'],523 ['bar' => 'baz', 'foo' => 'bar']524 ],525 ];526 }527 /**528 * @test529 * @dataProvider setExamples530 */531 public function setWorks($arguments, $expected)532 {533 $helper = new ArrayHelper();534 $result = $helper->set(...$arguments);535 self::assertEquals($expected, $result);536 }537 public function mapExamples()538 {539 return [540 'map squares' => [541 [1, 2, 3, 4],542 function ($x) {543 return $x * $x;544 },545 [1, 4, 9, 16],546 ],547 'preserve keys' => [548 ['a' => 1, 'b' => 2],549 function ($x) {550 return $x * 2;551 },552 ['a' => 2, 'b' => 4],553 ],554 'with keys' => [555 [1, 2, 3, 4],556 function ($x, $index) {557 return $x * $index;558 },559 [0, 2, 6, 12],560 ],561 'traversable' => [562 TestArrayIterator::fromArray([1, 2, 3, 4]),563 function ($x) {564 return $x * $x;565 },566 [1, 4, 9, 16],567 ],568 ];569 }570 /**571 * @test572 * @dataProvider mapExamples573 */574 public function mapWorks($array, $callback, $expected)575 {576 $helper = new ArrayHelper();577 $result = $helper->map($array, $callback);578 self::assertSame($expected, $result);579 }580 public function reduceExamples()581 {582 return [583 'sum with initial value' => [584 [1, 2, 3, 4],585 function ($sum, $x) {586 return $sum + $x;587 },588 0,589 10,590 ],591 'sum without initial value' => [592 [1, 2, 3, 4],593 function ($sum, $x) {594 return $sum + $x;595 },596 null,597 10,598 ],599 'sum with empty array and initial value' => [600 [],601 function ($sum, $x) {602 return $sum + $x;603 },604 0,605 0,606 ],607 'sum with empty array and without initial value' => [608 [],609 function ($sum, $x) {610 return $sum + $x;611 },612 null,613 null,614 ],615 'traversable' => [616 TestArrayIterator::fromArray([1, 2, 3, 4]),617 function ($sum, $x) {618 return $sum + $x;619 },620 0,621 10,622 ],623 'traversable without initial value' => [624 TestArrayIterator::fromArray([1, 2, 3, 4]),625 function ($sum, $x) {626 return $sum + $x;627 },628 null,629 10,630 ],631 ];632 }633 /**634 * @test635 * @dataProvider reduceExamples636 */637 public function reduceWorks($array, $callback, $initialValue, $expected)638 {639 $helper = new ArrayHelper();640 $result = $helper->reduce($array, $callback, $initialValue);641 self::assertSame($expected, $result);642 }643 public function filterExamples()644 {645 return [646 'test by value' => [647 range(0, 5),648 function ($x) {649 return $x % 2 === 0;650 },651 [652 0 => 0,653 2 => 2,654 4 => 4,655 ],656 ],657 'test element by index' => [658 ['a', 'b', 'c', 'd'],659 function ($x, $index) {660 return $index % 2 === 0;661 },662 [663 0 => 'a',664 2 => 'c',665 ],666 ],667 'traversable' => [668 TestArrayIterator::fromArray([0, 1, 2, 3, 4, 5]),669 function ($x) {670 return $x % 2 === 0;671 },672 [673 0 => 0,674 2 => 2,675 4 => 4,676 ],677 ],678 ];679 }680 /**681 * @test682 * @dataProvider filterExamples683 */684 public function filterWorks($array, $callback, $expected)685 {686 $helper = new ArrayHelper();687 $result = $helper->filter($array, $callback);688 self::assertSame($expected, $result);689 }690 public function someExamples()691 {692 $isLongWord = function ($x) {693 return strlen($x) >= 8;694 };695 $isFiveApples = function ($x, $key) {696 return $key === 'apple' && $x > 5;697 };698 return [699 'test by value: success' => [700 ['brown', 'elephant', 'dung'],701 $isLongWord,702 true,703 ],704 'test by value: fail' => [705 ['foo', 'bar', 'baz'],706 $isLongWord,707 false,708 ],709 'test by key: success' => [710 ['apple' => 7, 'pear' => 5, 'banana' => 3],711 $isFiveApples,712 true,713 ],714 'test by key: fail' => [715 ['apple' => 3, 'pear' => 5, 'banana' => 7],716 $isFiveApples,717 false,718 ],719 'traversable' => [720 TestArrayIterator::fromArray(['brown', 'elephant', 'dung']),721 $isLongWord,722 true,723 ],724 ];725 }726 /**727 * @test728 * @dataProvider someExamples729 */730 public function someWorks($array, $callback, $expected)731 {732 $helper = new ArrayHelper();733 $result = $helper->some($array, $callback);734 self::assertSame($expected, $result);735 }736 public function everyExamples()737 {738 $isMediumWord = function ($x) {739 return strlen($x) >= 4;740 };741 $isValueEqualIndex = function ($x, $key) {742 return $key === $x;743 };744 return [745 'test by value: success' => [746 ['brown', 'elephant', 'dung'],747 $isMediumWord,748 true,749 ],750 'test by value: fail' => [751 ['foo', 'bar', 'baz'],752 $isMediumWord,753 false,754 ],755 'test by key: success' => [756 [0, 1, 2, 3],757 $isValueEqualIndex,758 true,759 ],760 'test by key: fail' => [761 [0 => 1, 1 => 2, 2 => 3],762 $isValueEqualIndex,763 false,764 ],765 'traversable' => [766 TestArrayIterator::fromArray([0 => 1, 1 => 2, 2 => 3]),767 $isValueEqualIndex,768 false,769 ],770 ];771 }772 /**773 * @test774 * @dataProvider everyExamples775 */776 public function everyWorks($array, $callback, $expected)777 {778 $helper = new ArrayHelper();779 $result = $helper->every($array, $callback);780 self::assertSame($expected, $result);...

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$examples = new Examples();2$examples->fromArray(array('foo' => 'bar'));3$examples = new Examples();4$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));5$examples = new Examples();6$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo', 'foo' => 'baz'));7$examples = new Examples();8$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo', 'foo' => 'baz', 'bar' => 'baz'));

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$examples = new Examples();2$examples->fromArray(array(3));4$examples = new Examples();5$examples->fromArray(array(6 array(7 array(8 array(9));10$examples = new Examples();11$examples->fromArray(array(12 array(13 array(14 array(15));16$examples = new Examples();17$examples->fromArray(array(18));

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$examples = new Examples();2$examples->fromArray(array('one', 'two', 'three'));3print_r($examples->toArray());4$examples = new Examples();5$examples->fromArray(array('one', 'two', 'three'));6print_r($examples->toArray());7$examples = new Examples();8$examples->fromArray(array('one', 'two', 'three'));9print_r($examples->toArray());10$examples = new Examples();11$examples->fromArray(array('one', 'two', 'three'));12print_r($examples->toArray());13$examples = new Examples();14$examples->fromArray(array('one', 'two', 'three'));15print_r($examples->toArray());16$examples = new Examples();17$examples->fromArray(array('one', 'two', 'three'));18print_r($examples->toArray());19$examples = new Examples();20$examples->fromArray(array('one', 'two', 'three'));21print_r($examples->toArray());

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$examples = new Examples();2$examples->fromArray(array(3));4print_r($examples);5$examples = new Examples();6$examples->example1 = 'value1';7$examples->example2 = 'value2';8$examples->example3 = 'value3';9print_r($examples->toArray());10$examples = new Examples();11$examples->fromArray(array(12 new Example('value1'),13 new Example('value2'),14 new Example('value3')15));16print_r($examples);17$examples = new Examples();18$examples[] = new Example('value1');19$examples[] = new Example('value2');20$examples[] = new Example('value3');21print_r($examples->toArray());

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$examples = new Examples();2$examples->fromArray(array('name' => 'John', 'surname' => 'Doe'));3echo $examples->name . ' ' . $examples->surname;4$examples = new Examples();5$examples->fromArray(array('name' => 'John', 'surname' => 'Doe', 'age' => 25));6echo $examples->name . ' ' . $examples->surname . ' ' . $examples->age;7PHP extract() Function8PHP array_key_exists() Function9PHP array_push() Function10PHP array_pop() Function11PHP array_shift() Function12PHP array_unshift() Function13PHP array_keys() Function14PHP array_values() Function15PHP array_merge() Function16PHP array_unique() Function17PHP array_search() Function18PHP array_reverse() Function19PHP array_slice() Function20PHP array_splice() Function21PHP array_filter() Function22PHP array_map() Function23PHP array_walk() Function24PHP array_rand() Function25PHP array_sum() Function26PHP array_product() Function27PHP array_diff() Function28PHP array_intersect() Function

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1require_once 'Examples.php';2$examples = new Examples();3$examples->fromArray(array('a', 'b', 'c'));4print_r($examples->getArray());5require_once 'Examples.php';6$examples = new Examples();7$examples->fromArray(array('a', 'b', 'c'));8print_r($examples->getArray());9require_once 'Examples.php';10$examples = new Examples();11$examples->fromArray(array('a', 'b', 'c'));12print_r($examples->getArray());13require_once 'Examples.php';14$examples = new Examples();15$examples->fromArray(array('a', 'b', 'c'));16print_r($examples->getArray());17require_once 'Examples.php';18$examples = new Examples();19$examples->fromArray(array('a', 'b', 'c'));20print_r($examples->getArray());21require_once 'Examples.php';22$examples = new Examples();23$examples->fromArray(array('a', 'b', 'c'));24print_r($examples->getArray());25require_once 'Examples.php';26$examples = new Examples();27$examples->fromArray(array('a', 'b', 'c'));28print_r($examples->getArray());29require_once 'Examples.php';30$examples = new Examples();31$examples->fromArray(array('a', 'b', 'c'));32print_r($examples->getArray());33require_once 'Examples.php';34$examples = new Examples();35$examples->fromArray(array('a', 'b', 'c'));36print_r($examples->getArray());37require_once 'Examples.php';38$examples = new Examples();39$examples->fromArray(array('a',

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1include('Examples.php');2$examples = new Examples();3$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));4include('Examples.php');5$examples = new Examples();6$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));7include('Examples.php');8$examples = new Examples();9$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));10include('Examples.php');11$examples = new Examples();12$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));13include('Examples.php');14$examples = new Examples();15$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));16include('Examples.php');17$examples = new Examples();18$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));19include('Examples.php');20$examples = new Examples();21$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));22include('Examples.php');23$examples = new Examples();24$examples->fromArray(array('foo' => 'bar', 'bar' => 'foo'));25include('Examples.php');26$examples = new Examples();27$examples->fromArray(array('foo' =>

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$example = new Examples();2$example->fromArray(array('name' => 'John',3 'height' => 170));4echo $example->name;5echo $example->age;6echo $example->height;7$example = new Examples();8$example->fromArray(array('name' => 'John',9 'height' => 170));10echo $example->name;11echo $example->age;12echo $example->height;13$example = new Examples();14$example->fromArray(array('name' => 'John',15 'height' => 170));16echo $example->name;17echo $example->age;18echo $example->height;19$example = new Examples();20$example->fromArray(array('name' => 'John',21 'height' => 170));22echo $example->name;23echo $example->age;24echo $example->height;25$example = new Examples();26$example->fromArray(array('name' => 'John',27 'height' => 170));28echo $example->name;29echo $example->age;30echo $example->height;31$example = new Examples();32$example->fromArray(array('name' => 'John',33 'height' => 170));34echo $example->name;35echo $example->age;36echo $example->height;

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.

Trigger fromArray code on LambdaTest Cloud Grid

Execute automation tests with fromArray 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