-
Notifications
You must be signed in to change notification settings - Fork 0
/
MockTest.php
102 lines (91 loc) · 2.25 KB
/
MockTest.php
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace Tests\Feature;
use App\User;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Str;
use Tests\TestCase;
class MockTest extends TestCase
{
use DatabaseMigrations;
/**
* @test
*/
public function testGenerateRandom()
{
// $today = new Today();
// Carbon::setTestNow();
// $this->assertEquals(Carbon::now(), $today->now());
$token = new Token();
Token::setHash('asadgafwd8235283tc');
$this->assertEquals('asadgafwd8235283tc',$token->generate());
}
public function testStub(){
$user = factory(User::class)->create();
$email = $user->email;
$user->fraud();
$this->assertNotEquals($email, $user->email);
}
public function testFake(){
$fb = $this->createMock(Facebook::class);
$fb->method('authorize')->willReturn(['result' => 'OK']);
$mem = new Member();
$this->assertTrue($mem->exist($fb));
}
public function testMock(){
$window = $this->createMock(Window::class);
$window->expects($this->once())
->method('close')
->with('A');
$door = $this->createMock(Door::class);
$door->expects($this->once())
->method('close')
->with('A');
$security = new SecurityA();
$security->closeAll($door, $window);
}
}
class Window{
public function close($w){
}
}
class Door{
public function close($d){
}
}
class SecurityA{
public function closeAll(Door $door,Window $window){
$door->close('A');
$window->close('A');
}
}
class Facebook{
public function authorize(){
}
}
class Member{
public function exist(Facebook $fb){
$result = $fb->authorize();
if($result['result'] == 'OK') return true;
}
}
class Token{
static $token;
public function generate()
{
if(static::$token) return static::$token;
return Str::random(16);
}
public static function setHash($data)
{
static::$token = $data;
}
}
class Today{
public function now()
{
return Carbon::now();
}
}