ApplicationTest.php 3.1 KB

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