ApplicationTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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\Test;
  12. use Composer\Console\Application;
  13. use Composer\Test\TestCase;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class ApplicationTest extends TestCase
  16. {
  17. public function testDevWarning()
  18. {
  19. $application = new Application;
  20. $inputMock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
  21. $outputMock = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
  22. putenv('COMPOSER_NO_INTERACTION=1');
  23. $index = 0;
  24. $inputMock->expects($this->at($index++))
  25. ->method('hasParameterOption')
  26. ->with($this->equalTo('--no-plugins'))
  27. ->will($this->returnValue(true));
  28. $inputMock->expects($this->at($index++))
  29. ->method('setInteractive')
  30. ->with($this->equalTo(false));
  31. $inputMock->expects($this->at($index++))
  32. ->method('hasParameterOption')
  33. ->with($this->equalTo('--no-cache'))
  34. ->will($this->returnValue(false));
  35. $inputMock->expects($this->at($index++))
  36. ->method('getParameterOption')
  37. ->with($this->equalTo(array('--working-dir', '-d')))
  38. ->will($this->returnValue(false));
  39. $inputMock->expects($this->any())
  40. ->method('getFirstArgument')
  41. ->will($this->returnValue('show'));
  42. $index = 0;
  43. $outputMock->expects($this->at($index++))
  44. ->method("write");
  45. if (extension_loaded('xdebug')) {
  46. $outputMock->expects($this->at($index++))
  47. ->method("getVerbosity")
  48. ->willReturn(OutputInterface::VERBOSITY_NORMAL);
  49. $outputMock->expects($this->at($index++))
  50. ->method("write")
  51. ->with($this->equalTo('<warning>You are running composer with Xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug</warning>'));
  52. }
  53. $outputMock->expects($this->at($index++))
  54. ->method("getVerbosity")
  55. ->willReturn(OutputInterface::VERBOSITY_NORMAL);
  56. $outputMock->expects($this->at($index++))
  57. ->method("write")
  58. ->with($this->equalTo(sprintf('<warning>Warning: This development build of composer is over 60 days old. It is recommended to update it by running "%s self-update" to get the latest version.</warning>', $_SERVER['PHP_SELF'])));
  59. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  60. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  61. }
  62. $application->doRun($inputMock, $outputMock);
  63. }
  64. public function ensureNoDevWarning($command)
  65. {
  66. $application = new Application;
  67. $application->add(new \Composer\Command\SelfUpdateCommand);
  68. $inputMock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
  69. $outputMock = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
  70. putenv('COMPOSER_NO_INTERACTION=1');
  71. $index = 0;
  72. $inputMock->expects($this->at($index++))
  73. ->method('hasParameterOption')
  74. ->with($this->equalTo('--no-plugins'))
  75. ->will($this->returnValue(true));
  76. $inputMock->expects($this->at($index++))
  77. ->method('setInteractive')
  78. ->with($this->equalTo(false));
  79. $inputMock->expects($this->at($index++))
  80. ->method('hasParameterOption')
  81. ->with($this->equalTo('--no-cache'))
  82. ->will($this->returnValue(false));
  83. $inputMock->expects($this->at($index++))
  84. ->method('getParameterOption')
  85. ->with($this->equalTo(array('--working-dir', '-d')))
  86. ->will($this->returnValue(false));
  87. $inputMock->expects($this->any())
  88. ->method('getFirstArgument')
  89. ->will($this->returnValue('show'));
  90. $outputMock->expects($this->never())
  91. ->method("writeln");
  92. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  93. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  94. }
  95. $application->doRun($inputMock, $outputMock);
  96. }
  97. public function testDevWarningPrevented()
  98. {
  99. $this->ensureNoDevWarning('self-update');
  100. }
  101. public function testDevWarningPreventedAlias()
  102. {
  103. $this->ensureNoDevWarning('self-up');
  104. }
  105. }