You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
2.1 KiB

  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\composer;
  12. use Composer\Installer\LibraryInstaller;
  13. use Composer\Package\PackageInterface;
  14. use Composer\Repository\InstalledRepositoryInterface;
  15. class ThinkTesting extends LibraryInstaller
  16. {
  17. /**
  18. * {@inheritDoc}
  19. */
  20. public function getInstallPath(PackageInterface $package)
  21. {
  22. if ('topthink/think-testing' !== $package->getPrettyName()) {
  23. throw new \InvalidArgumentException('Unable to install this library!');
  24. }
  25. return parent::getInstallPath($package);
  26. }
  27. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  28. {
  29. parent::install($repo, $package);
  30. $this->copyTestDir($package);
  31. }
  32. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  33. {
  34. parent::update($repo, $initial, $target);
  35. $this->copyTestDir($target);
  36. }
  37. private function copyTestDir(PackageInterface $package)
  38. {
  39. $appDir = dirname($this->vendorDir);
  40. $source = $this->getInstallPath($package) . DIRECTORY_SEPARATOR . 'example';
  41. if (!is_file($appDir . DIRECTORY_SEPARATOR . 'phpunit.xml')) {
  42. $this->filesystem->copyThenRemove($source, $appDir);
  43. } else {
  44. $this->filesystem->removeDirectoryPhp($source);
  45. }
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. public function supports($packageType)
  51. {
  52. return 'think-testing' === $packageType;
  53. }
  54. }