/** * @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 classesFromPsr4PackagesAreLoaded() { $this->mockPackage1 = $this->getMockBuilder(\TYPO3\Flow\Package\Package::class)->disableOriginalConstructor()->getMock(); $this->mockPackage1->expects($this->any())->method('getNamespace')->will($this->returnValue('Acme\\MyApp')); $this->mockPackage1->expects($this->any())->method('getPackagePath')->will($this->returnValue('vfs://Test/Packages/Application/Acme.MyApp/')); $this->mockPackage1->expects($this->any())->method('getFlattenedAutoloadConfiguration')->will($this->returnValue([['namespace' => 'Acme\\MyApp', 'classPath' => 'vfs://Test/Packages/Application/Acme.MyApp/Classes/', 'mappingType' => ClassLoader::MAPPING_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->mockPackages['Acme.MyApp'] = $this->mockPackage1; $this->classLoader->setPackages($this->mockPackages); $this->classLoader->loadClass('Acme\\MyApp\\Foo'); $this->assertTrue(self::$testClassWasLoaded); }
/** * @test */ public function packageMetaDataContainsPackageType() { $packagePath = 'vfs://Packages/Application/Acme.MyPackage/'; mkdir($packagePath, 0777, TRUE); file_put_contents($packagePath . 'composer.json', '{"name": "acme/mypackage", "type": "flow-test"}'); $package = new Package($this->getMock('TYPO3\\Flow\\Package\\PackageManager'), 'Acme.MyPackage', $packagePath, 'Classes'); $metaData = $package->getPackageMetaData(); $this->assertEquals('flow-test', $metaData->getPackageType()); }
/** * @test */ public function getPackageMetaDataIgnoresUnresolvableConstraints() { $packagePath = 'vfs://Packages/Application/Acme.MyPackage/'; mkdir($packagePath, 0777, true); file_put_contents($packagePath . 'composer.json', '{"name": "acme/mypackage", "type": "flow-test", "require": { "non/existing/package": "*" }}'); $mockPackageManager = $this->getMockBuilder(PackageManager::class)->disableOriginalConstructor()->getMock(); $mockPackageManager->expects($this->once())->method('getPackageKeyFromComposerName')->with('non/existing/package')->will($this->throwException(new InvalidPackageStateException())); $package = new Package($mockPackageManager, 'Acme.MyPackage', $packagePath, 'Classes'); $metaData = $package->getPackageMetaData(); $packageConstraints = $metaData->getConstraintsByType(MetaDataInterface::CONSTRAINT_TYPE_DEPENDS); $this->assertCount(0, $packageConstraints); }
/** * Returns the package meta data object of this package. * * @return \TYPO3\Flow\Package\MetaData */ public function getPackageMetaData() { if ($this->packageMetaData === NULL) { parent::getPackageMetaData(); $suggestions = $this->getComposerManifest('suggest'); if ($suggestions !== NULL) { foreach ($suggestions as $suggestion => $version) { if ($this->packageRequirementIsComposerPackage($suggestion) === FALSE) { // Skip non-package requirements continue; } $packageKey = $this->packageManager->getPackageKeyFromComposerName($suggestion); $constraint = new \TYPO3\Flow\Package\MetaData\PackageConstraint(\TYPO3\Flow\Package\MetaDataInterface::CONSTRAINT_TYPE_SUGGESTS, $packageKey); $this->packageMetaData->addConstraint($constraint); } } } return $this->packageMetaData; }
/** * @test * @expectedException \TYPO3\Flow\Composer\Exception\MissingPackageManifestException */ public function throwExceptionWhenSpecifyingAPathWithMissingComposerManifest() { $packagePath = 'vfs://Packages/Some/Path/Some.Package/'; mkdir($packagePath, 0777, true); $package = new Package('Some.Package', 'some/package', 'vfs://Packages/Some/Path/Some.Package/', []); $package->getComposerManifest(); }
/** * @test */ public function getClassFilesReturnsAListOfClassFilesOfThePackage() { $packagePath = 'vfs://Packages/Application/Acme.MyPackage/'; mkdir($packagePath, 0777, TRUE); file_put_contents($packagePath . 'composer.json', '{"name": "acme/mypackage", "type": "flow-test"}'); mkdir($packagePath . 'Classes/Acme/MyPackage/Controller', 0770, TRUE); mkdir($packagePath . 'Classes/Acme/MyPackage/Domain/Model', 0770, TRUE); file_put_contents($packagePath . 'Classes/Acme/MyPackage/Controller/FooController.php', ''); file_put_contents($packagePath . 'Classes/Acme/MyPackage/Domain/Model/Foo.php', ''); file_put_contents($packagePath . 'Classes/Acme/MyPackage/Domain/Model/Bar.php', ''); $expectedClassFilesArray = array('Acme\\MyPackage\\Controller\\FooController' => 'Classes/Acme/MyPackage/Controller/FooController.php', 'Acme\\MyPackage\\Domain\\Model\\Foo' => 'Classes/Acme/MyPackage/Domain/Model/Foo.php', 'Acme\\MyPackage\\Domain\\Model\\Bar' => 'Classes/Acme/MyPackage/Domain/Model/Bar.php'); $package = new Package($this->mockPackageManager, 'Acme.MyPackage', $packagePath, 'Classes'); $actualClassFilesArray = $package->getClassFiles(); $this->assertEquals($expectedClassFilesArray, $actualClassFilesArray); }
/** * Checks if a package is qualified to be shown for translations (e.g. the default * directories and the file exists. * * The check depends on the default language from the configuration! * * @param \TYPO3\Flow\Package\Package $package * @return boolean */ protected function hasXliffFilesInDefaultDirectories(\TYPO3\Flow\Package\Package $package) { $packageBasePath = $package->getResourcesPath(); $defaultLanguage = $this->settings['defaultLanguage']; if (is_dir($packageBasePath . 'Private/Translations') && is_dir($packageBasePath . 'Private/Translations/' . $defaultLanguage) && is_file($packageBasePath . 'Private/Translations/' . $defaultLanguage . '/Main.xlf')) { return true; } return false; }