2018-10-17 14:26:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\Http\ValidationRules\UniqueUserRule;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
|
2018-10-18 07:04:36 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
2018-10-17 14:26:27 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Utils\NumberHelper
|
|
|
|
*/
|
|
|
|
class UniqueEmailTest extends TestCase
|
|
|
|
{
|
2018-10-18 12:47:55 +02:00
|
|
|
use InteractsWithDatabase;
|
2018-10-18 07:04:36 +02:00
|
|
|
//use DatabaseMigrations;
|
2018-10-17 14:26:27 +02:00
|
|
|
|
|
|
|
protected $rule;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2018-10-21 00:26:21 +02:00
|
|
|
if (! config('ninja.db.multi_db_enabled'))
|
2018-10-17 14:26:27 +02:00
|
|
|
$this->markTestSkipped('Multi DB not enabled - skipping');
|
|
|
|
|
|
|
|
DB::connection('db-ninja-1')->table('users')->delete();
|
|
|
|
DB::connection('db-ninja-2')->table('users')->delete();
|
|
|
|
|
|
|
|
$this->rule = new UniqueUserRule();
|
|
|
|
|
|
|
|
$user = [
|
2018-10-19 05:45:55 +02:00
|
|
|
'first_name' => 'user_db_1',
|
|
|
|
'email' => 'user@example.com',
|
|
|
|
'password' => Hash::make('password'),
|
|
|
|
'db' => config('database.default')
|
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
User::on('db-ninja-1')->create($user);
|
|
|
|
User::on('db-ninja-2')->create($user);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_unique_emails_detected_on_database()
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->assertFalse($this->rule->passes('email', 'user@example.com'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_no_unique_emails_detected()
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->assertTrue($this->rule->passes('email', 'nohit@example.com'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
2018-10-18 07:04:36 +02:00
|
|
|
DB::connection('db-ninja-1')->table('users')->delete();
|
|
|
|
DB::connection('db-ninja-2')->table('users')->delete();
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|