public function testNormalizationJson() { $dateOfBirth = new \DateTime('1990-05-25'); $personalDetails = Entities\PersonalDetails::createFromArray(['firstName' => 'Personal', 'lastName' => 'DataUser', 'email' => '*****@*****.**', 'dateOfBirth' => $dateOfBirth, 'phoneNumber' => '01202 000001', 'houseNumber' => '1', 'street' => 'Street', 'area' => 'Bournemouth', 'city' => 'Bournemouth', 'county' => 'Dorset', 'postcode' => 'BH1 1AA']); $normalized = $this->extension->normalize($this->serializer, $personalDetails, 'json'); $this->assertEquals($this->getNormalizedForJson(), $normalized); }
public function denormalize($serializer, $data, $format = null, array $context = []) { if ($format === 'json') { if (!is_null($data['dob'])) { $dateOfBirth = new \DateTime($data['dob'], new \DateTimeZone('UTC')); } else { $dateOfBirth = null; } $data = ['firstName' => $data['first_name'], 'lastName' => $data['last_name'], 'dateOfBirth' => $dateOfBirth, 'houseNumber' => $data['housenumber'], 'street' => $data['street'], 'area' => $data['town'], 'city' => $data['city'], 'county' => $data['county'], 'postcode' => $data['postcode'], 'phoneNumber' => $data['telephone']]; } $denormalized = PersonalDetails::createFromArray($data); return $denormalized; }
/** * @dataProvider postCodeProvider */ public function testPostCodeValidation($postCode, $errorsPresent) { $dateOfBirth = new \DateTime('1990-05-25'); $personalDetails = PersonalDetails::createFromArray(['firstName' => 'Personal', 'lastName' => 'DataUser', 'dateOfBirth' => $dateOfBirth, 'phoneNumber' => '01202 000001', 'houseNumber' => '1', 'street' => 'Street', 'area' => 'Bournemouth', 'city' => 'Bournemouth', 'county' => 'Dorset', 'postcode' => $postCode]); $this->assertEquals($errorsPresent, (bool) count($this->validator->validate($personalDetails))); }