-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
TestCase.php
95 lines (75 loc) · 2.28 KB
/
TestCase.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
<?php
namespace Tests\Support;
use CodeIgniter\Config\Factories;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use org\bovigo\vfs\vfsStream;
use Tatter\Assets\Test\AssetsTestTrait;
use Tatter\Files\Config\Files;
use Tatter\Files\Models\FileModel;
use Tatter\Imposter\Entities\User;
use Tatter\Imposter\Factories\ImposterFactory;
use Tatter\Users\UserProvider;
/**
* @internal
*/
abstract class TestCase extends CIUnitTestCase
{
use AssetsTestTrait;
use DatabaseTestTrait;
protected $refreshVfs = false;
protected $refresh = false;
protected $namespace;
/**
* Path to a test file to work with
*/
protected string $testPath;
protected FileModel $model;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
helper(['auth', 'files', 'preferences']);
UserProvider::addFactory(ImposterFactory::class, ImposterFactory::class);
}
protected function setUp(): void
{
$this->resetServices();
parent::setUp();
$_POST = [];
$_GET = [];
$_FILES = [];
$_REQUEST = [];
// Make sure all files are on a single page
$_REQUEST['perPage'] = 200;
// Force Files config to the virtual path
$path = self::$root->url() . DIRECTORY_SEPARATOR;
$config = config('Files');
$config->setPath($path);
Factories::injectMock('config', 'Files', $config);
// Copy the files to VFS (if necessary)
$this->testPath = $config->getPath() . 'image.jpg';
if (! is_file($this->testPath)) {
vfsStream::copyFromFileSystem(SUPPORTPATH . 'VFS', self::$root);
}
// Set up the model
$this->model = model(FileModel::class);
}
protected function tearDown(): void
{
parent::tearDown();
ImposterFactory::reset();
}
/**
* Creates a test User with some files.
*
* @return array Tuple of [User, File]
*/
protected function createUserWithFile(): array
{
$user = ImposterFactory::fake();
$user->id = ImposterFactory::add($user);
$file = fake(FileModel::class);
$this->model->addToUser($file->id, $user->id);
return [$user, $file];
}
}