/** * Test transformNews(). */ public function testTransformNews() { $transformer = new Transformer(); // one $result = $transformer->transform(new News(['author' => 'overtrue', 'description' => 'foobar'])); $this->assertEquals(1, $result['ArticleCount']); $this->assertEquals(1, count($result['Articles'])); $this->assertEquals('foobar', $result['Articles'][0]['Description']); $this->assertArrayHasKey('Url', $result['Articles'][0]); $this->assertArrayNotHasKey('Author', $result['Articles'][0]); // more $articles = [new News(['author' => 'overtrue', 'description' => 'foobar']), new News(['author' => 'foo', 'description' => 'bar'])]; $result = $transformer->transform($articles); $this->assertEquals(2, $result['ArticleCount']); $this->assertEquals(2, count($result['Articles'])); $this->assertEquals('foobar', $result['Articles'][0]['Description']); $this->assertEquals('bar', $result['Articles'][1]['Description']); $this->assertArrayHasKey('Url', $result['Articles'][0]); $this->assertArrayNotHasKey('Author', $result['Articles'][0]); }
/** * Build reply XML. * * @param string $to * @param string $from * @param AbstractMessage $message * * @return string */ protected function buildReply($to, $from, $message) { $base = ['ToUserName' => $to, 'FromUserName' => $from, 'CreateTime' => time(), 'MsgType' => is_array($message) ? current($message)->getType() : $message->getType()]; $transformer = new Transformer(); return XML::build(array_merge($base, $transformer->transform($message))); }