From 8979ddc49d3111a2365407d600b07c09bcc14a19 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 13 Dec 2022 21:21:08 +0100 Subject: [PATCH] Lint tests --- tests/Feature/Subscription/StoreTest.php | 19 ++++----- .../SubscriptionRequestFactory.php | 42 +++++++++++++++++++ 2 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 tests/RequestFactories/SubscriptionRequestFactory.php diff --git a/tests/Feature/Subscription/StoreTest.php b/tests/Feature/Subscription/StoreTest.php index c6588684..3e6f973b 100644 --- a/tests/Feature/Subscription/StoreTest.php +++ b/tests/Feature/Subscription/StoreTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Subscription; use App\Fee; use Illuminate\Foundation\Testing\DatabaseTransactions; +use Tests\RequestFactories\SubscriptionRequestFactory; use Tests\TestCase; class StoreTest extends TestCase @@ -15,11 +16,10 @@ class StoreTest extends TestCase $this->withoutExceptionHandling()->login()->loginNami(); $fee = Fee::factory()->create(); - $response = $this->from('/subscription')->post('/subscription', [ - 'amount' => 2500, - 'fee_id' => $fee->id, - 'name' => 'Lorem', - ]); + $response = $this->from('/subscription')->post( + '/subscription', + SubscriptionRequestFactory::new()->amount(2500)->fee($fee)->name('lorem')->create() + ); $response->assertRedirect('/subscription'); $this->assertDatabaseHas('subscriptions', [ @@ -34,11 +34,10 @@ class StoreTest extends TestCase $this->login()->loginNami(); $fee = Fee::factory()->create(); - $response = $this->post('/subscription', [ - 'amount' => '', - 'fee_id' => 99, - 'name' => '', - ]); + $response = $this->post( + '/subscription', + SubscriptionRequestFactory::new()->invalid()->create() + ); $this->assertErrors([ 'amount' => 'Interner Beitrag ist erforderlich.', diff --git a/tests/RequestFactories/SubscriptionRequestFactory.php b/tests/RequestFactories/SubscriptionRequestFactory.php new file mode 100644 index 00000000..1be28522 --- /dev/null +++ b/tests/RequestFactories/SubscriptionRequestFactory.php @@ -0,0 +1,42 @@ + $this->faker->numberBetween(100, 2000), + 'fee_id' => Fee::factory()->create()->id, + 'name' => $this->faker->words(5, true), + ]; + } + + public function amount(int $amount): self + { + return $this->state(['amount' => $amount]); + } + + public function fee(Fee $fee): self + { + return $this->state(['fee_id' => $fee->id]); + } + + public function name(string $name): self + { + return $this->state(['name' => $name]); + } + + public function invalid(): self + { + return $this->state([ + 'amount' => '', + 'fee_id' => 9999, + 'name' => '', + ]); + } +}