/**
  * This is more of an acceptance test case instead of a unit test. It verifies
  * that the Celerity map is up-to-date.
  */
 public function testCelerityMaps()
 {
     $resources_map = CelerityPhysicalResources::getAll();
     foreach ($resources_map as $resources) {
         $old_map = new CelerityResourceMap($resources);
         $new_map = id(new CelerityResourceMapGenerator($resources))->generate();
         // Don't actually compare these values with assertEqual(), since the diff
         // isn't helpful and is often enormously huge.
         $maps_are_identical = $new_map->getNameMap() === $old_map->getNameMap() && $new_map->getSymbolMap() === $old_map->getSymbolMap() && $new_map->getRequiresMap() === $old_map->getRequiresMap() && $new_map->getPackageMap() === $old_map->getPackageMap();
         $this->assertTrue($maps_are_identical, pht('When this test fails, it means the Celerity resource map is out ' . 'of date. Run `%s` to rebuild it.', 'bin/celerity map'));
     }
 }
예제 #2
0
 public static function getNamedInstance($name)
 {
     if (empty(self::$instances[$name])) {
         $resources_list = CelerityPhysicalResources::getAll();
         if (empty($resources_list[$name])) {
             throw new Exception(pht('No resource source exists with name "%s"!', $name));
         }
         $instance = new CelerityResourceMap($resources_list[$name]);
         self::$instances[$name] = $instance;
     }
     return self::$instances[$name];
 }
 /**
  * Rebuild the resource map for a resource source.
  *
  * @param CelerityPhysicalResources Resource source to rebuild.
  * @return void
  */
 private function rebuildResources(CelerityPhysicalResources $resources)
 {
     $this->log(pht('Rebuilding resource source "%s" (%s)...', $resources->getName(), get_class($resources)));
     id(new CelerityResourceMapGenerator($resources))->setDebug(true)->generate()->write();
 }
 public function testGetAll()
 {
     CelerityPhysicalResources::getAll();
     $this->assertTrue(true);
 }
 /**
  * Build package specifications for a given resource source.
  *
  * @param CelerityPhysicalResources Resource source to rebuild.
  * @param list<string, string> Map of `@provides` to hashes.
  * @param list<string, string> Map of hashes to resource names.
  * @return map<string, map<string, string>> Package information maps.
  */
 private function rebuildPackages(CelerityPhysicalResources $resources, array $symbol_map, array $reverse_map)
 {
     $package_map = array();
     $package_spec = $resources->getResourcePackages();
     foreach ($package_spec as $package_name => $package_symbols) {
         $type = null;
         $hashes = array();
         foreach ($package_symbols as $symbol) {
             $symbol_hash = idx($symbol_map, $symbol);
             if ($symbol_hash === null) {
                 throw new Exception(pht('Package specification for "%s" includes "%s", but that symbol ' . 'is not @provided by any resource.', $package_name, $symbol));
             }
             $resource_name = $reverse_map[$symbol_hash];
             $resource_type = $resources->getResourceType($resource_name);
             if ($type === null) {
                 $type = $resource_type;
             } else {
                 if ($type !== $resource_type) {
                     throw new Exception(pht('Package specification for "%s" includes resources of multiple ' . 'types (%s, %s). Each package may only contain one type of ' . 'resource.', $package_name, $type, $resource_type));
                 }
             }
             $hashes[] = $symbol . ':' . $symbol_hash;
         }
         $hash = $resources->getCelerityHash(implode("\n", $hashes));
         $package_map[$package_name] = array('hash' => $hash, 'symbols' => $package_symbols);
     }
     return $package_map;
 }