ApplicationTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. $index = 0;
  23. $inputMock->expects($this->at($index++))
  24. ->method('hasParameterOption')
  25. ->with($this->equalTo('--no-plugins'))
  26. ->will($this->returnValue(true));
  27. $inputMock->expects($this->at($index++))
  28. ->method('hasParameterOption')
  29. ->with($this->equalTo('--no-cache'))
  30. ->will($this->returnValue(false));
  31. $inputMock->expects($this->at($index++))
  32. ->method('getParameterOption')
  33. ->with($this->equalTo(array('--working-dir', '-d')))
  34. ->will($this->returnValue(false));
  35. $inputMock->expects($this->any())
  36. ->method('getFirstArgument')
  37. ->will($this->returnValue('show'));
  38. $index = 0;
  39. $outputMock->expects($this->at($index++))
  40. ->method("writeError");
  41. if (extension_loaded('xdebug')) {
  42. $outputMock->expects($this->at($index++))
  43. ->method("getVerbosity")
  44. ->willReturn(OutputInterface::VERBOSITY_NORMAL);
  45. $outputMock->expects($this->at($index++))
  46. ->method("write")
  47. ->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>'));
  48. }
  49. $outputMock->expects($this->at($index++))
  50. ->method("getVerbosity")
  51. ->willReturn(OutputInterface::VERBOSITY_NORMAL);
  52. $outputMock->expects($this->at($index++))
  53. ->method("write")
  54. ->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'])));
  55. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  56. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  57. }
  58. $application->doRun($inputMock, $outputMock);
  59. }
  60. public function ensureNoDevWarning($command)
  61. {
  62. $application = new Application;
  63. $application->add(new \Composer\Command\SelfUpdateCommand);
  64. $inputMock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
  65. $outputMock = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
  66. $index = 0;
  67. $inputMock->expects($this->at($index++))
  68. ->method('hasParameterOption')
  69. ->with($this->equalTo('--no-plugins'))
  70. ->will($this->returnValue(true));
  71. $inputMock->expects($this->at($index++))
  72. ->method('hasParameterOption')
  73. ->with($this->equalTo('--no-cache'))
  74. ->will($this->returnValue(false));
  75. $inputMock->expects($this->at($index++))
  76. ->method('getParameterOption')
  77. ->with($this->equalTo(array('--working-dir', '-d')))
  78. ->will($this->returnValue(false));
  79. $inputMock->expects($this->any())
  80. ->method('getFirstArgument')
  81. ->will($this->returnValue('show'));
  82. $outputMock->expects($this->never())
  83. ->method("writeln");
  84. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  85. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  86. }
  87. $application->doRun($inputMock, $outputMock);
  88. }
  89. public function testDevWarningPrevented()
  90. {
  91. $this->ensureNoDevWarning('self-update');
  92. }
  93. public function testDevWarningPreventedAlias()
  94. {
  95. $this->ensureNoDevWarning('self-up');
  96. }
  97. }