build($options); $data = $serializer->serialize($instance); $expected = array(); if (!empty($options['itn'])) { $expected['itn'] = preg_replace('/\D/', '', $options['itn']); } if (!empty($options['phone'])) { $expected['phone'] = preg_replace('/\D/', '', $options['phone']); } if (!empty($options['confirmation'])) { $expected['confirmation'] = $instance->getConfirmation()->toArray(); } self::assertEquals($expected, $data); } /** * @return array * @throws Exception */ public function validDataProvider() { $result = array(); for ($i = 0; $i < 10; $i++) { $request = array(); $request['itn'] = (string)Random::int(1000000000, 9999999999); if (Random::bool()) { $request['phone'] = Random::str(1, 15, '0123456789'); } if (Random::bool()) { $request['confirmation'] = array( 'type' => Random::value(SelfEmployedConfirmationType::getValidValues()), ); } $result[] = array($request); } return $result; } public function testSerializeWithItnOnly() { $serializer = new SelfEmployedRequestSerializer(); $instance = SelfEmployedRequest::builder()->build(array( 'itn' => '1234567890', )); $data = $serializer->serialize($instance); $expected = array( 'itn' => '1234567890', ); self::assertEquals($expected, $data); } public function testSerializeWithPhoneOnly() { $serializer = new SelfEmployedRequestSerializer(); $instance = SelfEmployedRequest::builder()->build(array( 'phone' => '79000000000', )); $data = $serializer->serialize($instance); $expected = array( 'phone' => '79000000000', ); self::assertEquals($expected, $data); } public function testSerializeWithAllFields() { $serializer = new SelfEmployedRequestSerializer(); $instance = SelfEmployedRequest::builder()->build(array( 'itn' => '1234567890', 'phone' => '79000000000', 'confirmation' => array( 'type' => SelfEmployedConfirmationType::REDIRECT, ), )); $data = $serializer->serialize($instance); self::assertArrayHasKey('itn', $data); self::assertArrayHasKey('phone', $data); self::assertArrayHasKey('confirmation', $data); self::assertEquals('1234567890', $data['itn']); self::assertEquals('79000000000', $data['phone']); self::assertEquals( array('type' => SelfEmployedConfirmationType::REDIRECT), $data['confirmation'] ); } }