예제 #1
0
 public function getVisitorMock(RecordInterface $record)
 {
     $visitor = $this->getMock('PSX\\Data\\Record\\VisitorInterface', array('visitObjectStart', 'visitObjectEnd', 'visitObjectValueStart', 'visitObjectValueEnd', 'visitArrayStart', 'visitArrayEnd', 'visitArrayValueStart', 'visitArrayValueEnd', 'visitValue'));
     $visitor->expects($this->at(0))->method('visitObjectStart')->with($this->equalTo('record'));
     $visitor->expects($this->at(1))->method('visitObjectValueStart')->with($this->equalTo('id'), $this->equalTo(1));
     $visitor->expects($this->at(2))->method('visitValue')->with($this->equalTo(1));
     $visitor->expects($this->at(4))->method('visitObjectValueStart')->with($this->equalTo('title'), $this->equalTo('foobar'));
     $visitor->expects($this->at(5))->method('visitValue')->with($this->equalTo('foobar'));
     $visitor->expects($this->at(7))->method('visitObjectValueStart')->with($this->equalTo('active'), $this->equalTo(true));
     $visitor->expects($this->at(8))->method('visitValue')->with($this->equalTo(true));
     $visitor->expects($this->at(10))->method('visitObjectValueStart')->with($this->equalTo('disabled'), $this->equalTo(false));
     $visitor->expects($this->at(11))->method('visitValue')->with($this->equalTo(false));
     $visitor->expects($this->at(13))->method('visitObjectValueStart')->with($this->equalTo('rating'), $this->equalTo(12.45));
     $visitor->expects($this->at(14))->method('visitValue')->with($this->equalTo(12.45));
     $visitor->expects($this->at(16))->method('visitObjectValueStart')->with($this->equalTo('date'), $this->equalTo(new \DateTime('2014-01-01T12:34:47+01:00')));
     $visitor->expects($this->at(17))->method('visitValue')->with($this->equalTo(new \DateTime('2014-01-01T12:34:47+01:00')));
     $visitor->expects($this->at(19))->method('visitObjectValueStart')->with($this->equalTo('href'), $this->equalTo(new Uri('http://foo.com')));
     $visitor->expects($this->at(20))->method('visitValue')->with($this->equalTo(new Uri('http://foo.com')));
     // person
     $visitor->expects($this->at(22))->method('visitObjectValueStart')->with($this->equalTo('person'), $this->equalTo($record->getPerson()));
     $visitor->expects($this->at(23))->method('visitObjectStart')->with($this->equalTo('person'));
     $visitor->expects($this->at(24))->method('visitObjectValueStart')->with($this->equalTo('title'), $this->equalTo('Foo'));
     $visitor->expects($this->at(25))->method('visitValue')->with($this->equalTo('Foo'));
     // category
     $visitor->expects($this->at(29))->method('visitObjectValueStart')->with($this->equalTo('category'), $this->equalTo($record->getCategory()));
     $visitor->expects($this->at(30))->method('visitObjectStart')->with($this->equalTo('category'));
     $visitor->expects($this->at(31))->method('visitObjectValueStart')->with($this->equalTo('general'), $this->equalTo($record->getCategory()->getGeneral()));
     $visitor->expects($this->at(32))->method('visitObjectStart')->with($this->equalTo('category'));
     $visitor->expects($this->at(33))->method('visitObjectValueStart')->with($this->equalTo('news'), $this->equalTo($record->getCategory()->getGeneral()->getNews()));
     $visitor->expects($this->at(34))->method('visitObjectStart')->with($this->equalTo('category'));
     $visitor->expects($this->at(35))->method('visitObjectValueStart')->with($this->equalTo('technic'), $this->equalTo('Foo'));
     $visitor->expects($this->at(36))->method('visitValue')->with($this->equalTo('Foo'));
     // tags
     $visitor->expects($this->at(44))->method('visitObjectValueStart')->with($this->equalTo('tags'), $this->equalTo($record->getTags()));
     $visitor->expects($this->at(46))->method('visitArrayValueStart')->with($this->equalTo('bar'));
     $visitor->expects($this->at(47))->method('visitValue')->with($this->equalTo('bar'));
     $visitor->expects($this->at(49))->method('visitArrayValueStart')->with($this->equalTo('foo'));
     $visitor->expects($this->at(50))->method('visitValue')->with($this->equalTo('foo'));
     $visitor->expects($this->at(52))->method('visitArrayValueStart')->with($this->equalTo('test'));
     $visitor->expects($this->at(53))->method('visitValue')->with($this->equalTo('test'));
     // entry
     $visitor->expects($this->at(57))->method('visitObjectValueStart')->with($this->equalTo('entry'), $this->equalTo($record->getEntry()));
     $visitor->expects($this->at(59))->method('visitArrayValueStart')->with($this->equalTo($record->getEntry()[0]));
     $visitor->expects($this->at(60))->method('visitObjectStart')->with($this->equalTo('entry'));
     $visitor->expects($this->at(61))->method('visitObjectValueStart')->with($this->equalTo('title'), $this->equalTo($record->getEntry()[0]->getTitle()));
     $visitor->expects($this->at(62))->method('visitValue')->with($this->equalTo($record->getEntry()[0]->getTitle()));
     $visitor->expects($this->at(66))->method('visitArrayValueStart')->with($this->equalTo($record->getEntry()[1]));
     $visitor->expects($this->at(67))->method('visitObjectStart')->with($this->equalTo('entry'));
     $visitor->expects($this->at(68))->method('visitObjectValueStart')->with($this->equalTo('title'), $this->equalTo($record->getEntry()[1]->getTitle()));
     $visitor->expects($this->at(69))->method('visitValue')->with($this->equalTo($record->getEntry()[1]->getTitle()));
     return $visitor;
 }
