View file vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/BinaryDriverTestCase.php

File size: 2.13Kb
  1. <?php
  2.  
  3. namespace Alchemy\BinaryDriver;
  4.  
  5. use Psr\Log\LoggerInterface;
  6. use Symfony\Component\Process\Process;
  7.  
  8. /**
  9. * Convenient PHPUnit methods for testing BinaryDriverInterface implementations.
  10. */
  11. class BinaryDriverTestCase extends \PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @return ProcessBuilderFactoryInterface
  15. */
  16. public function createProcessBuilderFactoryMock()
  17. {
  18. return $this->getMock('Alchemy\BinaryDriver\ProcessBuilderFactoryInterface');
  19. }
  20.  
  21. /**
  22. * @param integer $runs The number of runs expected
  23. * @param Boolean $success True if the process expects to be successfull
  24. * @param string $commandLine The commandline executed
  25. * @param string $output The process output
  26. * @param string $error The process error output
  27. *
  28. * @return Process
  29. */
  30. public function createProcessMock($runs = 1, $success = true, $commandLine = null, $output = null, $error = null, $callback = false)
  31. {
  32. $process = $this->getMockBuilder('Symfony\Component\Process\Process')
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35.  
  36. $builder = $process->expects($this->exactly($runs))
  37. ->method('run');
  38.  
  39. if (true === $callback) {
  40. $builder->with($this->isInstanceOf('Closure'));
  41. }
  42.  
  43. $process->expects($this->any())
  44. ->method('isSuccessful')
  45. ->will($this->returnValue($success));
  46.  
  47. foreach (array(
  48. 'getOutput' => $output,
  49. 'getErrorOutput' => $error,
  50. 'getCommandLine' => $commandLine,
  51. ) as $command => $value) {
  52. $process
  53. ->expects($this->any())
  54. ->method($command)
  55. ->will($this->returnValue($value));
  56. }
  57.  
  58. return $process;
  59. }
  60.  
  61. /**
  62. * @return LoggerInterface
  63. */
  64. public function createLoggerMock()
  65. {
  66. return $this->getMock('Psr\Log\LoggerInterface');
  67. }
  68.  
  69. /**
  70. * @return ConfigurationInterface
  71. */
  72. public function createConfigurationMock()
  73. {
  74. return $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface');
  75. }
  76. }