1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of questocat/laravel-referral package. |
5
|
|
|
* |
6
|
|
|
* (c) questocat <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tests; |
13
|
|
|
|
14
|
|
|
use Illuminate\Filesystem\Filesystem; |
15
|
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; |
16
|
|
|
use Tests\Stubs\UserStub; |
17
|
|
|
|
18
|
|
|
class TestCase extends BaseTestCase |
19
|
|
|
{ |
20
|
|
|
use CreatesApplication; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Setup DB before each test. |
24
|
|
|
*/ |
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
|
29
|
|
|
$this->app['config']->set('database.default', 'sqlite'); |
30
|
|
|
$this->app['config']->set('database.connections.sqlite.database', ':memory:'); |
31
|
|
|
$this->app['config']->set('app.key', 'base64:jkHe+0IUIG1lp9d2LIaLjcsRZg4TIZ5Ccya2g/8ByGs='); |
32
|
|
|
if (empty($this->config)) { |
33
|
|
|
$this->config = require __DIR__.'/../config/referral.php'; |
|
|
|
|
34
|
|
|
} |
35
|
|
|
$this->app['config']->set('referral', $this->config); |
36
|
|
|
$this->migrate(); |
37
|
|
|
$this->seedDatabase(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* run package database migrations. |
42
|
|
|
*/ |
43
|
|
|
public function migrate() |
44
|
|
|
{ |
45
|
|
|
$fileSystem = new Filesystem(); |
46
|
|
|
foreach ($fileSystem->files(__DIR__.'/../tests/database/migrations') as $file) { |
47
|
|
|
$fileSystem->requireOnce($file); |
48
|
|
|
} |
49
|
|
|
(new \CreateUsersTable())->up(); |
50
|
|
|
(new \AddAffiliateIdToUsersTable())->up(); |
51
|
|
|
(new \CreateReferralsTable())->up(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Seed testing database. |
56
|
|
|
*/ |
57
|
|
|
public function seedDatabase() |
58
|
|
|
{ |
59
|
|
|
UserStub::create([ |
|
|
|
|
60
|
|
|
'name' => 'questocat', |
61
|
|
|
'email' => '[email protected]', |
62
|
|
|
'password' => bcrypt('secret'), |
63
|
|
|
]); |
64
|
|
|
UserStub::create([ |
|
|
|
|
65
|
|
|
'name' => 'zhengchaopu', |
66
|
|
|
'email' => '[email protected]', |
67
|
|
|
'password' => bcrypt('secret'), |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: