/** * @covers ::setProperties * @covers ::getProperties * @covers ::addProperty */ public function testProperties() { $dataSet = new DataSet('JUC (Linux; U; 2.3*) UCWEB8.4*'); $dataSet->setProperties(['A' => 'x', 'B' => 'y']); static::assertSame(['A' => 'x', 'B' => 'y'], $dataSet->getProperties()); $dataSet->addProperty('C', 'z'); static::assertSame(['A' => 'x', 'B' => 'y', 'C' => 'z'], $dataSet->getProperties()); $dataSet->setProperties(['A' => 'x', 'B' => 'y']); static::assertSame(['A' => 'x', 'B' => 'y'], $dataSet->getProperties()); }
/** * @param string $data * * @return DataSet * @throws ParserRuntimeException */ protected function getDataSetFromString(string $data) : DataSet { if (strpos($data, "\n") === false) { throw new ParserRuntimeException('The data could not be parsed (no pattern found).', 1459589758); } if (strpos($data, "\r\n") !== false) { // if the source file was created under windows, replace the line endings $data = str_replace("\r\n", "\n", $data); } // Prepare the data from the data set list($pattern, $properties) = explode("\n", $data, 2); $pattern = substr($pattern, 1, -1); $properties = @parse_ini_string($properties); if ($properties === false) { throw new ParserRuntimeException("The data could not be parsed (invalid properties for pattern '{$pattern}').", 1459589759); } $dataSet = new DataSet($pattern); $dataSet->setProperties($properties); return $dataSet; }