This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
#89 - unit tests #104
Open
Anna-Sokolowska
wants to merge
13
commits into
main
Choose a base branch
from
#89-unit-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
#89 - unit tests #104
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bd8c792
#89 - unit tests init
Anna-Sokolowska 8120c8d
Merge branch 'main' into #89-unit-tests
Anna-Sokolowska dbcba11
#89 - basic features tests
Anna-Sokolowska 7d7edd2
Merge branch 'main' into #89-unit-tests
Anna-Sokolowska 5ae0b73
#89 - cs-fix
Anna-Sokolowska a851f81
Merge branch 'main' into #89-unit-tests
Anna-Sokolowska 202c4d7
#89 - refactor tests
Anna-Sokolowska d95551e
#89 - add .env.ci
Anna-Sokolowska 86a33bb
#89 - add cache views
Anna-Sokolowska d6cd834
#89 - add organization profile scope bindings
Anna-Sokolowska 56b5dfd
#89 - fix wrong admin invitation receiver
Anna-Sokolowska 88dc366
Merge remote-tracking branch 'origin/#89-unit-tests' into #89-unit-tests
Anna-Sokolowska 5dd4a7e
#89 - cs-fix
Anna-Sokolowska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
APP_NAME=Laravel | ||
APP_ENV=testing | ||
APP_KEY=base64:fDr4dLzbpxwzo9eDpy8of5b6/Dt2Pnvnd3lng8cf348= | ||
APP_DEBUG=true | ||
APP_URL=http://localhost | ||
APP_TIMEZONE='Europe/Warsaw' | ||
|
||
LOG_CHANNEL=stack | ||
LOG_LEVEL=debug | ||
|
||
BROADCAST_DRIVER=log | ||
CACHE_DRIVER=file | ||
FILESYSTEM_DRIVER=local | ||
QUEUE_CONNECTION=redis | ||
SESSION_DRIVER=file | ||
SESSION_LIFETIME=120 | ||
|
||
MEMCACHED_HOST=memcached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$app = new Illuminate\Foundation\Application( | ||
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__) | ||
); | ||
|
||
$app->singleton( | ||
Illuminate\Contracts\Http\Kernel::class, | ||
Blumilk\Meetup\Core\Http\Kernel::class | ||
); | ||
|
||
$app->singleton( | ||
Illuminate\Contracts\Console\Kernel::class, | ||
Blumilk\Meetup\Core\Console\Kernel::class | ||
); | ||
|
||
$app->singleton( | ||
Illuminate\Contracts\Debug\ExceptionHandler::class, | ||
Blumilk\Meetup\Core\Exceptions\Handler::class | ||
); | ||
|
||
return $app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests; | ||
|
||
use Illuminate\Contracts\Console\Kernel; | ||
use Illuminate\Foundation\Application; | ||
|
||
trait CreatesApplication | ||
{ | ||
public function createApplication(): Application | ||
{ | ||
$app = require __DIR__ . "/../bootstrap/app.php"; | ||
|
||
$app->make(Kernel::class)->bootstrap(); | ||
|
||
return $app; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature; | ||
|
||
use Blumilk\Meetup\Core\Models\Contact; | ||
use Blumilk\Meetup\Core\Notifications\ContactEmailNotification; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Notification; | ||
use Tests\TestCase; | ||
|
||
class ContactTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function testUserCanSeeContactPage(): void | ||
{ | ||
$this->get("/contact") | ||
->assertOk(); | ||
} | ||
|
||
public function testUserCanSendContactForm(): void | ||
{ | ||
Notification::fake(); | ||
|
||
$this->post("/contact", [ | ||
"name" => "John", | ||
"email" => "[email protected]", | ||
"subject" => "Test subject", | ||
"message" => "Test message", | ||
]) | ||
->assertSessionHasNoErrors(); | ||
|
||
$this->assertDatabaseHas("contacts", [ | ||
"name" => "John", | ||
"email" => "[email protected]", | ||
"subject" => "Test subject", | ||
"message" => "Test message", | ||
]); | ||
|
||
$contact = Contact::query()->first(); | ||
|
||
Notification::assertSentTo([$contact], ContactEmailNotification::class); | ||
} | ||
|
||
public function testContactFormDataIsRequired(): void | ||
{ | ||
$this->post("/contact") | ||
->assertInvalid([ | ||
"name", | ||
"email", | ||
"subject", | ||
"message", | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature; | ||
|
||
use Blumilk\Meetup\Core\Models\User; | ||
use Blumilk\Meetup\Core\Notifications\InvitationEmailNotification; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Notification; | ||
use Spatie\Permission\Models\Role; | ||
use Tests\TestCase; | ||
|
||
class InviteAdminTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public User $admin; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Role::create(["name" => "admin"]); | ||
$this->admin = User::factory()->create()->assignRole("admin"); | ||
} | ||
|
||
public function testAdminCanSeeSendInvitationPage(): void | ||
{ | ||
$this->actingAs($this->admin) | ||
->get("/invitation") | ||
->assertOk(); | ||
} | ||
|
||
public function testAdminCanSendInvitation(): void | ||
{ | ||
Notification::fake(); | ||
|
||
$this->actingAs($this->admin) | ||
->post("/invitation", [ | ||
"email" => "[email protected]", | ||
]) | ||
->assertSessionHasNoErrors(); | ||
|
||
Notification::assertSentOnDemand( | ||
InvitationEmailNotification::class, | ||
fn ($notification, $channels, $notifiable) => $notifiable->routes["mail"] === "[email protected]", | ||
); | ||
} | ||
|
||
public function testUserCannotSendInvitation(): void | ||
{ | ||
$user = User::factory()->create(); | ||
|
||
$this->actingAs($user) | ||
->get("/invitation") | ||
->assertLocation("/"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Meetups; | ||
|
||
use Blumilk\Meetup\Core\Models\Meetup; | ||
use Blumilk\Meetup\Core\Models\User; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Spatie\Permission\Models\Role; | ||
use Tests\TestCase; | ||
|
||
class BrowseMeetupsTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public User $admin; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Role::create(["name" => "admin"]); | ||
$this->admin = User::factory()->create()->assignRole("admin"); | ||
} | ||
|
||
public function testUserCanSeeMeetupsList(): void | ||
{ | ||
$meetups = Meetup::factory() | ||
->count(15) | ||
->for($this->admin) | ||
->create(); | ||
|
||
$this->assertDatabaseCount("meetups", 15); | ||
|
||
$response = $this->get(route("meetups")) | ||
->assertOk(); | ||
|
||
foreach ($meetups as $meetup) { | ||
$response->assertSee($meetup->logo_path) | ||
->assertSee($meetup->title) | ||
->assertSee($meetup->date->toDateString()) | ||
->assertSee($meetup->place); | ||
} | ||
} | ||
|
||
public function testMeetupsListIsPaginated(): void | ||
{ | ||
Meetup::factory() | ||
->count(30) | ||
->for($this->admin) | ||
->create(); | ||
|
||
$meetups = Meetup::query() | ||
->latest() | ||
->skip(20) | ||
->take(10); | ||
|
||
$this->assertDatabaseCount("meetups", 30); | ||
|
||
$response = $this->get(route("meetups") . "?page=2") | ||
->assertOk(); | ||
|
||
foreach ($meetups as $meetup) { | ||
$response->assertSee($meetup->logo_path) | ||
->assertSee($meetup->title) | ||
->assertSee($meetup->date->format("Y-m-d h:i")) | ||
->assertSee($meetup->place); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need bootstrapping file. You can bootstrap application from
Blumilk\Meetup\Core\MeetupApplication
class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I get the RuntimeException "A facade root has not been set".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What facade do you want to use and where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nowhere, I just create object of MeetupApplication class and use getApplication method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't get it. Behat tests were working fine with this packaged app approach. Please take care about removing
/bootstrap/app.php
file and wire application in your test cases bootstrap.