Skip to content

Commit f3016de

Browse files
committed
Split LaravelModuleCest.php
1 parent 8540164 commit f3016de

12 files changed

+924
-649
lines changed

composer.lock

Lines changed: 391 additions & 246 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Functional;
6+
7+
use App\Models\User;
8+
use App\Repository\UserRepositoryInterface;
9+
use Tests\FunctionalTester;
10+
11+
final class AuthenticationCest
12+
{
13+
public function amActingAs(FunctionalTester $I)
14+
{
15+
// TODO
16+
}
17+
18+
public function amLoggedAs(FunctionalTester $I)
19+
{
20+
$userRepository = app()->get(UserRepositoryInterface::class);
21+
$user = $userRepository->create();
22+
$I->amLoggedAs($user);
23+
$I->amOnPage('/home');
24+
$I->see('You are logged in!');
25+
$I->amOnPage('/');
26+
$I->seeAuthentication();
27+
}
28+
29+
public function assertAuthenticatedAs(FunctionalTester $I)
30+
{
31+
// TODO
32+
}
33+
34+
public function assertCredentials(FunctionalTester $I)
35+
{
36+
// TODO
37+
}
38+
39+
public function assertInvalidCredentials(FunctionalTester $I)
40+
{
41+
// TODO
42+
}
43+
44+
public function dontSeeAuthentication(FunctionalTester $I)
45+
{
46+
$I->amOnPage('/home');
47+
$I->dontSeeAuthentication();
48+
}
49+
50+
public function logout(FunctionalTester $I)
51+
{
52+
// TODO
53+
}
54+
55+
public function seeAuthentication(FunctionalTester $I)
56+
{
57+
$I->amLoggedAs([
58+
'email' => 'john_doe@gmail.com',
59+
'password' => '123456'
60+
]);
61+
$I->amOnPage('/');
62+
$I->seeRecord(User::class, ['email' => 'john_doe@gmail.com']);
63+
64+
$I->seeAuthentication();
65+
}
66+
}

tests/Functional/ConsoleCest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Functional;
6+
7+
use App\Models\User;
8+
use Tests\FunctionalTester;
9+
10+
final class ConsoleCest
11+
{
12+
public function callArtisan(FunctionalTester $I)
13+
{
14+
$output = $I->callArtisan('app:create-user', [
15+
'Name' => 'Jane Doe',
16+
'Email' => 'jane_doe@gmail.com',
17+
'Password' => '123456'
18+
]);
19+
20+
$I->seeRecord(User::class, ['email' => 'jane_doe@gmail.com']);
21+
$I->assertEquals('User created!', $output);
22+
}
23+
}

