setFilter() public method

public setFilter ( Browscap\Filter\FilterInterface $filter ) : Browscap\Writer\WriterInterface
$filter Browscap\Filter\FilterInterface
return Browscap\Writer\WriterInterface
コード例 #1
0
ファイル: JsonWriterTest.php プロジェクト: prox2k/browscap
 /**
  * tests rendering the body of one section
  *
  * @group writer
  * @group sourcetest
  */
 public function testRenderSectionBodyIfNotSilentWithDefaultPropertiesAsParent()
 {
     $this->object->setSilent(false);
     $section = array('Parent' => 'DefaultProperties', 'Comment' => '1', 'Win16' => true, 'Platform' => 'bcd');
     $sections = array('X2' => $section);
     $expectedAgents = array(0 => array('properties' => array('Comment' => '12', 'Win16' => true, 'Platform' => 'bcd')));
     $mockDivision = $this->getMock('\\Browscap\\Data\\Division', array('getUserAgents'), array(), '', false);
     $mockDivision->expects(self::once())->method('getUserAgents')->will(self::returnValue($expectedAgents));
     $mockCollection = $this->getMock('\\Browscap\\Data\\DataCollection', array('getDefaultProperties'), array(), '', false);
     $mockCollection->expects(self::once())->method('getDefaultProperties')->will(self::returnValue($mockDivision));
     $mockFormatter = $this->getMock('\\Browscap\\Formatter\\JsonFormatter', array('formatPropertyName', 'formatPropertyValue'), array(), '', false);
     $mockFormatter->expects(self::never())->method('formatPropertyName')->will(self::returnArgument(0));
     $mockFormatter->expects(self::once())->method('formatPropertyValue')->will(self::returnArgument(0));
     self::assertSame($this->object, $this->object->setFormatter($mockFormatter));
     $map = array(array('Comment', $this->object, true), array('Win16', $this->object, false), array('Platform', $this->object, true), array('Parent', $this->object, true));
     $mockFilter = $this->getMock('\\Browscap\\Filter\\StandardFilter', array('isOutputProperty'), array(), '', false);
     $mockFilter->expects(self::exactly(4))->method('isOutputProperty')->will(self::returnValueMap($map));
     self::assertSame($this->object, $this->object->setFilter($mockFilter));
     self::assertSame($this->object, $this->object->renderSectionBody($section, $mockCollection, $sections));
     self::assertSame('{"Parent":"DefaultProperties","Comment":"1"}', file_get_contents($this->file));
 }
コード例 #2
0
ファイル: JsonWriterTest.php プロジェクト: browscap/browscap
 /**
  * tests rendering the body of one section
  *
  * @group writer
  * @group sourcetest
  */
 public function testRenderSectionBodyIfNotSilentWithDefaultPropertiesAsParent()
 {
     $this->object->setSilent(false);
     $section = ['Parent' => 'DefaultProperties', 'Comment' => '1', 'Win16' => true, 'Platform' => 'bcd'];
     $sections = ['X2' => $section];
     $expectedAgents = [0 => ['properties' => ['Comment' => '12', 'Win16' => true, 'Platform' => 'bcd']]];
     $mockExpander = $this->getMockBuilder(\Browscap\Data\Expander::class)->disableOriginalConstructor()->setMethods(['trimProperty'])->getMock();
     $mockExpander->expects(self::any())->method('trimProperty')->will(self::returnArgument(0));
     self::assertSame($this->object, $this->object->setExpander($mockExpander));
     $division = $this->getMockBuilder(\Browscap\Data\Division::class)->disableOriginalConstructor()->setMethods(['getUserAgents'])->getMock();
     $division->expects(self::once())->method('getUserAgents')->will(self::returnValue($expectedAgents));
     $collection = $this->getMockBuilder(\Browscap\Data\DataCollection::class)->disableOriginalConstructor()->setMethods(['getDefaultProperties'])->getMock();
     $collection->expects(self::once())->method('getDefaultProperties')->will(self::returnValue($division));
     $mockFormatter = $this->getMockBuilder(\Browscap\Formatter\JsonFormatter::class)->disableOriginalConstructor()->setMethods(['formatPropertyName', 'formatPropertyValue'])->getMock();
     $mockFormatter->expects(self::never())->method('formatPropertyName')->will(self::returnArgument(0));
     $mockFormatter->expects(self::once())->method('formatPropertyValue')->will(self::returnArgument(0));
     self::assertSame($this->object, $this->object->setFormatter($mockFormatter));
     $map = [['Comment', $this->object, true], ['Win16', $this->object, false], ['Platform', $this->object, true], ['Parent', $this->object, true]];
     $mockFilter = $this->getMockBuilder(\Browscap\Filter\StandardFilter::class)->disableOriginalConstructor()->setMethods(['isOutputProperty'])->getMock();
     $mockFilter->expects(self::exactly(4))->method('isOutputProperty')->will(self::returnValueMap($map));
     self::assertSame($this->object, $this->object->setFilter($mockFilter));
     self::assertSame($this->object, $this->object->renderSectionBody($section, $collection, $sections));
     self::assertSame('{"Parent":"DefaultProperties","Comment":"1"}', file_get_contents($this->file));
 }