protected function execute(InputInterface $input, OutputInterface $output) { $in = $input->getArgument('in'); if (!is_readable($in)) { throw new \InvalidArgumentException("in must be a readable file or directory"); } $this->setupDriver($input->getOption("builtinannot")); $config = $this->generateConfigs($in); $json = $this->mapper->writeString($config, '\\Weasel\\JsonMarshaller\\Config\\ClassMarshaller[string]'); if ($out = $input->getArgument("out")) { file_put_contents($out, $json); } else { print $json; } }
/** * Test to show that something that PHP would normally think is an "array" gets encoded as a map when we ask for that. * @covers \Weasel\JsonMarshaller\JsonMapper */ public function testWriteStringMapIntKeysLooksLikeArray() { $configProvider = new MockedConfigProvider(); $mtc = 'Weasel\\JsonMarshaller\\MockTestClass'; $config = new Config\ClassMarshaller(); $this->addPropConfig($config, "blah", "string"); $configProvider->fakeConfig[$mtc] = $config; $mapper = new JsonMapper($configProvider); $result = $mapper->writeString(array(123, 34, 99), 'int[int]'); $expected = '{"0": 123, "1": 34, "2": 99}'; $this->assertEquals($expected, $result); }