ApplicationTest.php 3.0 KB

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