TestCase.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Installers\Test;
  12. use Composer\Package\Version\VersionParser;
  13. use Composer\Package\Package;
  14. use Composer\Package\AliasPackage;
  15. use Composer\Package\LinkConstraint\VersionConstraint;
  16. use Composer\Util\Filesystem;
  17. abstract class TestCase extends \PHPUnit_Framework_TestCase
  18. {
  19. private static $parser;
  20. protected static function getVersionParser()
  21. {
  22. if (!self::$parser) {
  23. self::$parser = new VersionParser();
  24. }
  25. return self::$parser;
  26. }
  27. protected function getVersionConstraint($operator, $version)
  28. {
  29. return new VersionConstraint(
  30. $operator,
  31. self::getVersionParser()->normalize($version)
  32. );
  33. }
  34. protected function getPackage($name, $version)
  35. {
  36. $normVersion = self::getVersionParser()->normalize($version);
  37. return new Package($name, $normVersion, $version);
  38. }
  39. protected function getAliasPackage($package, $version)
  40. {
  41. $normVersion = self::getVersionParser()->normalize($version);
  42. return new AliasPackage($package, $normVersion, $version);
  43. }
  44. protected function ensureDirectoryExistsAndClear($directory)
  45. {
  46. $fs = new Filesystem();
  47. if (is_dir($directory)) {
  48. $fs->removeDirectory($directory);
  49. }
  50. mkdir($directory, 0777, true);
  51. }
  52. }