Best Atoum code snippet using autoloader.getClasses
ScannerTest.php
Source:ScannerTest.php
...26 $scanner = new Scanner();27 $definitions = $scanner->parse('<?php class FooBar { }');28 $this->assertCount(1, $definitions);29 $this->assertSame('FooBar', reset($definitions)->getName());30 $this->assertValues(['FooBar'], $scanner->getClasses());31 $this->assertValues(['FooBar'], $scanner->getClasses(TypeDefinition::TYPE_CLASS));32 $this->assertValues([], $scanner->getClasses(TypeDefinition::TYPE_ABSTRACT));33 $this->assertValues([], $scanner->getClasses(TypeDefinition::TYPE_INTERFACE));34 $this->assertValues([], $scanner->getClasses(TypeDefinition::TYPE_TRAIT));35 $this->assertValues([], $scanner->getSubClasses('FooBar'));36 $this->assertValues([], $scanner->getSubClasses('Foo'));37 $this->assertValues($definitions, $scanner->getDefinitions($scanner->getClasses()));38 }39 public function testBasicInheritance(): void40 {41 $scanner = new Scanner();42 $scanner->parse('<?php class FooBar extends Foo { }');43 $scanner->parse('<?php Class Foo { }');44 $this->assertValues(['FooBar', 'Foo'], $scanner->getClasses());45 $this->assertValues(['FooBar'], $scanner->getSubClasses('Foo'));46 $this->assertValues([], $scanner->getSubClasses('FooBar'));47 }48 public function testMissingLink(): void49 {50 $scanner = new Scanner();51 $scanner->parse('<?php class FooIterator extends ArrayIterator { }');52 $this->assertValues(['FooIterator'], $scanner->getSubClasses(\Traversable::class));53 }54 public function testHierarchy(): void55 {56 $scanner = new Scanner();57 $scanner->parse(58 <<<'PHP'59<?php60interface ParentOnlyInterface extends Throwable { }61interface ParentInterface extends Throwable { }62interface ChildInterface extends ParentInterface { }63trait ParentOnlyTrait { }64trait ParentTrait { }65trait ChildTrait { use ParentTrait; }66abstract class ParentException extends Exception implements ParentOnlyInterface { use ParentOnlyTrait; }67class ChildException extends ParentException implements ChildInterface { use ChildTrait; } 68PHP69);70 $definitionTypes = [71 'ParentOnlyInterface' => TypeDefinition::TYPE_INTERFACE,72 'ParentInterface' => TypeDefinition::TYPE_INTERFACE,73 'ChildInterface' => TypeDefinition::TYPE_INTERFACE,74 'ParentOnlyTrait' => TypeDefinition::TYPE_TRAIT,75 'ParentTrait' => TypeDefinition::TYPE_TRAIT,76 'ChildTrait' => TypeDefinition::TYPE_TRAIT,77 'ParentException' => TypeDefinition::TYPE_ABSTRACT,78 'ChildException' => TypeDefinition::TYPE_CLASS,79 ];80 $classes = $scanner->getClasses();81 $this->assertValues(array_keys($definitionTypes), $classes);82 $definitions = $scanner->getDefinitions($classes);83 $this->assertCount(\count($definitionTypes), $definitions);84 foreach ($definitions as $definition) {85 $name = $definition->getName();86 $this->assertArrayHasKey($name, $definitionTypes);87 $this->assertSame($definitionTypes[$name], $definition->getType());88 unset($definitionTypes[$name]);89 }90 $this->assertCount(0, $definitionTypes);91 $definitions = $scanner->getDefinitions(['ChildException']);92 $type = current($definitions);93 $this->assertCount(1, $definitions);94 $this->assertInstanceOf(TypeDefinition::class, $type);95 $this->assertSame('ParentException', $type->getParentName());96 $this->assertValues(['ChildInterface'], $type->getInterfaceNames());97 $this->assertValues(['ChildTrait'], $type->getTraitNames());98 $this->assertValues(['ParentException', 'ChildInterface', 'ChildTrait'], $type->getAllNames());99 $this->assertValues(['ChildException'], $scanner->getClasses(TypeDefinition::TYPE_CLASS));100 $this->assertValues(['ParentException'], $scanner->getClasses(TypeDefinition::TYPE_ABSTRACT));101 $this->assertValues(102 ['ParentOnlyInterface', 'ParentInterface', 'ChildInterface'],103 $scanner->getClasses(TypeDefinition::TYPE_INTERFACE)104 );105 $this->assertValues(106 ['ParentOnlyTrait', 'ParentTrait', 'ChildTrait'],107 $scanner->getClasses(TypeDefinition::TYPE_TRAIT)108 );109 $this->assertValues(['ChildException'], $scanner->getSubClasses('ParentOnlyInterface'));110 $this->assertValues(['ChildException'], $scanner->getSubClasses('ParentInterface'));111 $this->assertValues(['ChildException'], $scanner->getSubClasses('ChildInterface'));112 $this->assertValues(['ChildException'], $scanner->getSubClasses('ParentOnlyTrait'));113 $this->assertValues(['ChildException'], $scanner->getSubClasses('ParentTrait'));114 $this->assertValues(['ChildException'], $scanner->getSubClasses('ChildTrait'));115 $this->assertValues(['ChildException'], $scanner->getSubClasses('ParentException'));116 $this->assertValues(117 ['ParentException', 'ChildException'],118 $scanner->getSubClasses('ParentOnlyInterface', TypeDefinition::TYPE_ANY)119 );120 $this->assertValues(121 ['ChildInterface', 'ChildException'],122 $scanner->getSubClasses('ParentInterface', TypeDefinition::TYPE_ANY)123 );124 $this->assertValues(125 ['ChildException'],126 $scanner->getSubClasses('ChildInterface', TypeDefinition::TYPE_ANY)127 );128 $this->assertValues(129 ['ParentException', 'ChildException'],130 $scanner->getSubClasses('ParentOnlyTrait', TypeDefinition::TYPE_ANY)131 );132 $this->assertValues(133 ['ChildTrait', 'ChildException'],134 $scanner->getSubClasses('ParentTrait', TypeDefinition::TYPE_ANY)135 );136 $this->assertValues(137 ['ChildException'],138 $scanner->getSubClasses('ChildTrait', TypeDefinition::TYPE_ANY)139 );140 $this->assertValues(141 ['ChildException'],142 $scanner->getSubClasses('ParentException', TypeDefinition::TYPE_ANY)143 );144 }145 public function testComplexParsing(): void146 {147 $scanner = new Scanner();148 $scanner->parse(149 <<<'PHP'150<?php151namespace Foo;152class FooClass { }153namespace Bar;154use Foo\FooClass as ClassFromFoo;155use Foo\{FooClass as Foos};156if (true) { class BarClass extends ClassFromFoo { }}157if (true) { class BarBarClass extends Foos { }}158class FooBarClass extends \Foo\FooClass { }159PHP160);161 $this->assertValues(162 ['Bar\BarClass', 'Bar\BarBarClass', 'Bar\FooBarClass'],163 $scanner->getSubClasses('Foo\FooClass')164 );165 }166 public function testNoAnonymousClasses(): void167 {168 $scanner = new Scanner();169 $scanner->parse('<?php class Foo extends Exception { } $bar = new class extends Exception { };');170 $this->assertValues(['Foo'], $scanner->getSubClasses('Exception'));171 }172 public function testReflectionLoading(): void173 {174 require_once TEST_FILES_DIRECTORY . '/../helpers/SampleException.php';175 require_once TEST_FILES_DIRECTORY . '/../helpers/SampleTrait.php';176 $scanner = new Scanner();177 $scanner->parse('<?php class Foo extends ' . SampleException::class . ' { } ');178 $this->assertValues(['Foo'], $scanner->getSubClasses(\Exception::class));179 $this->assertValues(['Foo'], $scanner->getSubClasses(SampleTrait::class));180 }181 public function testParsingFilePath(): void182 {183 $scanner = new Scanner();184 $scanner->scanFile(TEST_FILES_DIRECTORY . '/TopClass.php');185 $this->assertSame([TopClass::class], $scanner->getClasses());186 $this->assertSame(187 TEST_FILES_DIRECTORY . '/TopClass.php',188 current($scanner->getDefinitions([TopClass::class]))->getFilename()189 );190 }191 public function testParsingDirectory(): void192 {193 $scanner = new Scanner();194 $scanner->scanDirectory(TEST_FILES_DIRECTORY);195 $this->assertValues([TopClass::class, SecondTopClass::class], $scanner->getClasses());196 }197 public function testScanningFilePaths(): void198 {199 $scanner = new Scanner();200 $scanner->scan([201 TEST_FILES_DIRECTORY . '/TopClass.php',202 new \SplFileInfo(TEST_FILES_DIRECTORY . '/sub/SubClass.php'),203 ]);204 $paths = array_map(function (TypeDefinition $type): string {205 return $type->getFilename();206 }, $scanner->getDefinitions($scanner->getClasses()));207 $this->assertValues([TopClass::class, SubClass::class], $scanner->getClasses());208 $this->assertValues([209 TEST_FILES_DIRECTORY . '/TopClass.php',210 TEST_FILES_DIRECTORY . '/sub/SubClass.php',211 ], $paths);212 }213 public function testFileNotFoundError(): void214 {215 $scanner = new Scanner();216 $this->expectException(FileNotFoundException::class);217 $scanner->scanFile(TEST_FILES_DIRECTORY . '/PathToUndefinedFile');218 }219 public function testMissingLinkFile(): void220 {221 $temp = tempnam(sys_get_temp_dir(), 'test');222 unlink($temp);223 symlink(TEST_FILES_DIRECTORY . '/PathToUndefinedFile', $temp);224 try {225 $scanner = new Scanner();226 $scanner->scanFile($temp);227 $this->assertValues([], $scanner->getClasses());228 } finally {229 unlink($temp);230 }231 }232 public function testAutoloadingSuccess(): void233 {234 $class = $this->generateDynamicClass('SuccessTest');235 $autoloader = new ClassLoader($class, "class $class { }");236 spl_autoload_register([$autoloader, 'autoload']);237 try {238 $scanner = new Scanner();239 $scanner->parse("<?php class Foo Extends $class { }");240 $scanner->allowAutoloading();241 $this->assertValues(['Foo'], $scanner->getSubClasses($class));242 } finally {243 spl_autoload_unregister([$autoloader, 'autoload']);244 }245 }246 public function testAutoloadingFailure(): void247 {248 $class = $this->generateDynamicClass('FailureTest');249 $autoloader = $this->getMockBuilder(ClassLoader::class)250 ->disableOriginalConstructor()251 ->getMock();252 $autoloader->expects($this->never())->method('autoload');253 spl_autoload_register([$autoloader, 'autoload']);254 $result = null;255 try {256 $scanner = new Scanner();257 $scanner->parse("<?php class Foo Extends $class { }");258 $scanner->getSubClasses($class);259 } catch (ClassScannerException $exception) {260 $result = $exception;261 } finally {262 spl_autoload_unregister([$autoloader, 'autoload']);263 }264 $this->assertInstanceOf(UndefinedClassException::class, $result);265 }266 public function testIgnoreMissingClasses(): void267 {268 $class = $this->generateDynamicClass('MissingTest');269 $scanner = new Scanner();270 $scanner->parse("<?php class Foo Extends $class { }");271 $scanner->ignoreMissing();272 $this->assertValues(['Foo'], $scanner->getSubClasses($class));273 }274 public function testParsingErrorInString(): void275 {276 $scanner = new Scanner();277 $this->expectException(ParsingException::class);278 $this->expectExceptionMessage('Error parsing:');279 $scanner->parse('<?php class foo {');280 }281 public function testParsingErrorInFile(): void282 {283 $scanner = new Scanner();284 $file = tempnam(sys_get_temp_dir(), 'test');285 file_put_contents($file, '<?php class foo {');286 $this->expectException(ParsingException::class);287 $this->expectExceptionMessage("Error parsing '$file':");288 try {289 $scanner->scanFile($file);290 } finally {291 unlink($file);292 }293 }294 public function testSkipSameActualFile()295 {296 $scanner = new Scanner();297 try {298 $file = tempnam(sys_get_temp_dir(), 'test');299 $link = tempnam(sys_get_temp_dir(), 'test');300 unlink($link);301 file_put_contents($file, '<?php class Foo { }');302 symlink($file, $link);303 $scanner->scanFile($file);304 $scanner->scanFile($link);305 $this->assertCount(1, $scanner->getDefinitions($scanner->getClasses()));306 } finally {307 if (isset($file) && file_exists($file)) {308 unlink($file);309 }310 if (isset($link) && file_exists($link)) {311 unlink($link);312 }313 }314 }315 private function generateDynamicClass($prefix): string316 {317 $iteration = 0;318 do {319 $name = sprintf('DynamicClass_%s_%s', $prefix, $iteration++);...
ClassFinderTest.php
Source:ClassFinderTest.php
...41 * @throws Exception42 */43 public function testSelf()44 {45 $classes = $this->classFinder->getClasses('Cruxinator\\ClassFinder\\');46 $this->assertEquals(6, count($classes));47 $this->assertTrue(in_array(ClassFinder::class, $classes));48 $this->assertTrue(in_array(TestCase::class, $classes));49 }50 /**51 * @throws Exception52 */53 public function testFindPsr()54 {55 $classes = $this->classFinder->getClasses('Psr\\Log\\');56 $this->assertTrue(count($classes) > 0);57 foreach ($classes as $class) {58 $this->assertTrue(class_exists($class));59 $this->assertStringStartsWith('Psr\\Log\\', $class);60 }61 $twoClasses = $this->classFinder->getClasses('Psr\\Log\\');62 $this->assertEquals(count($classes), count($twoClasses));63 }64 /**65 * @throws Exception66 */67 public function testTwoCallsSameFinder()68 {69 $this->testFindPsr();70 $this->testSelf();71 }72 /**73 * @throws \ReflectionException74 * @throws Exception75 */76 public function testFindPsrNotAbstract()77 {78 $classes = $this->classFinder->getClasses('Psr\\Log\\', function ($class) {79 $reflectionClass = new ReflectionClass($class);80 return !$reflectionClass->isAbstract();81 });82 $this->assertTrue(count($classes) > 0);83 foreach ($classes as $class) {84 $this->assertTrue(class_exists($class));85 $this->assertStringStartsWith('Psr\\Log\\', $class);86 $reflectionClass = new ReflectionClass($class);87 $this->assertFalse($reflectionClass->isAbstract());88 }89 }90 /**91 * @throws \ReflectionException92 * @throws Exception93 */94 public function testFindPsrOnlyAbstract()95 {96 $classes = $this->classFinder->getClasses('Psr\\Log\\', function ($class) {97 $reflectionClass = new ReflectionClass($class);98 return $reflectionClass->isAbstract();99 });100 $this->assertTrue(count($classes) > 0);101 foreach ($classes as $class) {102 $this->assertTrue(class_exists($class));103 $this->assertStringStartsWith('Psr\\Log\\', $class);104 $reflectionClass = new ReflectionClass($class);105 $this->assertTrue($reflectionClass->isAbstract());106 }107 }108 /**109 * @throws Exception110 */111 public function testFindPsrNotInVendor()112 {113 $classes = $this->classFinder->getClasses('Psr\\Log\\', null, false);114 $this->assertFalse(count($classes) > 0);115 }116 public function testClassMapInitCache()117 {118 $forceInit = $this->classFinder->classLoaderInit;119 $this->classFinder->initClassMap();120 if ($forceInit) {121 $this->assertNull($this->classFinder->optimisedClassMap);122 } else {123 $this->assertIsArray($this->classFinder->optimisedClassMap);124 }125 $this->assertTrue($this->classFinder->classLoaderInit);126 }127 /**...
PreloaderTest.php
Source:PreloaderTest.php
...15{16 public function testEmptyListFiles() : void17 {18 $preloader = new Preloader(packagesDir: __DIR__);19 self::assertEmpty($preloader->getAutoloader()->getClasses());20 self::assertEmpty($preloader->listPackagesFiles());21 self::assertEmpty($preloader->listFiles());22 self::assertEmpty($preloader->getAutoloader()->getClasses());23 }24 public function testListFiles() : void25 {26 $autoloader = new Autoloader();27 $autoloader->setNamespace(28 'Foo\Bar\Baz',29 __DIR__ . '/support'30 )->setClass(\OneInterface::class, __DIR__ . '/support/OneInterface.php');31 $preloader = new Preloader($autoloader, __DIR__ . '/../vendor/aplus');32 $packageFiles = $preloader->listPackagesFiles();33 $files = $preloader->listFiles();34 self::assertContains(35 \realpath(__DIR__ . '/../vendor/aplus/debug/src/Debugger.php'),36 $packageFiles37 );38 self::assertContains(39 \realpath(__DIR__ . '/../vendor/aplus/debug/src/Debugger.php'),40 $files41 );42 self::assertNotContains(43 \realpath(__DIR__ . '/../vendor/aplus/coding-standard/src/Config.php'),44 $files45 );46 self::assertNotContains(47 __DIR__ . '/support/OneClass.php',48 $files49 );50 self::assertContains(51 __DIR__ . '/support/OneEnum.php',52 $files53 );54 self::assertContains(55 __DIR__ . '/support/OneInterface.php',56 $files57 );58 $classes = $preloader->getAutoloader()->getClasses();59 self::assertArrayHasKey(60 \Framework\Debug\Debugger::class,61 $classes62 );63 self::assertArrayNotHasKey(64 \Framework\CodingStandard\Config::class,65 $classes66 );67 self::assertArrayHasKey(68 \Foo\Bar\Baz\OneEnum::class,69 $classes70 );71 self::assertArrayHasKey(72 \Foo\Bar\Baz\OneTrait::class,73 $classes74 );75 self::assertArrayNotHasKey(76 \OneClass::class,77 $classes78 );79 self::assertArrayHasKey(80 \OneInterface::class,81 $classes82 );83 self::assertContains(84 $classes[\Framework\Debug\Debugger::class],85 $packageFiles86 );87 self::assertContains(88 $classes[\Framework\Debug\Debugger::class],89 $files90 );91 }92 public function testPackagesDir() : void93 {94 $dir = __DIR__ . '/../vendor/aplus';95 $preloader = new Preloader(packagesDir: null);96 $preloader->setPackagesDir($dir);97 self::assertSame(98 \realpath($dir) . \DIRECTORY_SEPARATOR,99 $preloader->getPackagesDir()100 );101 self::assertEmpty($preloader->listFiles());102 self::assertNotEmpty($preloader->withPackages()->listFiles());103 $classes = $preloader->getAutoloader()->getClasses();104 self::assertContains(105 $classes[\Framework\Debug\Debugger::class],106 $preloader->listFiles()107 );108 self::assertArrayNotHasKey(109 \Framework\CodingStandard\Config::class,110 $classes111 );112 $preloader->withDevPackages()->listFiles();113 $classes = $preloader->getAutoloader()->getClasses();114 self::assertArrayHasKey(115 \Framework\CodingStandard\Config::class,116 $classes117 );118 self::assertContains(119 $classes[\Framework\CodingStandard\Config::class],120 $preloader->withDevPackages()->listFiles()121 );122 $this->expectException(\InvalidArgumentException::class);123 $this->expectExceptionMessage('Invalid packages dir: /foo/bar');124 $preloader->setPackagesDir('/foo/bar');125 }126 public function testLoad() : void127 {...
getClasses
Using AI Code Generation
1$autoloader = new Autoloader();2$classes = $autoloader->getClasses();3print_r($classes);4$autoloader = new Autoloader();5$classes = $autoloader->getClasses();6print_r($classes);7Array ( [0] => Autoloader [1] => Test [2] => Test1 [3] => Test2 [4] => Test3 )8Array ( [0] => Autoloader [1] => Test [2] => Test1 [3] => Test2 [4] => Test3 )
getClasses
Using AI Code Generation
1require_once 'autoloader.php';2$autoloader = new Autoloader();3$autoloader->getClasses();4require_once 'autoloader.php';5$autoloader = new Autoloader();6$autoloader->getClasses();7require_once 'autoloader.php';8$autoloader = new Autoloader();9$autoloader->getClasses();10require_once 'autoloader.php';11$autoloader = new Autoloader();12$autoloader->getClasses();13require_once 'autoloader.php';14$autoloader = new Autoloader();15$autoloader->getClasses();16require_once 'autoloader.php';17$autoloader = new Autoloader();18$autoloader->getClasses();19require_once 'autoloader.php';20$autoloader = new Autoloader();21$autoloader->getClasses();22require_once 'autoloader.php';23$autoloader = new Autoloader();24$autoloader->getClasses();25require_once 'autoloader.php';26$autoloader = new Autoloader();27$autoloader->getClasses();28require_once 'autoloader.php';29$autoloader = new Autoloader();30$autoloader->getClasses();
getClasses
Using AI Code Generation
1spl_autoload_register(array('Autoloader', 'getClasses'));2$test = new Test();3$test->testMethod();4spl_autoload_register(array('Autoloader', 'getClasses'));5$test = new Test();6$test->testMethod();7spl_autoload_register(array('Autoloader', 'getClasses'));8$test = new Test();9$test->testMethod();10spl_autoload_register(array('Autoloader', 'getClasses'));11$test = new Test();12$test->testMethod();13spl_autoload_register(array('Autoloader', 'getClasses'));14$test = new Test();15$test->testMethod();16spl_autoload_register(array('Autoloader', 'getClasses'));17$test = new Test();18$test->testMethod();19spl_autoload_register(array('Autoloader', 'getClasses'));20$test = new Test();21$test->testMethod();22spl_autoload_register(array('Autoloader', 'getClasses'));23$test = new Test();24$test->testMethod();25spl_autoload_register(array('Autoloader', 'getClasses'));26$test = new Test();27$test->testMethod();28spl_autoload_register(array('Autoloader', 'getClasses'));29$test = new Test();30$test->testMethod();31spl_autoload_register(array('Autoloader', 'getClasses'));32$test = new Test();33$test->testMethod();
getClasses
Using AI Code Generation
1require_once 'autoloader.php';2$autoloader = new Autoloader();3$classes = $autoloader->getClasses();4echo '<pre>';5print_r($classes);6echo '</pre>';7require_once 'autoloader.php';8$autoloader = new Autoloader();9$methods = get_class_methods($autoloader);10echo '<pre>';11print_r($methods);12echo '</pre>';13require_once 'autoloader.php';14$autoloader = new Autoloader();15$methods = get_class_methods($autoloader);16echo '<pre>';17print_r($methods);18echo '</pre>';19require_once 'autoloader.php';20$autoloader = new Autoloader();21$methods = get_class_methods($autoloader);22echo '<pre>';23print_r($methods);24echo '</pre>';
getClasses
Using AI Code Generation
1require_once 'autoloader.php';2$autoloader = new autoloader();3$classes = $autoloader->getClasses();4foreach($classes as $class) {5 echo $class.'<br>';6}7require_once 'autoloader.php';8$autoloader = new autoloader();9$classes = $autoloader->getClasses();10foreach($classes as $class) {11 echo $class.'<br>';12}13require_once 'autoloader.php';14$autoloader = new autoloader();15$classes = $autoloader->getClasses();16foreach($classes as $class) {17 echo $class.'<br>';18}19require_once 'autoloader.php';20$autoloader = new autoloader();21$classes = $autoloader->getClasses();22foreach($classes as $class) {23 echo $class.'<br>';24}25require_once 'autoloader.php';26$autoloader = new autoloader();27$classes = $autoloader->getClasses();28foreach($classes as $class) {29 echo $class.'<br>';30}31require_once 'autoloader.php';32$autoloader = new autoloader();33$classes = $autoloader->getClasses();34foreach($classes as $class) {35 echo $class.'<br>';36}37require_once 'autoloader.php';38$autoloader = new autoloader();39$classes = $autoloader->getClasses();40foreach($classes as $class) {41 echo $class.'<br>';42}43require_once 'autoloader.php';44$autoloader = new autoloader();45$classes = $autoloader->getClasses();46foreach($classes as $class) {
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 getClasses 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!!