예제 #2
0
 protected function assertRecord(RecordInterface $record)
 {
     // check available fields
     $this->assertTrue($record->getRecordInfo()->hasField('id'));
     $this->assertTrue($record->getRecordInfo()->hasField('title'));
     $this->assertTrue($record->getRecordInfo()->hasField('active'));
     $this->assertTrue($record->getRecordInfo()->hasField('disabled'));
     $this->assertTrue($record->getRecordInfo()->hasField('count'));
     $this->assertTrue($record->getRecordInfo()->hasField('rating'));
     $this->assertFalse($record->getRecordInfo()->hasField('foobar'));
     $this->assertFalse($record->getRecordInfo()->hasField('foo'));
     if ($this->canDetermineType()) {
         $this->assertEquals(1, $record->getId());
         $this->assertEquals('foobar', $record->getTitle());
         $this->assertTrue($record->getActive());
         $this->assertFalse($record->getDisabled());
         $this->assertEquals(12, $record->getCount());
         $this->assertEquals(12.45, $record->getRating());
         $this->assertInternalType('integer', $record->getId());
         $this->assertInternalType('string', $record->getTitle());
         $this->assertInternalType('boolean', $record->getActive());
         $this->assertInternalType('boolean', $record->getDisabled());
         $this->assertInternalType('integer', $record->getCount());
         $this->assertInternalType('float', $record->getRating());
         $this->assertInstanceOf('DateTime', $record->getDate());
     } else {
         $this->assertEquals('1', $record->getId());
         $this->assertEquals('foobar', $record->getTitle());
         // the json reader returns the real php type the xml reader returns
         // the string true or false
         $this->assertTrue($record->getActive() === true || $record->getActive() === 'true');
         $this->assertTrue($record->getDisabled() === false || $record->getDisabled() === 'false');
         $this->assertEquals('12', $record->getCount());
         $this->assertEquals('12.45', $record->getRating());
         $this->assertEquals('2014-01-01T12:34:47+01:00', $record->getDate());
     }
     if ($this->canImportComplexRecord()) {
         $this->assertInstanceOf('PSX\\Data\\Record\\Importer\\Test\\Person', $record->getPerson());
         $this->assertEquals('Foo', $record->getPerson()->getTitle());
         $this->assertEquals(true, is_array($record->getTags()));
         $this->assertEquals(3, count($record->getTags()));
         $this->assertEquals('bar', $record->getTags()[0]);
         $this->assertEquals('foo', $record->getTags()[1]);
         $this->assertEquals('test', $record->getTags()[2]);
         $this->assertEquals(true, is_array($record->getEntry()));
         $this->assertEquals(3, count($record->getEntry()));
         $this->assertEquals('bar', $record->getEntry()[0]->getTitle());
         $this->assertEquals('foo', $record->getEntry()[1]->getTitle());
         $this->assertEquals('test', $record->getEntry()[2]->getTitle());
         foreach ($record->getEntry() as $entry) {
             $this->assertInstanceOf('PSX\\Data\\Record\\Importer\\Test\\Entry', $entry);
         }
         $this->assertInstanceOf('stdClass', $record->getToken());
         $this->assertEquals('bar', $record->getToken()->value);
         $this->assertInstanceOf('PSX\\Url', $record->getUrl());
         $this->assertEquals('http://google.com', $record->getUrl()->__toString());
     }
 }