. */ namespace Tests\Api\Models\BudgetLimit; use Faker\Factory; use Laravel\Passport\Passport; use Log; use Tests\TestCase; use Tests\Traits\CollectsValues; use Tests\Traits\RandomValues; use Tests\Traits\TestHelpers; /** * Class StoreControllerTest */ class StoreControllerTest extends TestCase { use RandomValues, TestHelpers, CollectsValues; /** * */ public function setUp(): void { parent::setUp(); Passport::actingAs($this->user()); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @param array $submission * * emptyDataProvider / storeDataProvider * @dataProvider storeDataProvider */ public function testStore(array $submission): void { if ([] === $submission) { $this->markTestSkipped('Empty data provider'); } // run account store with a minimal data set: $route = 'api.v1.budgets.limits.store'; $this->storeAndCompare($route, $submission); } /** * @return array */ public function emptyDataProvider(): array { return [[[]]]; } /** * @return array */ public function storeDataProvider(): array { $minimalSets = $this->minimalSets(); $optionalSets = $this->optionalSets(); $regenConfig = [ 'start' => function () { $faker = Factory::create(); return $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d'); }, 'end' => function () { $faker = Factory::create(); return $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'); }, ]; return $this->genericDataProvider($minimalSets, $optionalSets, $regenConfig); } /** * @return array */ private function minimalSets(): array { $faker = Factory::create(); return [ 'default_bl' => [ 'parameters' => [1], 'fields' => [ 'start' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d'), 'end' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'), 'amount' => number_format($faker->randomFloat(2, 10, 100), 2), ], ], ]; } /** * @return \array[][] */ private function optionalSets(): array { $faker = Factory::create(); $currencies = [ 1 => 'EUR', 2 => 'HUF', 3 => 'GBP', 4 => 'UAH', ]; $rand = rand(1, 4); return [ 'currency_id' => [ 'fields' => [ 'currency_id' => $rand, ], ], 'currency_code' => [ 'fields' => [ 'currency_code' => $currencies[$rand], ], ], 'start' => [ 'fields' => [ 'start' => $faker->dateTimeBetween('-2 year', '-1 year')->format('Y-m-d'), ], ], 'end' => [ 'fields' => [ 'end' => $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d'), ], ], 'amount' => [ 'fields' => [ 'amount' => number_format($faker->randomFloat(2, 10, 100), 2), ], ], ]; } }