public function test_Should_DeserializeGivenJsonFormattedStringToObject()
    {
        $inputBugJson = <<<EOF
{"severity":"loss of functionality","version_affected":"1.0"}
EOF;
        $serializer = new JsonSerializer();
        $actualBug = $serializer->deserialize($inputBugJson, Bug::class);
        $expectedBug = new Bug();
        $expectedBug->setSeverity('loss of functionality');
        $expectedBug->setVersionAffected('1.0');
        $this->assertEquals($expectedBug, $actualBug);
    }
    public function test_Should_DeserializeGivenXmlFormattedStringToObject()
    {
        $inputBugXml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<result>
  <severity><![CDATA[loss of functionality]]></severity>
  <version_affected><![CDATA[1.0]]></version_affected>
</result>

EOF;
        $serializer = new XmlSerializer();
        $actualBug = $serializer->deserialize($inputBugXml, Bug::class);
        $expectedBug = new Bug();
        $expectedBug->setSeverity('loss of functionality');
        $expectedBug->setVersionAffected('1.0');
        $this->assertEquals($expectedBug, $actualBug);
    }
 public function test_Should_SetSerializationOfAttribute_When_StoringSubtypesOfObjectInOneTable()
 {
     // issue_type is 'bug'.
     $bug = new Bug();
     $bug->setSeverity('loss of functionality');
     $bug->setVersionAffected('1.0');
     $issueBug = new Issue();
     $issueBug->reported_by = 1;
     $issueBug->product_id = 1;
     $issueBug->priority = 'high';
     $issueBug->version_resolved = null;
     $issueBug->status = 'new';
     $issueBug->issue_type = 'bug';
     $issueBug->attributes = $bug;
     $issueBug->save();
     // issue_type is 'feature'.
     $featureRequest = new FeatureRequest();
     $featureRequest->setSponsor('Sponsor');
     $issueFeature = new Issue();
     $issueFeature->reported_by = 1;
     $issueFeature->product_id = 1;
     $issueFeature->priority = 'high';
     $issueFeature->version_resolved = null;
     $issueFeature->status = 'new';
     $issueFeature->issue_type = 'feature';
     $issueFeature->attributes = $featureRequest;
     $issueFeature->save();
     $createdIssueTypeBug = $this->db->table('issues')->where('id', 1)->first();
     $createdIssueTypeFeature = $this->db->table('issues')->where('id', 2)->first();
     $this->assertEquals(1, $createdIssueTypeBug->reported_by);
     $this->assertEquals(1, $createdIssueTypeBug->product_id);
     $this->assertEquals('high', $createdIssueTypeBug->priority);
     $this->assertEquals(null, $createdIssueTypeBug->version_resolved);
     $this->assertEquals('new', $createdIssueTypeBug->status);
     $this->assertEquals('bug', $createdIssueTypeBug->issue_type);
     $this->assertEquals('{"severity":"loss of functionality","version_affected":"1.0"}', $createdIssueTypeBug->attributes);
     $this->assertEquals(1, $createdIssueTypeFeature->reported_by);
     $this->assertEquals(1, $createdIssueTypeFeature->product_id);
     $this->assertEquals('high', $createdIssueTypeFeature->priority);
     $this->assertEquals(null, $createdIssueTypeFeature->version_resolved);
     $this->assertEquals('new', $createdIssueTypeFeature->status);
     $this->assertEquals('feature', $createdIssueTypeFeature->issue_type);
     $this->assertEquals('{"sponsor":"Sponsor"}', $createdIssueTypeFeature->attributes);
 }