Skip to content

Commit

Permalink
Adopt PHP attributes in test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
laravel-shift committed Jul 3, 2024
1 parent dc0c560 commit b4f3d69
Show file tree
Hide file tree
Showing 25 changed files with 273 additions and 246 deletions.
9 changes: 5 additions & 4 deletions tests/Api/BioApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Tests\Api;

use PHPUnit\Framework\Attributes\Test;
use App\Models\Bio;

class BioApiTest extends ApiTestCase
{
/** @test */
#[Test]
public function can_fetch_all_user_bios(): void
{
$response = $this->call('GET', '/api/user/1/bios');
Expand All @@ -16,7 +17,7 @@ public function can_fetch_all_user_bios(): void
$this->assertIsArray($data->data);
}

/** @test */
#[Test]
public function can_fetch_one_user_bio(): void
{
$bioId = Bio::first()->id;
Expand All @@ -27,15 +28,15 @@ public function can_fetch_one_user_bio(): void
$this->assertIsObject($data->data);
}

/** @test */
#[Test]
public function cannot_fetch_all_bios_for_other_user(): void
{
$response = $this->call('GET', 'api/user/2/bios');

$this->assertEquals(404, $response->getStatusCode());
}

/** @test */
#[Test]
public function cannot_fetch_one_bio_for_other_user(): void
{
$bioId = Bio::where('user_id', 2)->first()->id;
Expand Down
11 changes: 6 additions & 5 deletions tests/Api/ConferenceApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Tests\Api;

use PHPUnit\Framework\Attributes\Test;
use App\Models\Conference;

class ConferenceApiTest extends ApiTestCase
{
/** @test */
#[Test]
public function can_fetch_all_conferences(): void
{
$response = $this->call('GET', 'api/conferences');
Expand All @@ -16,7 +17,7 @@ public function can_fetch_all_conferences(): void
$this->assertIsArray($data->data);
}

/** @test */
#[Test]
public function can_fetch_one_conference(): void
{
$conferenceId = Conference::first()->id;
Expand All @@ -27,7 +28,7 @@ public function can_fetch_one_conference(): void
$this->assertIsObject($data->data);
}

/** @test */
#[Test]
public function cfp_url_returns_if_set(): void
{
$conference = Conference::create([
Expand All @@ -44,7 +45,7 @@ public function cfp_url_returns_if_set(): void
$this->assertEquals('http://awesome.com/cfp', $data->data->attributes->cfp_url);
}

/** @test */
#[Test]
public function cfp_url_returns_null_on_api_if_not_set(): void
{
$conference = Conference::create([
Expand All @@ -60,7 +61,7 @@ public function cfp_url_returns_null_on_api_if_not_set(): void
$this->assertNull($data->data->attributes->cfp_url);
}

/** @test */
#[Test]
public function unclosed_cfp_returns_open_and_future_cfp(): void
{
Conference::factory()
Expand Down
4 changes: 3 additions & 1 deletion tests/Api/JsonApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Tests\Api;

use PHPUnit\Framework\Attributes\Test;

class JsonApiTest extends ApiTestCase
{
/** @test */
#[Test]
public function uses_correct_json_api_header(): void
{
$response = $this->call('GET', '/api/user/1/talks');
Expand Down
4 changes: 3 additions & 1 deletion tests/Api/MeApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Tests\Api;

use PHPUnit\Framework\Attributes\Test;

class MeApiTest extends ApiTestCase
{
/** @test */
#[Test]
public function can_fetch_my_info(): void
{
$response = $this->call('GET', 'api/me');
Expand Down
17 changes: 9 additions & 8 deletions tests/Api/TalkApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Tests\Api;

use PHPUnit\Framework\Attributes\Test;
use App\Models\Talk;
use App\Models\TalkRevision;

class TalkApiTest extends ApiTestCase
{
/** @test */
#[Test]
public function can_fetch_all_talks_for_user(): void
{
$response = $this->call('GET', 'api/user/1/talks');
Expand All @@ -17,7 +18,7 @@ public function can_fetch_all_talks_for_user(): void
$this->assertCount(2, $data->data);
}

/** @test */
#[Test]
public function all_talks_doesnt_return_archived_talks(): void
{
$toBeArchivedTalk = $this->user->talks()->create([]);
Expand All @@ -36,7 +37,7 @@ public function all_talks_doesnt_return_archived_talks(): void
$this->assertCount(2, $data->data);
}

/** @test */
#[Test]
public function including_archived_talks(): void
{
Talk::factory()
Expand All @@ -50,7 +51,7 @@ public function including_archived_talks(): void
$response->assertJsonFragment(['title' => 'My Archived Talk']);
}

/** @test */
#[Test]
public function excluding_archived_talks(): void
{
Talk::factory()
Expand All @@ -64,7 +65,7 @@ public function excluding_archived_talks(): void
$response->assertJsonMissing(['title' => 'My Archived Talk']);
}

/** @test */
#[Test]
public function all_talks_return_alpha_sorted(): void
{
$response = $this->call('GET', 'api/user/1/talks');
Expand All @@ -76,7 +77,7 @@ public function all_talks_return_alpha_sorted(): void
$this->assertEquals('My great talk', $titles->last());
}

/** @test */
#[Test]
public function can_fetch_one_talk(): void
{
$talkId = Talk::first()->id;
Expand All @@ -87,15 +88,15 @@ public function can_fetch_one_talk(): void
$this->assertIsObject($data->data);
}

/** @test */
#[Test]
public function cannot_fetch_all_talks_for_other_users(): void
{
$response = $this->call('GET', 'api/user/2/talks');

$this->assertEquals(404, $response->getStatusCode());
}

/** @test */
#[Test]
public function cannot_fetch_one_talk_for_other_users(): void
{
$talkId = Talk::where('author_id', 2)->first()->id;
Expand Down
9 changes: 5 additions & 4 deletions tests/Console/Commands/TweetImportantCFPDatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Console\Commands;

use PHPUnit\Framework\Attributes\Test;
use App\Console\Commands\TweetImportantCFPDates;
use App\Models\Conference;
use Atymic\Twitter\ApiV1\Service\Twitter;
Expand All @@ -10,7 +11,7 @@

class TweetImportantCFPDatesTest extends TestCase
{
/** @test */
#[Test]
public function cfps_opening_today_should_be_tweeted(): void
{
// starts today, ends next week
Expand All @@ -25,7 +26,7 @@ public function cfps_opening_today_should_be_tweeted(): void
(new TweetImportantCFPDates($mock, 0))->handle();
}

/** @test */
#[Test]
public function cfps_closing_tomorrow_should_be_tweeted(): void
{
// started last week, ends tomorrow
Expand All @@ -40,7 +41,7 @@ public function cfps_closing_tomorrow_should_be_tweeted(): void
(new TweetImportantCFPDates($mock, 0))->handle();
}

/** @test */
#[Test]
public function cfps_not_opening_today_nor_closing_tomorrow_should_not_be_tweeted(): void
{
// started last week, ends next week
Expand All @@ -55,7 +56,7 @@ public function cfps_not_opening_today_nor_closing_tomorrow_should_not_be_tweete
(new TweetImportantCFPDates($mock, 0))->handle();
}

/** @test */
#[Test]
public function cfps_that_open_and_close_same_day_should_not_be_tweeted(): void
{
Conference::factory()->create([
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/AcceptanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests;

use PHPUnit\Framework\Attributes\Test;
use App\Models\Acceptance;
use App\Models\Conference;
use App\Models\Submission;
Expand All @@ -11,7 +12,7 @@

class AcceptanceTest extends TestCase
{
/** @test */
#[Test]
public function can_create_from_submission(): void
{
$user = User::factory()->create();
Expand All @@ -35,7 +36,7 @@ public function can_create_from_submission(): void
$this->assertEquals($submission->id, $acceptance->submission->id);
}

/** @test */
#[Test]
public function user_can_remove_acceptance_via_http(): void
{
$user = User::factory()->create();
Expand Down
25 changes: 13 additions & 12 deletions tests/Feature/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature;

use PHPUnit\Framework\Attributes\Test;
use App\Http\Livewire\ConferenceList;
use App\Models\Bio;
use App\Models\Conference;
Expand All @@ -18,7 +19,7 @@

class AccountTest extends TestCase
{
/** @test */
#[Test]
public function users_can_log_in(): void
{
$user = User::factory()->create(['password' => Hash::make('super-secret')]);
Expand All @@ -32,7 +33,7 @@ public function users_can_log_in(): void
$response->assertSessionDoesntHaveErrors('email');
}

/** @test */
#[Test]
public function logging_in_with_invalid_credentials(): void
{
$user = User::factory()->create();
Expand All @@ -46,7 +47,7 @@ public function logging_in_with_invalid_credentials(): void
$response->assertSessionHasErrors('email');
}

/** @test */
#[Test]
public function user_can_update_their_profile(): void
{
$user = User::factory()->create();
Expand Down Expand Up @@ -75,7 +76,7 @@ public function user_can_update_their_profile(): void
]);
}

/** @test */
#[Test]
public function user_can_update_their_profile_picture(): void
{
Storage::fake();
Expand All @@ -96,7 +97,7 @@ public function user_can_update_their_profile_picture(): void
Storage::disk()->assertExists(User::PROFILE_PICTURE_HIRES_PATH . $user->profile_picture);
}

/** @test */
#[Test]
public function password_reset_emails_are_sent_for_valid_users(): void
{
Notification::fake();
Expand All @@ -109,7 +110,7 @@ public function password_reset_emails_are_sent_for_valid_users(): void
Notification::assertSentTo($user, ResetPassword::class);
}

/** @test */
#[Test]
public function user_can_reset_their_password_from_email_link(): void
{
Notification::fake();
Expand Down Expand Up @@ -149,7 +150,7 @@ function ($notification, $channels) use (&$token) {
])->assertLocation('dashboard');
}

/** @test */
#[Test]
public function users_can_delete_their_accounts(): void
{
$user = User::factory()->create();
Expand All @@ -162,7 +163,7 @@ public function users_can_delete_their_accounts(): void
$this->assertModelMissing($user);
}

/** @test */
#[Test]
public function deleting_a_user_deletes_its_associated_entities(): void
{
$user = User::factory()->create();
Expand Down Expand Up @@ -204,7 +205,7 @@ public function deleting_a_user_deletes_its_associated_entities(): void
]);
}

/** @test */
#[Test]
public function users_can_dismiss_a_conference(): void
{
$user = User::factory()->create();
Expand All @@ -220,7 +221,7 @@ public function users_can_dismiss_a_conference(): void
]);
}

/** @test */
#[Test]
public function users_can_undismiss_a_conference(): void
{
$user = User::factory()->create();
Expand All @@ -236,7 +237,7 @@ public function users_can_undismiss_a_conference(): void
]);
}

/** @test */
#[Test]
public function users_can_favorite_a_conference(): void
{
$user = User::factory()->create();
Expand All @@ -252,7 +253,7 @@ public function users_can_favorite_a_conference(): void
]);
}

/** @test */
#[Test]
public function users_can_unfavorite_a_conference(): void
{
$user = User::factory()->create();
Expand Down
Loading

0 comments on commit b4f3d69

Please sign in to comment.