tests/Functional/ContainerCest.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Functional;
6+
7+
use App\Utils\Contracts\StringConverterInterface;
8+
use App\Utils\Repeat;
9+
use App\Utils\ToUppercase;
10+
use Illuminate\Contracts\Config\Repository as Config;
11+
use Illuminate\Contracts\Http\Kernel;
12+
use Illuminate\Foundation\Application;
13+
use Tests\FunctionalTester;
14+
15+
final class ContainerCest
16+
{
17+
public function clearApplicationHandlers(FunctionalTester $I)
18+
{
19+
$I->haveApplicationHandler(function(Application $app): void {
20+
$config = $app->get(Config::class);
21+
$config->set('test_value', 15);
22+
});
23+
$I->amOnPage('/test-value');
24+
$I->see('Test value is: 15');
25+
26+
$I->clearApplicationHandlers();
27+
$I->amOnPage('/test-value');
28+
$I->see('Test value is: 5'); // 5 is the default value
29+
}
30+
31+
public function getApplication(FunctionalTester $I)
32+
{
33+
$I->assertInstanceOf(Application::class, $I->getApplication());
34+
}
35+
36+
public function grabService(FunctionalTester $I)
37+
{
38+
$kernel = $I->grabService(Kernel::class);
39+
$I->assertInstanceOf('App\Http\Kernel', $kernel);
40+
}
41+
42+
public function haveApplicationHandler(FunctionalTester $I)
43+
{
44+
$I->haveApplicationHandler(function(Application $app): void {
45+
$config = $app->get(Config::class);
46+
$config->set('test_value', 10);
47+
});
48+
$I->amOnPage('/test-value');
49+
$I->see('Test value is: 10');
50+
}
51+
52+
public function haveBinding(FunctionalTester $I)
53+
{
54+
$I->haveBinding(StringConverterInterface::class, ToUppercase::class);
55+
56+
$I->amOnPage('/service-container');
57+
$expected = sprintf("//p[text()='%s']", 'STRING TO CONVERT');
58+
$I->seeElement($expected);
59+
}
60+
61+
public function haveContextualBinding(FunctionalTester $I)
62+
{
63+
$I->haveContextualBinding(
64+
Repeat::class,
65+
'$times',
66+
2 // 3 is the default
67+
);
68+
$I->haveBinding(StringConverterInterface::class, Repeat::class);
69+
70+
$I->amOnPage('/service-container');
71+
$expected = sprintf("//p[text()='%s']", 'String To ConvertString To Convert');
72+
$I->seeElement($expected);
73+
}
74+
75+
public function haveInstance(FunctionalTester $I)
76+
{
77+
$converter = new ToUppercase();
78+
$I->haveInstance(StringConverterInterface::class, $converter);
79+
80+
$I->amOnPage('/service-container');
81+
$expected = sprintf("//p[text()='%s']", 'STRING TO CONVERT');
82+
$I->seeElement($expected);
83+
}
84+
85+
public function haveSingleton(FunctionalTester $I)
86+
{
87+
$I->haveSingleton(StringConverterInterface::class, ToUppercase::class);
88+
89+
$I->amOnPage('/service-container');
90+
$expected = sprintf("//p[text()='%s']", 'STRING TO CONVERT');
91+
$I->seeElement($expected);
92+
}
93+
94+
public function setApplication(FunctionalTester $I)
95+
{
96+
// TODO
97+
}
98+
}

tests/Functional/EloquentCest.php

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Functional;
6+
7+
use App\Models\User;
8+
use App\Repository\UserRepositoryInterface;
9+
use Illuminate\Database\Eloquent\Collection;
10+
use Tests\FunctionalTester;
11+
12+
final class EloquentCest
13+
{
14+
public function dontSeeRecord(FunctionalTester $I)
15+
{
16+
$I->disableEvents();
17+
18+
$I->amOnPage('/fire-event');
19+
$I->dontSeeRecord(User::class, ['email' => 'johndoe@example.com']);
20+
}
21+
22+
public function grabNumRecords(FunctionalTester $I)
23+
{
24+
$numRecords = $I->grabNumRecords(User::class);
25+
$I->assertSame(1, $numRecords);
26+
27+
$numRecords = $I->grabNumRecords('users');
28+
$I->assertSame(1, $numRecords);
29+
}
30+
31+
public function grabRecord(FunctionalTester $I)
32+
{
33+
$I->haveRecord(User::class, [
34+
'name' => 'Jane Doe',
35+
'email' => 'jane_doe@gmail.com',
36+
'password' => 'password',
37+
'created_at' => '',
38+
'updated_at' => '',
39+
]);
40+
41+
// Grab record with table name
42+
$record = $I->grabRecord('users', ['email' => 'jane_doe@gmail.com']);
43+
$I->assertTrue(is_array($record));
44+
45+
// Grab record with model class
46+
$model = $I->grabRecord(User::class, ['email' => 'jane_doe@gmail.com']);
47+
$I->assertTrue($model instanceof User);
48+
}
49+
50+
public function have(FunctionalTester $I)
51+
{
52+
$user = $I->have(User::class, ['email' => 'johndoe@example.com']);
53+
54+
$I->assertEquals('johndoe@example.com', $user->email);
55+
$I->seeRecord('users', ['email' => 'johndoe@example.com']);
56+
}
57+
58+
public function haveMultiple(FunctionalTester $I)
59+
{
60+
$I->haveMultiple(User::class, 3);
61+
62+
$I->seeNumRecords(4, User::class);
63+
}
64+
65+
public function haveRecord(FunctionalTester $I)
66+
{
67+
$emails = [
68+
'users' => 'bonnie@gmail.com',
69+
User::class => 'clyde@gmail.com'
70+
];
71+
72+
foreach ($emails as $table => $email) {
73+
$I->haveRecord($table, [
74+
'name' => 'John Doe',
75+
'email' => $email,
76+
'password' => 'password',
77+
'created_at' => '',
78+
'updated_at' => ''
79+
]);
80+
$I->seeRecord($table, ['email' => $email]);
81+
}
82+
}
83+
84+
public function make(FunctionalTester $I)
85+
{
86+
/** @var Collection $collection */
87+
$collection = $I->make(User::class, ['email' => 'johndoe@example.com']);
88+
89+
$I->assertInstanceOf(User::class, $collection->first());
90+
}
91+
92+
public function makeMultiple(FunctionalTester $I)
93+
{
94+
/** @var Collection $collection */
95+
$collection = $I->makeMultiple(User::class, 3);
96+
97+
$I->assertSame(3, $collection->count());
98+
}
99+
100+
public function seedDatabase(FunctionalTester $I)
101+
{
102+
// TODO
103+
}
104+
105+
public function seeNumRecords(FunctionalTester $I)
106+
{
107+
$I->seeNumRecords(1,'users');
108+
$I->seeNumRecords(1,User::class);
109+
}
110+
111+
public function seeRecord(FunctionalTester $I)
112+
{
113+
$userRepository = app()->get(UserRepositoryInterface::class);
114+
$userRepository->create([
115+
'email' => 'jane_doe@gmail.com',
116+
'password' => '123456'
117+
]);
118+
119+
$I->seeRecord('users', ['email' => 'jane_doe@gmail.com']);
120+
}
121+
}

