Browscap\Writer\CsvWriter::setFilter PHP Method

setFilter() public method

public setFilter ( Browscap\Filter\FilterInterface $filter ) : Browscap\Writer\WriterInterface
$filter Browscap\Filter\FilterInterface
return Browscap\Writer\WriterInterface
    public function setFilter(FilterInterface $filter)
    {
        $this->type = $filter;
        $this->outputProperties = [];
        return $this;
    }

Usage Example

Example #1
0
 /**
  * tests rendering the body of one section
  *
  * @group writer
  * @group sourcetest
  */
 public function testRenderSectionBodyIfNotSilent()
 {
     $this->object->setSilent(false);
     $section = ['Test' => 1, 'isTest' => true, 'abc' => 'bcd'];
     $expectedAgents = [0 => ['properties' => ['Test' => 'abc', 'abc' => true, 'alpha' => true]]];
     $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\CsvFormatter::class)->disableOriginalConstructor()->setMethods(['formatPropertyValue'])->getMock();
     $mockFormatter->expects(self::exactly(3))->method('formatPropertyValue')->will(self::returnArgument(0));
     self::assertSame($this->object, $this->object->setFormatter($mockFormatter));
     $mockFilter = $this->getMockBuilder(\Browscap\Filter\FullFilter::class)->disableOriginalConstructor()->setMethods(['isOutputProperty'])->getMock();
     $map = [['Test', $this->object, true], ['isTest', $this->object, false], ['abc', $this->object, true], ['alpha', $this->object, true]];
     $mockFilter->expects(self::exactly(7))->method('isOutputProperty')->will(self::returnValueMap($map));
     self::assertSame($this->object, $this->object->setFilter($mockFilter));
     $logger = $this->createMock(\Monolog\Logger::class);
     $this->object->setLogger($logger);
     self::assertSame($this->object, $this->object->renderSectionBody($section, $collection));
     self::assertSame('1,bcd,' . PHP_EOL, file_get_contents($this->file));
 }
All Usage Examples Of Browscap\Writer\CsvWriter::setFilter