public function testAddJobs()
 {
     $queue = ['jobs' => []];
     $this->reader->expects($this->at(0))->method('read')->willReturn('');
     $queue['jobs'][] = ['name' => 'job A', 'params' => []];
     $this->writer->expects($this->at(0))->method('write')->with(json_encode($queue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     $this->reader->expects($this->at(1))->method('read')->willReturn(json_encode($queue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     $queue['jobs'][] = ['name' => 'job B', 'params' => []];
     $this->writer->expects($this->at(1))->method('write')->with(json_encode($queue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     $this->queue->addJobs([['name' => 'job A', 'params' => []], ['name' => 'job B', 'params' => []]]);
 }
Example #2
0
 public function testRead()
 {
     $this->directoryRead->expects($this->once())->method('isExist')->willReturn(true);
     $this->directoryRead->expects($this->once())->method('readFile')->willReturn('{"jobs":[{"name": "job A", "params": []}]}');
     $this->assertEquals('{"jobs":[{"name": "job A", "params": []}]}', $this->reader->read());
 }
Example #3
0
 /**
  * Initialize reader.
  *
  * @param Filesystem $filesystem
  * @param string|null $queueFileBasename
  */
 public function __construct(Filesystem $filesystem, $queueFileBasename = null)
 {
     $this->writer = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     parent::__construct($filesystem, $queueFileBasename);
 }