Esempio n. 1
0
 public function createProcessMock($successfully = true)
 {
     /** @var \PHPUnit_Framework_TestCase $this */
     $processBuilderMock = $this->getMock(ProcessBuilder::class);
     $processMock = $this->getMock(Process::class, [], [], '', false);
     $processBuilderMock->expects($this->any())->method('getProcess')->willReturn($processMock);
     $processMock->expects($this->any())->method('run')->willReturn(null);
     $processMock->expects($this->any())->method('isSuccessful')->willReturn($successfully);
     ProcessUtil::instance()->setProcessBuilder($processBuilderMock);
     return $processMock;
 }
Esempio n. 2
0
 /**
  * Push printable to print queue
  * @param PrintableInterface $printable
  * @throws PrinterTimeoutException
  * @throws PrinterException
  * @throws ExecutableNotFoundException
  * @throws PrinterProfileNotFoundException
  */
 public function enqueue(PrintableInterface $printable)
 {
     try {
         ProcessUtil::instance()->executeCommand($this->getProcessArguments($printable, $this->printerProfile), function ($processBuilder) use($printable) {
             /** @var ProcessBuilder $processBuilder */
             $processBuilder->setTimeout(self::PRINT_TIMEOUT);
             $processBuilder->setInput($printable->getContent());
         });
     } catch (ProcessTimedOutException $e) {
         throw new PrinterTimeoutException('Print timeout.', 0, $e);
     } catch (ProcessFailedException $e) {
         $process = $e->getProcess();
         if (false !== stripos($process->getErrorOutput(), 'The printer or class does not exist.')) {
             throw new PrinterProfileNotFoundException($this->printerProfile, $e);
         }
         throw new PrinterException($e->getMessage(), $e->getCode(), $e);
     } catch (RuntimeException $e) {
         throw new PrinterException($e->getMessage(), $e->getCode(), $e);
     }
 }
Esempio n. 3
0
 /**
  * @param $name
  * @param $device
  * @param null $driver
  * @return bool
  * @throws InvalidPrinterDeviceException
  * @throws PrinterConfigurationFailed
  * @throws ExecutableNotFoundException
  * @throws InvalidPrinterDeviceException
  * @throws InvalidPrinterDriverException
  */
 public function configure($name, $device, $driver = null)
 {
     try {
         $arguments = [$this->manager->getLpadminBinary(), '-p', $name, '-v', $device, '-E'];
         if ($driver) {
             $arguments = array_merge($arguments, ['-P', $driver]);
         }
         // in theory we don't need to check process output if it's succedded
         ProcessUtil::instance()->executeCommand($arguments);
         return true;
     } catch (ProcessFailedException $e) {
         $output = $e->getProcess()->getErrorOutput();
         if (false !== strpos($output, 'lpadmin: Bad device-uri')) {
             throw new InvalidPrinterDeviceException(sprintf('"%s" is not valid device uri.', $device), 0, $e);
         } elseif (false !== strpos($output, 'Unable to open PPD')) {
             throw new InvalidPrinterDriverException(sprintf('"%s" is not valid driver.', $driver), 0, $e);
         }
         throw new PrinterConfigurationFailed('Printer configuration failed.', 0, $e);
     }
 }
Esempio n. 4
0
 public function getProcessUtil()
 {
     return ProcessUtil::instance();
 }