ApplicationTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $outputMock->expects($this->once())
  25. ->method("write")
  26. ->with($this->equalTo(sprintf('<warning>Warning: This development build of composer is over 30 days old. It is recommended to update it by running "%s self-update" to get the latest version.</warning>', $_SERVER['PHP_SELF'])));
  27. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  28. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  29. }
  30. $this->setExpectedException('RuntimeException');
  31. $application->doRun($inputMock, $outputMock);
  32. }
  33. public function ensureNoDevWarning($command)
  34. {
  35. $application = new Application;
  36. $application->add(new \Composer\Command\SelfUpdateCommand);
  37. $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
  38. $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
  39. $inputMock->expects($this->once())
  40. ->method('getFirstArgument')
  41. ->will($this->returnValue($command));
  42. $outputMock->expects($this->never())
  43. ->method("writeln");
  44. if (!defined('COMPOSER_DEV_WARNING_TIME')) {
  45. define('COMPOSER_DEV_WARNING_TIME', time() - 1);
  46. }
  47. $this->setExpectedException('RuntimeException');
  48. $application->doRun($inputMock, $outputMock);
  49. }
  50. public function testDevWarningPrevented()
  51. {
  52. $this->ensureNoDevWarning('self-update');
  53. }
  54. public function testDevWarningPreventedAlias()
  55. {
  56. $this->ensureNoDevWarning('self-up');
  57. }
  58. }