Best Atoum code snippet using controller.getIterator
FinderTest.php
Source:FinderTest.php
...18 public function testDirectories()19 {20 $finder = $this->buildFinder();21 $this->assertSame($finder, $finder->directories());22 $this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator());23 $finder = $this->buildFinder();24 $finder->directories();25 $finder->files();26 $finder->directories();27 $this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator());28 }29 public function testFiles()30 {31 $finder = $this->buildFinder();32 $this->assertSame($finder, $finder->files());33 $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'TestController.phproller.php', 'testController.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());34 $finder = $this->buildFinder();35 $finder->files();36 $finder->directories();37 $finder->files();38 $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'testControllerController.php', 'testController.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());39 }40 public function testRemoveTrailingSlash()41 {42 $finder = $this->buildFinder();43 $expected = $this->toAbsolute(array('foo/bar.tmp', 'TestController.phproller.php', 'testController.py', 'foo bar'));44 $in = self::$tmpDir.'//';45 $this->assertIterator($expected, $finder->in($in)->files()->getIterator());46 }47 public function testSymlinksNotResolved()48 {49 if ('\\' === DIRECTORY_SEPARATOR) {50 $this->markTestSkipped('symlinks are not supported on Windows');51 }52 $finder = $this->buildFinder();53 symlink($this->toAbsolute('foo'), $this->toAbsolute('baz'));54 $expected = $this->toAbsolute(array('baz/bar.tmp'));55 $in = self::$tmpDir.'/baz/';56 try {57 $this->assertIterator($expected, $finder->in($in)->files()->getIterator());58 unlink($this->toAbsolute('baz'));59 } catch (\Exception $e) {60 unlink($this->toAbsolute('baz'));61 throw $e;62 }63 }64 public function testBackPathNotNormalized()65 {66 $finder = $this->buildFinder();67 $expected = $this->toAbsolute(array('foo/../foo/bar.tmp'));68 $in = self::$tmpDir.'/foo/../foo/';69 $this->assertIterator($expected, $finder->in($in)->files()->getIterator());70 }71 public function testDepth()72 {73 $finder = $this->buildFinder();74 $this->assertSame($finder, $finder->depth('< 1'));75 $this->assertIterator($this->toAbsolute(array('foo', 'TestController.phproller.php', 'testController.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());76 $finder = $this->buildFinder();77 $this->assertSame($finder, $finder->depth('<= 0'));78 $this->assertIterator($this->toAbsolute(array('foo', 'TestController.phproller.php', 'testController.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());79 $finder = $this->buildFinder();80 $this->assertSame($finder, $finder->depth('>= 1'));81 $this->assertIterator($this->toAbsolute(array('foo/bar.tmp')), $finder->in(self::$tmpDir)->getIterator());82 $finder = $this->buildFinder();83 $finder->depth('< 1')->depth('>= 1');84 $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());85 }86 public function testName()87 {88 $finder = $this->buildFinder();89 $this->assertSame($finder, $finder->name('*.php'));90 $this->assertIterator($this->toAbsolute(array('testControllerController.php')), $finder->in(self::$tmpDir)->getIterator());91 $finder = $this->buildFinder();92 $finder->name('testController.ph*');93 $finder->name('testController.py');94 $this->assertIterator($this->toAbsolute(array('testControllerController.php', 'testController.py')), $finder->in(self::$tmpDir)->getIterator());95 $finder = $this->buildFinder();96 $finder->name('~^testController~i');97 $this->assertIterator($this->toAbsolute(array('TestController.phproller.php', 'testController.py')), $finder->in(self::$tmpDir)->getIterator());98 $finder = $this->buildFinder();99 $finder->name('~\\.php$~i');100 $this->assertIterator($this->toAbsolute(array('testControllerController.php')), $finder->in(self::$tmpDir)->getIterator());101 $finder = $this->buildFinder();102 $finder->name('testController.p{hp,y}');103 $this->assertIterator($this->toAbsolute(array('TestController.phproller.php', 'testController.py')), $finder->in(self::$tmpDir)->getIterator());104 }105 public function testNotName()106 {107 $finder = $this->buildFinder();108 $this->assertSame($finder, $finder->notName('*.php'));109 $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'testController.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());110 $finder = $this->buildFinder();111 $finder->notName('*.php');112 $finder->notName('*.py');113 $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());114 $finder = $this->buildFinder();115 $finder->name('testController.ph*');116 $finder->name('testController.py');117 $finder->notName('*.php');118 $finder->notName('*.py');119 $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());120 $finder = $this->buildFinder();121 $finder->name('testController.ph*');122 $finder->name('testController.py');123 $finder->notName('*.p{hp,y}');124 $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());125 }126 /**127 * @dataProvider getRegexNameTestData128 */129 public function testRegexName($regex)130 {131 $finder = $this->buildFinder();132 $finder->name($regex);133 $this->assertIterator($this->toAbsolute(array('testController.py', 'TestController.phproller.php')), $finder->in(self::$tmpDir)->getIterator());134 }135 public function testSize()136 {137 $finder = $this->buildFinder();138 $this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500'));139 $this->assertIterator($this->toAbsolute(array('TestController.phproller.php')), $finder->in(self::$tmpDir)->getIterator());140 }141 public function testDate()142 {143 $finder = $this->buildFinder();144 $this->assertSame($finder, $finder->files()->date('until last month'));145 $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'testControllerController.php')), $finder->in(self::$tmpDir)->getIterator());146 }147 public function testExclude()148 {149 $finder = $this->buildFinder();150 $this->assertSame($finder, $finder->exclude('foo'));151 $this->assertIterator($this->toAbsolute(array('testControllerController.php', 'testController.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());152 }153 public function testIgnoreVCS()154 {155 $finder = $this->buildFinder();156 $this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));157 $this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'testControllerController.php', 'testController.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());158 $finder = $this->buildFinder();159 $finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);160 $this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'TestController.phproller.php', 'testController.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());161 $finder = $this->buildFinder();162 $this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));163 $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'testControllerController.php', 'testController.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());164 }165 public function testIgnoreDotFiles()166 {167 $finder = $this->buildFinder();168 $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));169 $this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'TestController.phproller.php', 'testController.py', 'toto', 'toto/.git', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());170 $finder = $this->buildFinder();171 $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);172 $this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'testControllerController.php', 'testController.py', 'toto', 'toto/.git', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());173 $finder = $this->buildFinder();174 $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));175 $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'TestController.phproller.php', 'testController.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());176 }177 public function testSortByName()178 {179 $finder = $this->buildFinder();180 $this->assertSame($finder, $finder->sortByName());181 $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'testControllerController.php', 'testController.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());182 }183 public function testSortByType()184 {185 $finder = $this->buildFinder();186 $this->assertSame($finder, $finder->sortByType());187 $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'toto', 'foo/bar.tmp', 'testControllerController.php', 'testController.py')), $finder->in(self::$tmpDir)->getIterator());188 }189 public function testSortByAccessedTime()190 {191 $finder = $this->buildFinder();192 $this->assertSame($finder, $finder->sortByAccessedTime());193 $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'testControllerController.php', 'toto', 'testController.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());194 }195 public function testSortByChangedTime()196 {197 $finder = $this->buildFinder();198 $this->assertSame($finder, $finder->sortByChangedTime());199 $this->assertIterator($this->toAbsolute(array('toto', 'testController.py', 'TestController.phproller.php', 'foo/bar.tmp', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());200 }201 public function testSortByModifiedTime()202 {203 $finder = $this->buildFinder();204 $this->assertSame($finder, $finder->sortByModifiedTime());205 $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'TestController.phproller.php', 'toto', 'testController.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());206 }207 public function testSort()208 {209 $finder = $this->buildFinder();210 $this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));211 $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'testControllerController.php', 'testController.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());212 }213 public function testFilter()214 {215 $finder = $this->buildFinder();216 $this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'testController'); }));217 $this->assertIterator($this->toAbsolute(array('TestController.phproller.php', 'testController.py')), $finder->in(self::$tmpDir)->getIterator());218 }219 public function testFollowLinks()220 {221 if ('\\' == DIRECTORY_SEPARATOR) {222 $this->markTestSkipped('symlinks are not supported on Windows');223 }224 $finder = $this->buildFinder();225 $this->assertSame($finder, $finder->followLinks());226 $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'TestController.phproller.php', 'testController.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());227 }228 public function testIn()229 {230 $finder = $this->buildFinder();231 $iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator();232 $expected = array(233 self::$tmpDir.DIRECTORY_SEPARATOR.'TestController.phproller.php',234 __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php',235 __DIR__.DIRECTORY_SEPARATOR.'GlobTest.php',236 );237 $this->assertIterator($expected, $iterator);238 }239 /**240 * @expectedException \InvalidArgumentException241 */242 public function testInWithNonExistentDirectory()243 {244 $finder = new Finder();245 $finder->in('foobar');246 }247 public function testInWithGlob()248 {249 $finder = $this->buildFinder();250 $finder->in(array(__DIR__.'/Fixtures/*/B/C/', __DIR__.'/Fixtures/*/*/B/C/'))->getIterator();251 $this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);252 }253 /**254 * @expectedException \InvalidArgumentException255 */256 public function testInWithNonDirectoryGlob()257 {258 $finder = new Finder();259 $finder->in(__DIR__.'/Fixtures/A/a*');260 }261 public function testInWithGlobBrace()262 {263 $finder = $this->buildFinder();264 $finder->in(array(__DIR__.'/Fixtures/{A,copy/A}/B/C'))->getIterator();265 $this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);266 }267 /**268 * @expectedException \LogicException269 */270 public function testGetIteratorWithoutIn()271 {272 $finder = Finder::create();273 $finder->getIterator();274 }275 public function testGetIterator()276 {277 $finder = $this->buildFinder();278 $dirs = array();279 foreach ($finder->directories()->in(self::$tmpDir) as $dir) {280 $dirs[] = (string) $dir;281 }282 $expected = $this->toAbsolute(array('foo', 'toto'));283 sort($dirs);284 sort($expected);285 $this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface');286 $finder = $this->buildFinder();287 $this->assertEquals(2, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface');288 $finder = $this->buildFinder();289 $a = iterator_to_array($finder->directories()->in(self::$tmpDir));290 $a = array_values(array_map('strval', $a));291 sort($a);292 $this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface');293 }294 public function testRelativePath()295 {296 $finder = $this->buildFinder()->in(self::$tmpDir);297 $paths = array();298 foreach ($finder as $file) {299 $paths[] = $file->getRelativePath();300 }301 $ref = array('', '', '', '', 'foo', '');302 sort($ref);303 sort($paths);304 $this->assertEquals($ref, $paths);305 }306 public function testRelativePathname()307 {308 $finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();309 $paths = array();310 foreach ($finder as $file) {311 $paths[] = $file->getRelativePathname();312 }313 $ref = array('TestController.phproller.php', 'toto', 'testController.py', 'foo', 'foo'.DIRECTORY_SEPARATOR.'bar.tmp', 'foo bar');314 sort($paths);315 sort($ref);316 $this->assertEquals($ref, $paths);317 }318 public function testAppendWithAFinder()319 {320 $finder = $this->buildFinder();321 $finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');322 $finder1 = $this->buildFinder();323 $finder1->directories()->in(self::$tmpDir);324 $finder = $finder->append($finder1);325 $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());326 }327 public function testAppendWithAnArray()328 {329 $finder = $this->buildFinder();330 $finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');331 $finder->append($this->toAbsolute(array('foo', 'toto')));332 $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());333 }334 public function testAppendReturnsAFinder()335 {336 $this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', Finder::create()->append(array()));337 }338 public function testAppendDoesNotRequireIn()339 {340 $finder = $this->buildFinder();341 $finder->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');342 $finder1 = Finder::create()->append($finder);343 $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());344 }345 public function testCountDirectories()346 {347 $directory = Finder::create()->directories()->in(self::$tmpDir);348 $i = 0;349 foreach ($directory as $dir) {350 ++$i;351 }352 $this->assertCount($i, $directory);353 }354 public function testCountFiles()355 {356 $files = Finder::create()->files()->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures');357 $i = 0;358 foreach ($files as $file) {359 ++$i;360 }361 $this->assertCount($i, $files);362 }363 /**364 * @expectedException \LogicException365 */366 public function testCountWithoutIn()367 {368 $finder = Finder::create()->files();369 count($finder);370 }371 public function testHasResults()372 {373 $finder = $this->buildFinder();374 $finder->in(__DIR__);375 $this->assertTrue($finder->hasResults());376 }377 public function testNoResults()378 {379 $finder = $this->buildFinder();380 $finder->in(__DIR__)->name('DoesNotExist');381 $this->assertFalse($finder->hasResults());382 }383 /**384 * @dataProvider getContainsTestData385 */386 public function testContains($matchPatterns, $noMatchPatterns, $expected)387 {388 $finder = $this->buildFinder();389 $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures')390 ->name('*.txt')->sortByName()391 ->contains($matchPatterns)392 ->notContains($noMatchPatterns);393 $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);394 }395 public function testContainsOnDirectory()396 {397 $finder = $this->buildFinder();398 $finder->in(__DIR__)399 ->directories()400 ->name('Fixtures')401 ->contains('abc');402 $this->assertIterator(array(), $finder);403 }404 public function testNotContainsOnDirectory()405 {406 $finder = $this->buildFinder();407 $finder->in(__DIR__)408 ->directories()409 ->name('Fixtures')410 ->notContains('abc');411 $this->assertIterator(array(), $finder);412 }413 /**414 * Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator415 * with inner FilesystemIterator in an invalid state.416 *417 * @see https://bugs.php.net/68557418 */419 public function testMultipleLocations()420 {421 $locations = array(422 self::$tmpDir.'/',423 self::$tmpDir.'/toto/',424 );425 // it is expected that there are testController.py TestController.phproller.php in the tmpDir426 $finder = new Finder();427 $finder->in($locations)428 // the default flag IGNORE_DOT_FILES fixes the problem indirectly429 // so we set it to false for better isolation430 ->ignoreDotFiles(false)431 ->depth('< 1')->name('testControllerController.php');432 $this->assertCount(1, $finder);433 }434 /**435 * Searching in multiple locations with sub directories involves436 * AppendIterator which does an unnecessary rewind which leaves437 * FilterIterator with inner FilesystemIterator in an invalid state.438 *439 * @see https://bugs.php.net/68557440 */441 public function testMultipleLocationsWithSubDirectories()442 {443 $locations = array(444 __DIR__.'/Fixtures/one',445 self::$tmpDir.DIRECTORY_SEPARATOR.'toto',446 );447 $finder = $this->buildFinder();448 $finder->in($locations)->depth('< 10')->name('*.neon');449 $expected = array(450 __DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',451 __DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',452 );453 $this->assertIterator($expected, $finder);454 $this->assertIteratorInForeach($expected, $finder);455 }456 /**457 * Iterator keys must be the file pathname.458 */459 public function testIteratorKeys()460 {461 $finder = $this->buildFinder()->in(self::$tmpDir);462 foreach ($finder as $key => $file) {463 $this->assertEquals($file->getPathname(), $key);464 }465 }466 public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag()467 {468 $finder = $this->buildFinder();469 $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')470 ->path('/^dir/');471 $expected = array('r+e.gex[c]a(r)s'.DIRECTORY_SEPARATOR.'dir', 'r+e.gex[c]a(r)s'.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'bar.dat');472 $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);473 }474 public function getContainsTestData()475 {476 return array(477 array('', '', array()),478 array('foo', 'bar', array()),479 array('', 'foobar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')),480 array('lorem ipsum dolor sit amet', 'foobar', array('lorem.txt')),481 array('sit', 'bar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')),482 array('dolor sit amet', '@^L@m', array('dolor.txt', 'ipsum.txt')),483 array('/^lorem ipsum dolor sit amet$/m', 'foobar', array('lorem.txt')),484 array('lorem', 'foobar', array('lorem.txt')),485 array('', 'lorem', array('dolor.txt', 'ipsum.txt')),486 array('ipsum dolor sit amet', '/^IPSUM/m', array('lorem.txt')),487 );488 }489 public function getRegexNameTestData()490 {491 return array(492 array('~.+\\.p.+~i'),493 array('~t.*s~i'),494 );495 }496 /**497 * @dataProvider getTestPathData498 */499 public function testPath($matchPatterns, $noMatchPatterns, array $expected)500 {501 $finder = $this->buildFinder();502 $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures')503 ->path($matchPatterns)504 ->notPath($noMatchPatterns);505 $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);506 }507 public function getTestPathData()508 {509 return array(510 array('', '', array()),511 array('/^A\/B\/C/', '/C$/',512 array('A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat'),513 ),514 array('/^A\/B/', 'foobar',515 array(516 'A'.DIRECTORY_SEPARATOR.'B',517 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C',518 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat',519 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat',520 ),521 ),522 array('A/B/C', 'foobar',523 array(524 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C',525 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat',526 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C',527 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat.copy',528 ),529 ),530 array('A/B', 'foobar',531 array(532 //dirs533 'A'.DIRECTORY_SEPARATOR.'B',534 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C',535 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B',536 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C',537 //files538 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat',539 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat',540 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat.copy',541 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat.copy',542 ),543 ),544 array('/^with space\//', 'foobar',545 array(546 'with space'.DIRECTORY_SEPARATOR.'foo.txt',547 ),548 ),549 );550 }551 public function testAccessDeniedException()552 {553 if ('\\' === DIRECTORY_SEPARATOR) {554 $this->markTestSkipped('chmod is not supported on Windows');555 }556 $finder = $this->buildFinder();557 $finder->files()->in(self::$tmpDir);558 // make 'foo' directory non-readable559 $testDir = self::$tmpDir.DIRECTORY_SEPARATOR.'foo';560 chmod($testDir, 0333);561 if (false === $couldRead = is_readable($testDir)) {562 try {563 $this->assertIterator($this->toAbsolute(array('foo bar', 'TestController.phproller.php', 'testController.py')), $finder->getIterator());564 $this->fail('Finder should throw an exception when opening a non-readable directory.');565 } catch (\Exception $e) {566 $expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';567 if ($e instanceof \PHPUnit_Framework_ExpectationFailedException) {568 $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));569 }570 if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {571 $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, '\PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));572 }573 $this->assertInstanceOf($expectedExceptionClass, $e);574 }575 }576 // restore original permissions577 chmod($testDir, 0777);578 clearstatcache($testDir);579 if ($couldRead) {580 $this->markTestSkipped('could read testController files while testController requires unreadable');581 }582 }583 public function testIgnoredAccessDeniedException()584 {585 if ('\\' === DIRECTORY_SEPARATOR) {586 $this->markTestSkipped('chmod is not supported on Windows');587 }588 $finder = $this->buildFinder();589 $finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);590 // make 'foo' directory non-readable591 $testDir = self::$tmpDir.DIRECTORY_SEPARATOR.'foo';592 chmod($testDir, 0333);593 if (false === ($couldRead = is_readable($testDir))) {594 $this->assertIterator($this->toAbsolute(array('foo bar', 'testControllerController.php', 'testController.py')), $finder->getIterator());595 }596 // restore original permissions597 chmod($testDir, 0777);598 clearstatcache($testDir);599 if ($couldRead) {600 $this->markTestSkipped('could read testController files while testController requires unreadable');601 }602 }603 protected function buildFinder()604 {605 return Finder::create();606 }607}...
EntryCollection.php
Source:EntryCollection.php
...11 ->and($this->mockClass('\Spy\Timeline\Spread\Entry\EntryInterface', '\Mock'))12 ->and($entry = new \Mock\EntryInterface())13 ->and($entry->getMockController()->getIdent = 'ident1')14 ->when($collection->add($entry, 'NOTGLOBAL'))15 ->object($collection->getIterator())16 ->isEqualTo(new \ArrayIterator(array(17 'NOTGLOBAL' => array(18 'ident1' => $entry,19 ),20 'GLOBAL' => array(21 'ident1' => $entry,22 )23 )))24 // send with global context25 ->and($entry2 = new \Mock\EntryInterface())26 ->and($entry2->getMockController()->getIdent = 'ident2')27 ->when($collection->add($entry2, 'GLOBAL'))28 ->object($collection->getIterator())29 ->isEqualTo(new \ArrayIterator(array(30 'NOTGLOBAL' => array(31 'ident1' => $entry,32 ),33 'GLOBAL' => array(34 'ident1' => $entry,35 'ident2' => $entry2,36 )37 )))38 // not duplicate on global.39 ->and($collection->setDuplicateOnGlobal(false))40 ->and($entry3 = new \Mock\EntryInterface())41 ->and($entry3->getMockController()->getIdent = 'ident3')42 ->when($collection->add($entry3, 'OTHERCONTEXT'))43 ->object($collection->getIterator())44 ->isEqualTo(new \ArrayIterator(array(45 'OTHERCONTEXT' => array(46 'ident3' => $entry3,47 ),48 'NOTGLOBAL' => array(49 'ident1' => $entry,50 ),51 'GLOBAL' => array(52 'ident1' => $entry,53 'ident2' => $entry2,54 )55 )))56 ;57 }58 public function testLoadUnawareEntries()59 {60 }61 public function testClear()62 {63 $this->if($collection = new TestedModel())64 ->and($this->mockClass('\Spy\Timeline\Spread\Entry\EntryInterface', '\Mock'))65 ->and($entry = new \Mock\EntryInterface())66 ->and($entry->getMockController()->getIdent = 'ident1')67 ->when($collection->add($entry, 'NOTGLOBAL'))68 ->object($collection->getIterator())69 ->isEqualTo(new \ArrayIterator(array(70 'NOTGLOBAL' => array(71 'ident1' => $entry,72 ),73 'GLOBAL' => array(74 'ident1' => $entry,75 )76 )))77 // send with global context78 ->when($collection->clear())79 ->object($collection->getIterator())80 ->isEqualTo(new \ArrayIterator(array()))81 ;82 }83}...
getIterator
Using AI Code Generation
1$this->load->model('model');2$this->load->library('pagination');3$config = array();4$config["base_url"] = base_url() . "index.php/1";5$total_row = $this->model->record_count();6$config["total_rows"] = $total_row;7$config["per_page"] = 5;8$config['use_page_numbers'] = TRUE;9$config['num_links'] = $total_row;10$config['cur_tag_open'] = ' <a class="current">';11$config['cur_tag_close'] = '</a>';12$config['next_link'] = 'Next';13$config['prev_link'] = 'Previous';14$this->pagination->initialize($config);15if($this->uri->segment(2)){16$page = ($this->uri->segment(2)) ;17}18else{19$page = 1;20}21$data["results"] = $this->model->fetch_data($config["per_page"], $page);22$str_links = $this->pagination->create_links();23$data["links"] = explode(' ',$str_links );24$this->load->view('view', $data);25function fetch_data($limit, $start) {26$this->db->limit($limit, $start);27$query = $this->db->get("table_name");28if ($query->num_rows() > 0) {29foreach ($query->result() as $row) {30$data[] = $row;31}32return $data;33}34return false;35}36foreach($results as $data)37{38echo $data->id;39echo $data->title;40echo $data->description;41}42echo $links;
getIterator
Using AI Code Generation
1$obj = new controller();2$obj->getIterator();3$obj = new controller();4$obj->getIterator();5{6 private static $instance;7 private function __construct()8 {9 }10 public static function getInstance()11 {12 if (!self::$instance)13 {14 self::$instance = new controller();15 }16 return self::$instance;17 }18 public function getIterator()19 {20 echo "I am in getIterator method of controller class";21 }22}23$obj = controller::getInstance();24$obj->getIterator();25$obj = controller::getInstance();26$obj->getIterator();
getIterator
Using AI Code Generation
1$controller = new Controller();2$iterator = $controller->getIterator();3while($iterator->hasNext()){4 $item = $iterator->next();5 echo $item->getName();6}
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 getIterator 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!!