|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Http\Controllers; |
| 4 | + |
| 5 | +use App\Certificate; |
| 6 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 7 | +use Illuminate\Foundation\Testing\WithFaker; |
| 8 | +use JMac\Testing\Traits\AdditionalAssertions; |
| 9 | +use Tests\TestCase; |
| 10 | + |
| 11 | +/** |
| 12 | + * @see \App\Http\Controllers\CertificateController |
| 13 | + */ |
| 14 | +class CertificateControllerTest extends TestCase |
| 15 | +{ |
| 16 | + use AdditionalAssertions, RefreshDatabase, WithFaker; |
| 17 | + |
| 18 | + /** |
| 19 | + * @test |
| 20 | + */ |
| 21 | + public function index_behaves_as_expected() |
| 22 | + { |
| 23 | + $certificates = factory(Certificate::class, 3)->create(); |
| 24 | + |
| 25 | + $response = $this->get(route('certificate.index')); |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + /** |
| 30 | + * @test |
| 31 | + */ |
| 32 | + public function store_uses_form_request_validation() |
| 33 | + { |
| 34 | + $this->assertActionUsesFormRequest( |
| 35 | + \App\Http\Controllers\CertificateController::class, |
| 36 | + 'store', |
| 37 | + \App\Http\Requests\CertificateStoreRequest::class |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @test |
| 43 | + */ |
| 44 | + public function store_saves() |
| 45 | + { |
| 46 | + $name = $this->faker->name; |
| 47 | + $certificate_type_id = $this->faker->randomDigitNotNull; |
| 48 | + $reference = $this->faker->word; |
| 49 | + $document = $this->faker->word; |
| 50 | + $expiry_date = $this->faker->date(); |
| 51 | + |
| 52 | + $response = $this->post(route('certificate.store'), [ |
| 53 | + 'name' => $name, |
| 54 | + 'certificate_type_id' => $certificate_type_id, |
| 55 | + 'reference' => $reference, |
| 56 | + 'document' => $document, |
| 57 | + 'expiry_date' => $expiry_date, |
| 58 | + ]); |
| 59 | + |
| 60 | + $certificates = Certificate::query() |
| 61 | + ->where('name', $name) |
| 62 | + ->where('certificate_type_id', $certificate_type_id) |
| 63 | + ->where('reference', $reference) |
| 64 | + ->where('document', $document) |
| 65 | + ->where('expiry_date', $expiry_date) |
| 66 | + ->get(); |
| 67 | + $this->assertCount(1, $certificates); |
| 68 | + $certificate = $certificates->first(); |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + /** |
| 73 | + * @test |
| 74 | + */ |
| 75 | + public function show_behaves_as_expected() |
| 76 | + { |
| 77 | + $certificate = factory(Certificate::class)->create(); |
| 78 | + |
| 79 | + $response = $this->get(route('certificate.show', $certificate)); |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | + /** |
| 84 | + * @test |
| 85 | + */ |
| 86 | + public function update_uses_form_request_validation() |
| 87 | + { |
| 88 | + $this->assertActionUsesFormRequest( |
| 89 | + \App\Http\Controllers\CertificateController::class, |
| 90 | + 'update', |
| 91 | + \App\Http\Requests\CertificateUpdateRequest::class |
| 92 | + ); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @test |
| 97 | + */ |
| 98 | + public function update_behaves_as_expected() |
| 99 | + { |
| 100 | + $certificate = factory(Certificate::class)->create(); |
| 101 | + $name = $this->faker->name; |
| 102 | + $certificate_type_id = $this->faker->randomDigitNotNull; |
| 103 | + $reference = $this->faker->word; |
| 104 | + $document = $this->faker->word; |
| 105 | + $expiry_date = $this->faker->date(); |
| 106 | + |
| 107 | + $response = $this->put(route('certificate.update', $certificate), [ |
| 108 | + 'name' => $name, |
| 109 | + 'certificate_type_id' => $certificate_type_id, |
| 110 | + 'reference' => $reference, |
| 111 | + 'document' => $document, |
| 112 | + 'expiry_date' => $expiry_date, |
| 113 | + ]); |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | + /** |
| 118 | + * @test |
| 119 | + */ |
| 120 | + public function destroy_deletes_and_responds_with() |
| 121 | + { |
| 122 | + $certificate = factory(Certificate::class)->create(); |
| 123 | + |
| 124 | + $response = $this->delete(route('certificate.destroy', $certificate)); |
| 125 | + |
| 126 | + $response->assertOk(); |
| 127 | + |
| 128 | + $this->assertDeleted($certificate); |
| 129 | + } |
| 130 | +} |
0 commit comments