ApplicationTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. class ApplicationTest extends TestCase
  15. {
  16. public function testDevWarning()
  17. {
  18. $application = new Application;
  19. $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
  20. $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
  21. $inputMock->expects($this->once())
  22. ->method('getFirstArgument')
  23. ->will($this->returnValue('list'));
  24. $index = 0;
  25. if (extension_loaded('xdebug')) {
  26. $outputMock->expects($this->at($index++))
  27. ->method("write")
  28. ->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>'));
  29. }
  30. $outputMock->expects($this->at($index++))
  31. ->method("write")
  32. ->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'])));
  33. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  34. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  35. }
  36. $this->setExpectedException('RuntimeException');
  37. $application->doRun($inputMock, $outputMock);
  38. }
  39. public function ensureNoDevWarning($command)
  40. {
  41. $application = new Application;
  42. $application->add(new \Composer\Command\SelfUpdateCommand);
  43. $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
  44. $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
  45. $inputMock->expects($this->once())
  46. ->method('getFirstArgument')
  47. ->will($this->returnValue($command));
  48. $outputMock->expects($this->never())
  49. ->method("writeln");
  50. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  51. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  52. }
  53. $this->setExpectedException('RuntimeException');
  54. $application->doRun($inputMock, $outputMock);
  55. }
  56. public function testDevWarningPrevented()
  57. {
  58. $this->ensureNoDevWarning('self-update');
  59. }
  60. public function testDevWarningPreventedAlias()
  61. {
  62. $this->ensureNoDevWarning('self-up');
  63. }
  64. }