getTestInstance(); $paymentData = $instance->factory($type); self::assertNotNull($paymentData); self::assertInstanceOf(AbstractStatement::class, $paymentData); self::assertEquals($type, $paymentData->getType()); } /** * @dataProvider invalidTypeDataProvider * * @param mixed $type */ public function testInvalidFactory($type): void { $this->expectException(InvalidArgumentException::class); $instance = $this->getTestInstance(); $instance->factory($type); } /** * @dataProvider validArrayDataProvider */ public function testFactoryFromArray(array $options): void { $instance = $this->getTestInstance(); $paymentData = $instance->factoryFromArray($options); self::assertNotNull($paymentData); self::assertInstanceOf(AbstractStatement::class, $paymentData); foreach ($options as $property => $value) { self::assertEquals($paymentData->{$property}, $value); } $type = $options['type']; unset($options['type']); $paymentData = $instance->factoryFromArray($options, $type); self::assertNotNull($paymentData); self::assertInstanceOf(AbstractStatement::class, $paymentData); self::assertEquals($type, $paymentData->getType()); foreach ($options as $property => $value) { self::assertEquals($paymentData->{$property}, $value); } } /** * @dataProvider invalidDataArrayDataProvider * * @param mixed $options */ public function testInvalidFactoryFromArray($options): void { $this->expectException(InvalidArgumentException::class); $instance = $this->getTestInstance(); $instance->factoryFromArray($options); } public static function validTypeDataProvider(): array { $result = []; foreach (StatementType::getEnabledValues() as $value) { $result[] = [$value]; } return $result; } public static function invalidTypeDataProvider(): array { return [ [''], [0], [1], [-1], ['5'], [Random::str(10)], ]; } public static function validArrayDataProvider(): array { return [ [ [ 'type' => StatementType::PAYMENT_OVERVIEW, 'delivery_method' => new DeliveryMethodEmail([ 'email' => Factory::create()->email, ]), ], [ 'type' => StatementType::PAYMENT_OVERVIEW, 'delivery_method' => [ 'email' => Factory::create()->email, ], ], ], ]; } public static function invalidDataArrayDataProvider(): array { return [ [[]], [['type' => 'test']], [ [ 'type' => StatementType::PAYMENT_OVERVIEW, 'delivery_method' => Factory::create()->text(20), ], ], [ [ 'type' => StatementType::PAYMENT_OVERVIEW, 'delivery_method' => Factory::create()->text(20), ], ], [ [ 'type' => 'test', ], ], ]; } protected function getTestInstance(): StatementFactory { return new StatementFactory(); } }