setItn(Random::str(12, 12, '0123456789'))); self::assertSame($builder, $builder->setPhone(Random::str(11, 11, '0123456789'))); $factory = new SelfEmployedRequestConfirmationFactory(); $confirmation = $factory->factoryFromArray(array('type' => SelfEmployedConfirmationType::REDIRECT)); self::assertSame($builder, $builder->setConfirmation($confirmation)); } /** * @throws Exception */ public function testBuildWithItn() { $builder = new SelfEmployedRequestBuilder(); $itn = Random::str(12, 12, '0123456789'); $builder->setItn($itn); $instance = $builder->build(); self::assertSame($itn, $instance->getItn()); self::assertNull($instance->getPhone()); self::assertNull($instance->getConfirmation()); } /** * @throws Exception */ public function testBuildWithPhone() { $builder = new SelfEmployedRequestBuilder(); $phone = Random::str(11, 11, '0123456789'); $builder->setPhone($phone); $instance = $builder->build(); self::assertNull($instance->getItn()); self::assertSame($phone, $instance->getPhone()); self::assertNull($instance->getConfirmation()); } /** * @dataProvider confirmationDataProvider * * @param $confirmation * @throws Exception */ public function testBuildWithConfirmation($confirmation) { $builder = new SelfEmployedRequestBuilder(); $builder->setItn(Random::str(12, 12, '0123456789')); $builder->setConfirmation($confirmation); $instance = $builder->build(); if (empty($confirmation)) { self::assertNull($instance->getConfirmation()); } elseif ($confirmation instanceof SelfEmployedRequestConfirmation) { self::assertSame($confirmation, $instance->getConfirmation()); } elseif (is_array($confirmation)) { self::assertEquals($confirmation, $instance->getConfirmation()->toArray()); } } public function testBuildEmpty() { $builder = new SelfEmployedRequestBuilder(); try { $builder->build(); } catch (InvalidRequestException $e) { return; } self::fail('Exception not thrown in build method'); } /** * @throws Exception */ public function testSetOptions() { $builder = new SelfEmployedRequestBuilder(); $builder->setOptions(array( 'itn' => Random::str(12, 12, '0123456789'), )); $instance = $builder->build(); self::assertTrue($instance instanceof SelfEmployedRequest); $builder->setOptions(array()); try { $builder->build(); } catch (InvalidRequestException $e) { try { $builder->setOptions('test'); } catch (Exception $e) { self::assertTrue($e instanceof InvalidArgumentException); return; } self::fail('Exception not thrown in setOptions method'); return; } self::fail('Exception not thrown in build method'); } /** * @dataProvider invalidConfirmationDataProvider * * @param $value */ public function testSetInvalidConfirmation($value) { $builder = new SelfEmployedRequestBuilder(); try { $builder->setConfirmation($value); } catch (Exception $e) { self::assertTrue($e instanceof InvalidArgumentException); return; } self::fail('Exception not thrown in setConfirmation method'); } /** * @return array * @throws Exception */ public function confirmationDataProvider() { $factory = new SelfEmployedRequestConfirmationFactory(); $result = array( array(null), array( $factory->factoryFromArray(array('type' => SelfEmployedConfirmationType::REDIRECT)), ), array( array('type' => SelfEmployedConfirmationType::REDIRECT), ), ); return $result; } /** * @return array * @throws Exception */ public function invalidConfirmationDataProvider() { return array( array(false), array(true), array(new stdClass()), array(Random::str(10)), ); } }