/**
  * We need to test that toArray method on an instance of Redbox\Scan\Report\Report
  * returns a valid array.
  */
 public function test_report_to_array_returns_a_valid_array()
 {
     $input = array('name' => 'Test scan', 'date' => date(DATE_RFC2822), 'path' => '/somepath', 'items' => array());
     $report = Scan\Report\Report::fromArray($input);
     $output = $report->toArray();
     $this->assertEquals(json_encode($input), json_encode($output));
 }
 /**
  * Read the previous scan results from the file system.
  * @return bool|Report\Report
  */
 public function read()
 {
     if (file_exists($this->filename) === true) {
         $stored_report = (array) Yaml::parse(@file_get_contents($this->filename));
         $report = Report\Report::fromArray($stored_report);
         return $report;
     }
     return false;
 }
Exemple #3
0
 /**
  * Read the previous scan results from the file system.
  *
  * @return bool|Report
  */
 public function read()
 {
     $scan = $this->getScan();
     if (is_array($scan) === true) {
         $scan['items'] = $this->getReportItems();
         return Report::fromArray($scan);
     }
     return false;
 }
 /**
  * Compare a write and read operation on the filesystem adapter.
  * Lets hope this passes.
  */
 public function test_filesystem_write_and_read_get_the_same_data()
 {
     $src_file = dirname(__FILE__) . '/Assets/Filesystem/data.yml';
     $target_file = dirname(__FILE__) . '/Assets/tmp/filesystem.yml';
     $local_data = Yaml::parse(@file_get_contents($src_file));
     /**
      * Read the source file and create a report from it.
      * We will write te file to a temp location and then read it
      * and compare the results.
      */
     $fs1 = new Scan\Adapter\Filesystem($target_file);
     $report1 = Scan\Report\Report::fromArray($local_data);
     $fs1->write($report1);
     /**
      * Read the test file and compare the results.
      */
     $fs2 = new Scan\Adapter\Filesystem($target_file);
     $report2 = $fs2->read();
     /**
      * Here go comparing the 2 results.
      */
     $this->assertEquals($report2->getName(), $report1->getName());
     $this->assertEquals($report2->getPath(), $report1->getPath());
     $this->assertEquals($report2->getDate(), $report1->getDate());
     $this->assertEquals(array(), $report1->getModifiedFiles());
     $this->assertEquals(array(), $report1->getNewfiles());
     unset($fs1);
     unset($fs2);
     unset($report1);
     unset($report2);
     unlink($target_file);
 }
Exemple #5
0
 /**
  * Read the previous scan results from the file system.
  *
  * @return array
  */
 public function read()
 {
     if (!$this->handle) {
         return false;
     }
     $stream = fopen('php://memory', 'w');
     if (!$stream) {
         return false;
     }
     $data = '';
     if ($ret = ftp_nb_fget($this->handle, $stream, $this->filename, $this->transfer_mode)) {
         while ($ret === FTP_MOREDATA) {
             rewind($stream);
             $data .= stream_get_contents($stream);
             $ret = ftp_nb_continue($this->handle);
         }
         if ($ret != FTP_FINISHED) {
             return false;
         } else {
             $data = (array) Yaml::parse($data);
             return Report\Report::fromArray($data);
         }
     }
     return false;
 }