public function testUnderscoreKeys() { $item = new ParameterBag(['testScore' => 'test', 'test1Score' => 'test', '2TestScore' => 'test', '3test_Score' => 'test', '4test-Score' => 'test', 'TesTScore' => 'test', 'testscore' => ['underScore' => 'test']]); $transformer = new UnderscoreKeysTransformer(); $transformer->transform($item); $this->assertEquals(['test_score' => 'test', 'test1score' => 'test', '2test_score' => 'test', '3test_score' => 'test', '4test_score' => 'test', 'tes_tscore' => 'test', 'testscore' => ['under_score' => 'test']], $item->all()); }
/** * Returns the names of all mapped and extra mapped fields. These are the * fields that are allowed in the resulting item. The fields are * normalized to be lowercased and underscored (instead of dashes). * * @return array */ protected function getMappedFields() { $fields = array_diff(array_unique(array_merge(array_values($this->getEntityFields()), array_values($this->getExtraMappedFields()), array_values($this->getMapping()))), $this->getUnmappedFields()); $fields = new ParameterBag(array_flip($fields)); // make sure id is not in it $fields->remove('id'); $transformer = new UnderscoreKeysTransformer(); $transformer->transform($fields); return $fields->keys(); }