ApplicationTest.php 3.9 KB

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