-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCheckUserEmailExistTest.php
More file actions
69 lines (53 loc) · 2.08 KB
/
CheckUserEmailExistTest.php
File metadata and controls
69 lines (53 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Tests\Commands;
use App\Services\WikiUserEmailChecker;
use App\User;
use Mockery;
use Tests\TestCase;
class CheckUserEmailExistTest extends TestCase {
protected function tearDown(): void {
// delete all users
User::query()->delete();
}
public function testItFindsEmailInApiUsersTable() {
User::factory()->create([
'email' => 'user@example.com',
]);
// Act & Assert
$this->artisan('wbs-user:check-email', ['emails' => ['user@example.com']])
->expectsOutput('FOUND: user@example.com in apidb.users')
->assertExitCode(0);
}
public function testItReturnsNotFoundIfEmailDoesNotExist() {
$this->artisan('wbs-user:check-email', ['emails' => ['nonexistent@example.com']])
->expectsOutput('NOT FOUND: nonexistent@example.com')
->assertExitCode(0);
}
public function testItChecksMultipleEmails() {
User::factory()->create(['email' => 'user1@example.com']);
$emails = ['user1@example.com', 'other@example.com'];
$this->artisan('wbs-user:check-email', ['emails' => $emails])
->expectsOutput('FOUND: user1@example.com in apidb.users')
->expectsOutput('NOT FOUND: other@example.com')
->assertExitCode(0);
}
public function testEmailFoundInWikiDb() {
$checker = Mockery::mock(WikiUserEmailChecker::class);
$checker->shouldReceive('findEmail')
->with('test@example.com')
->andReturn(['mwdb_test.mwdb_test_user']);
$this->app->instance(WikiUserEmailChecker::class, $checker);
$this->artisan('wbs-user:check-email', [
'emails' => ['test@example.com'],
])
->expectsOutput('FOUND: test@example.com in mwdb_test.mwdb_test_user')
->assertExitCode(0);
}
public function testCaseInsensitive() {
User::factory()->create([
'email' => 'Test@Example.com',
]);
$exists = User::whereEmailInsensitive('tEsT@eXaMpLe.CoM')->exists();
$this->assertTrue($exists);
}
}