Exemplo n.º 1
0
 /**
  * @test
  */
 public function classesFromPsr4PackagesAreLoaded()
 {
     $this->mockPackage1->expects($this->any())->method('getAutoloadType')->will($this->returnValue(Package::AUTOLOADER_TYPE_PSR4));
     mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes', 0770, TRUE);
     file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Foo.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
     $this->classLoader->setPackages($this->mockPackages, $this->mockPackages);
     $this->classLoader->loadClass('Acme\\MyApp\\Foo');
     $this->assertTrue(self::$testClassWasLoaded);
 }
 /**
  * @test
  */
 public function classesFromOverlayedPsr4PackagesAreOverwritten()
 {
     $this->classLoader = new ClassLoader();
     $mockPackage1 = $this->getMockBuilder(\TYPO3\Flow\Package\Package::class)->disableOriginalConstructor()->getMock();
     $mockPackage1->expects($this->any())->method('getNamespace')->will($this->returnValue('TestPackage\\Foo'));
     $mockPackage1->expects($this->any())->method('getFlattenedAutoloadConfiguration')->will($this->returnValue([['namespace' => 'TestPackage\\Foo', 'classPath' => 'vfs://Test/Packages/Libraries/test/subPackage/src/', 'mappingType' => ClassLoader::MAPPING_TYPE_PSR4]]));
     $mockPackage2 = $this->getMockBuilder(\TYPO3\Flow\Package\Package::class)->disableOriginalConstructor()->getMock();
     $mockPackage2->expects($this->any())->method('getNamespace')->will($this->returnValue('TestPackage'));
     $mockPackage2->expects($this->any())->method('getFlattenedAutoloadConfiguration')->will($this->returnValue([['namespace' => 'TestPackage', 'classPath' => 'vfs://Test/Packages/Libraries/test/mainPackage/src/', 'mappingType' => ClassLoader::MAPPING_TYPE_PSR4]]));
     $packages = array($mockPackage2, $mockPackage1);
     mkdir('vfs://Test/Packages/Libraries/test/subPackage/src/', 0770, true);
     mkdir('vfs://Test/Packages/Libraries/test/mainPackage/src/Foo', 0770, true);
     file_put_contents('vfs://Test/Packages/Libraries/test/subPackage/src/Bar3.php', '<?php ' . __CLASS__ . '::$testClassWasOverwritten = TRUE; ?>');
     file_put_contents('vfs://Test/Packages/Libraries/test/mainPackage/src/Foo/Bar3.php', '<?php ' . __CLASS__ . '::$testClassWasOverwritten = FALSE; ?>');
     $this->classLoader->setPackages($packages);
     $this->classLoader->loadClass('TestPackage\\Foo\\Bar3');
     $this->assertTrue(self::$testClassWasOverwritten);
 }
 /**
  * @test
  */
 public function classesFromOverlayedPsr4PackagesAreOverwritten()
 {
     $this->classLoader = new ClassLoader();
     $mockPackage1 = $this->getMockBuilder('TYPO3\\Flow\\Package\\Package')->disableOriginalConstructor()->getMock();
     $mockPackage1->expects($this->any())->method('getAutoloadType')->will($this->returnValue(Package::AUTOLOADER_TYPE_PSR4));
     $mockPackage1->expects($this->any())->method('getNamespace')->will($this->returnValue('TestPackage\\Foo'));
     $mockPackage1->expects($this->any())->method('getClassesPath')->will($this->returnValue('vfs://Test/Packages/Libraries/test/subPackage/src/'));
     $mockPackage1->expects($this->any())->method('getPackagePath')->will($this->returnValue('vfs://Test/Packages/Libraries/test/subPackage/src/'));
     $mockPackage2 = $this->getMockBuilder('TYPO3\\Flow\\Package\\Package')->disableOriginalConstructor()->getMock();
     $mockPackage2->expects($this->any())->method('getAutoloadType')->will($this->returnValue(Package::AUTOLOADER_TYPE_PSR4));
     $mockPackage2->expects($this->any())->method('getNamespace')->will($this->returnValue('TestPackage'));
     $mockPackage2->expects($this->any())->method('getClassesPath')->will($this->returnValue('vfs://Test/Packages/Libraries/test/mainPackage/src/'));
     $mockPackage2->expects($this->any())->method('getPackagePath')->will($this->returnValue('vfs://Test/Packages/Libraries/test/mainPackage/src/'));
     $packages = array($mockPackage2, $mockPackage1);
     mkdir('vfs://Test/Packages/Libraries/test/subPackage/src/', 0770, TRUE);
     mkdir('vfs://Test/Packages/Libraries/test/mainPackage/src/Foo', 0770, TRUE);
     file_put_contents('vfs://Test/Packages/Libraries/test/subPackage/src/Bar.php', '<?php ' . __CLASS__ . '::$testClassWasOverwritten = TRUE; ?>');
     file_put_contents('vfs://Test/Packages/Libraries/test/mainPackage/src/Foo/Bar.php', '<?php ' . __CLASS__ . '::$testClassWasOverwritten = FALSE; ?>');
     $this->classLoader->setPackages($packages, $packages);
     $this->classLoader->loadClass('TestPackage\\Foo\\Bar');
     $this->assertTrue(self::$testClassWasOverwritten);
 }