/**
  * @testdox OptimizeObject tests
  * @dataProvider getOptimizeObjectTests
  */
 public function testOptimizeObject($original, $expected, $objects)
 {
     $encoder = new Encoder();
     $optimizer = new ConfigOptimizer($encoder);
     $config = $optimizer->optimize($original);
     $this->assertSame($expected, $encoder->encode($config));
     $this->assertSame(implode("\n", $objects), rtrim($optimizer->getVarDeclarations()));
 }
 /**
  * Inject the parser config into given source
  *
  * @param  string $src Parser's source
  * @return string      Modified source
  */
 protected function injectConfig($src)
 {
     $config = array_map([$this, 'encode'], $this->configOptimizer->optimize(['plugins' => $this->getPluginsConfig(), 'registeredVars' => $this->getRegisteredVarsConfig(), 'rootContext' => $this->getRootContext(), 'tagsConfig' => $this->getTagsConfig()]));
     $src = preg_replace_callback('/(\\nvar (' . implode('|', array_keys($config)) . '))(;)/', function ($m) use($config) {
         return $m[1] . '=' . $config[$m[2]] . $m[3];
     }, $src);
     // Prepend the deduplicated objects
     $src = $this->configOptimizer->getVarDeclarations() . $src;
     return $src;
 }