tests/Functional/EventsCest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Functional;
6+
7+
use App\Events\TestEvent;
8+
use App\Models\User;
9+
use App\Repository\UserRepositoryInterface;
10+
use Tests\FunctionalTester;
11+
12+
final class EventsCest
13+
{
14+
public function disableEvents(FunctionalTester $I)
15+
{
16+
$I->disableEvents();
17+
18+
$I->amOnPage('/fire-event');
19+
$I->dontSeeRecord(User::class, ['email' => 'johndoe@example.com']);
20+
}
21+
22+
public function disableModelEvents(FunctionalTester $I)
23+
{
24+
$userRepository = app()->get(UserRepositoryInterface::class);
25+
$user = $userRepository->create([
26+
'email' => 'john_doe@original.com',
27+
'password' => 'password',
28+
]);
29+
30+
User::saving(function () {
31+
return false;
32+
});
33+
34+
$I->disableModelEvents();
35+
36+
$user->setEmail('john_doe@updated.com');
37+
$userRepository->save($user);
38+
39+
$I->seeRecord(User::class, ['email' => 'john_doe@updated.com']);
40+
}
41+
42+
public function dontSeeEventTriggered(FunctionalTester $I)
43+
{
44+
// With class name
45+
$I->amOnPage('/');
46+
$I->dontSeeEventTriggered(TestEvent::class);
47+
48+
// With event object
49+
$I->amOnPage('/');
50+
$I->dontSeeEventTriggered(new TestEvent());
51+
}
52+
53+
public function seeEventTriggered(FunctionalTester $I)
54+
{
55+
$I->amOnPage('/fire-event');
56+
$I->seeNumRecords(2, User::class);
57+
58+
// With class name
59+
$I->seeEventTriggered(TestEvent::class);
60+
61+
// With event object
62+
$I->amOnPage('/fire-event');
63+
$I->seeEventTriggered(new TestEvent());
64+
65+
// With events array
66+
$I->amOnPage('/fire-event');
67+
$I->seeEventTriggered([TestEvent::class, TestEvent::class]);
68+
69+
// When events are disabled
70+
$I->disableEvents();
71+
$I->amOnPage('/fire-event');
72+
$I->seeEventTriggered(TestEvent::class);
73+
}
74+
}

0 commit comments

Comments
 (0)