ApplicationTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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->getMock('Symfony\Component\Console\Input\InputInterface');
  21. $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
  22. $inputMock->expects($this->once())
  23. ->method('hasParameterOption')
  24. ->with($this->equalTo('--no-plugins'))
  25. ->will($this->returnValue(true));
  26. $inputMock->expects($this->once())
  27. ->method('getFirstArgument')
  28. ->will($this->returnValue('list'));
  29. $index = 0;
  30. $outputMock->expects($this->at($index++))
  31. ->method("writeError");
  32. if (extension_loaded('xdebug')) {
  33. $outputMock->expects($this->at($index++))
  34. ->method("getVerbosity")
  35. ->willReturn(OutputInterface::VERBOSITY_NORMAL);
  36. $outputMock->expects($this->at($index++))
  37. ->method("write")
  38. ->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>'));
  39. }
  40. $outputMock->expects($this->at($index++))
  41. ->method("getVerbosity")
  42. ->willReturn(OutputInterface::VERBOSITY_NORMAL);
  43. $outputMock->expects($this->at($index++))
  44. ->method("write")
  45. ->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'])));
  46. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  47. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  48. }
  49. $this->setExpectedException('RuntimeException');
  50. $application->doRun($inputMock, $outputMock);
  51. }
  52. public function ensureNoDevWarning($command)
  53. {
  54. $application = new Application;
  55. $application->add(new \Composer\Command\SelfUpdateCommand);
  56. $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
  57. $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
  58. $inputMock->expects($this->once())
  59. ->method('getFirstArgument')
  60. ->will($this->returnValue($command));
  61. $outputMock->expects($this->never())
  62. ->method("writeln");
  63. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  64. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  65. }
  66. $this->setExpectedException('RuntimeException');
  67. $application->doRun($inputMock, $outputMock);
  68. }
  69. public function testDevWarningPrevented()
  70. {
  71. $this->ensureNoDevWarning('self-update');
  72. }
  73. public function testDevWarningPreventedAlias()
  74. {
  75. $this->ensureNoDevWarning('self-up');
  76. }
  77. }