/** * @test */ public function it_construct_a_valid_json_with_data() { $targetAdd = '{ "first_data":"first", "second_data":true }'; $targetSet = ' { "third_data":"third", "fourth_data":4 }'; $dataBuilder = new PayloadDataBuilder(); $dataBuilder->addData(['first_data' => 'first'])->addData(['second_data' => true]); $json = json_encode($dataBuilder->build()->toArray()); $this->assertJsonStringEqualsJsonString($targetAdd, $json); $dataBuilder->setData(['third_data' => 'third', 'fourth_data' => 4]); $json = json_encode($dataBuilder->build()->toArray()); $this->assertJsonStringEqualsJsonString($targetSet, $json); }
/** * PayloadData constructor. * * @param PayloadDataBuilder $builder */ public function __construct(PayloadDataBuilder $builder) { $this->data = $builder->getData(); }