Example #1
0
 public function testSetOptions()
 {
     $options = array('format' => 'csv', 'dialect' => 'standard');
     $sut = $this->getMock('Dfp_Datafeed_File_Reader', array('getFormat', 'setFormatString'));
     $mockFormat = $this->getMock('Dfp_Datafeed_File_Reader_Format_Interface');
     $mockFormat->expects($this->once())->method('setOptions')->with($this->equalTo(array('dialect' => 'standard')));
     $sut->expects($this->any())->method('getFormat')->will($this->returnValue($mockFormat));
     $sut->expects($this->once())->method('setFormatString')->with($this->equalTo('csv'));
     $sut->setOptions($options);
     //test with a format instance
     $mockFormat = $this->getMock('Dfp_Datafeed_File_Reader_Format_Interface');
     $options = array('format' => $mockFormat);
     $sut = new Dfp_Datafeed_File_Reader();
     $sut->setOptions($options);
     $this->assertEquals($mockFormat, $sut->getFormat());
     //test with invalid format
     $sut = new Dfp_Datafeed_File_Reader();
     $options = array('format' => array());
     try {
         $sut->setOptions($options);
     } catch (Dfp_Datafeed_File_Reader_Exception $e) {
         if ($e->getMessage() == 'Invalid format specified') {
             return;
         }
     }
     $this->fail('Exception not thrown');
 }