InstallViaComposerTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Smoke;
  12. use Keradus\CliExecutor\CommandExecutor;
  13. use PhpCsFixer\Utils;
  14. use PHPUnit\Framework\TestCase;
  15. use Symfony\Component\Filesystem\Filesystem;
  16. /**
  17. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @coversNothing
  22. * @group covers-nothing
  23. * @large
  24. */
  25. final class InstallViaComposerTest extends TestCase
  26. {
  27. public static function setUpBeforeClass()
  28. {
  29. try {
  30. CommandExecutor::create('php --version', __DIR__)->getResult();
  31. } catch (\RuntimeException $e) {
  32. self::markTestSkipped('Missing `php` env script. Details:'."\n".$e->getMessage());
  33. }
  34. try {
  35. CommandExecutor::create('composer --version', __DIR__)->getResult();
  36. } catch (\RuntimeException $e) {
  37. self::markTestSkipped('Missing `composer` env script. Details:'."\n".$e->getMessage());
  38. }
  39. }
  40. public function testFoo()
  41. {
  42. $fs = new Filesystem();
  43. $tmpPath = tempnam(sys_get_temp_dir(), 'cs_fixer_tmp_');
  44. unlink($tmpPath);
  45. $fs->mkdir($tmpPath);
  46. $initialComposerFileState = [
  47. 'repositories' => [
  48. [
  49. 'type' => 'path',
  50. 'url' => __DIR__.'/../..',
  51. ],
  52. ],
  53. 'require' => [
  54. 'friendsofphp/php-cs-fixer' => '*@dev',
  55. ],
  56. ];
  57. file_put_contents(
  58. $tmpPath.'/composer.json',
  59. json_encode($initialComposerFileState, Utils::calculateBitmask(['JSON_PRETTY_PRINT']))
  60. );
  61. $this->assertSame(0, CommandExecutor::create('composer install -q', $tmpPath)->getResult()->getCode());
  62. $this->assertSame(0, CommandExecutor::create('composer dump-autoload --optimize', $tmpPath)->getResult()->getCode());
  63. $this->assertSame(0, CommandExecutor::create('php vendor/autoload.php', $tmpPath)->getResult()->getCode());
  64. $this->assertSame(0, CommandExecutor::create('vendor/bin/php-cs-fixer --version', $tmpPath)->getResult()->getCode());
  65. $fs->remove($tmpPath);
  66. }
  67. }