public function __construct($stringVersion) { /* Parse the version into segments */ $segments = explode(".", $stringVersion); $segCount = count($segments); if ($segCount < 2 || $segCount > 3) { throw new \InvalidArgumentException($this->stdInvalidArgumentMessage()); } //When patch is ommited. It is interperated as a wildcard. if ($segCount == 2) { $segments[2] = "*"; } $spesVers = explode("-", $segments[2]); $segments[2] = $spesVers[0]; if (!isset($spesVers[1])) { $spesVers[1] = ""; } $spesVers = $spesVers[1]; /* end */ $this->major = $segments[0]; $this->minor = $segments[1]; $this->patch = $segments[2]; if (Str::startsWith($spesVers, "rc")) { $this->rc = (int) Str::subString($spesVers, 2); } else { if (Str::startsWith($spesVers, "alpha")) { $this->alpha = (int) Str::subString($spesVers, 5); } else { if (Str::startsWith($spesVers, "a")) { $this->alpha = (int) Str::subString($spesVers, 1); } else { if (Str::startsWith($spesVers, "beta")) { $this->beta = (int) Str::subString($spesVers, 4); } else { if (Str::startsWith($spesVers, "b")) { $this->beta = (int) Str::subString($spesVers, 1); } else { if ($spesVers === "") { //This means that -beta, -alpha and -rc was not supplied } else { throw new \InvalidArgumentException($this->stdInvalidArgumentMessage()); } } } } } } }
/** * Create a mock theme that is deleted * when the tests are done running * with a wp-require file * with the contents of $require. * * @param array $requires The desired contents of the wp-require file. * * @return WPTheme The theme */ public static function createMockTheme($requires) { $baseThemesDir = WPRequire::THEMES_DIR(); // Create a random name $themeName = Str::random(20); // Create the plugin directory $themeDir = new File($baseThemesDir . "/{$themeName}"); $themeDir->createDir(); // Create the base plugin file $styleCss = new File($themeDir->getPath() . "/style.css"); $styleCss->createFile(); // Write plugin name and version to the plugin header $styleCssWriter = new FileWriter($styleCss); $styleCssWriter->open(); $styleCssWriter->write("\n/*\n * Theme Name: {$themeName}\n * Version: 1.0.0\n */"); $styleCssWriter->close(); // Create the wp-require.json file $wpRequireFile = new File($themeDir->getPath() . "/wp-require.json"); $wpRequireFile->createFile(); $wpRequireFileWriter = new FileWriter($wpRequireFile); // Write the array as json to the wp-require.json file $wpRequireFileWriter->open(); $wpRequireFileWriter->write((string) new Json($requires)); $wpRequireFileWriter->close(); // Request files to be deleted on tearDown $styleCss->deleteOnExit(); $wpRequireFile->deleteOnExit(); $themeDir->deleteOnExit(); $theme = new WPTheme("{$themeName}"); return $theme; }