Skip to content

Commit 1cb6138

Browse files
author
Nicolas Boisvert
committed
Added unit test
1 parent 5633bdf commit 1cb6138

File tree

1 file changed

+120
-11
lines changed

1 file changed

+120
-11
lines changed

tests/ImportTest.php

Lines changed: 120 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,23 @@
44

55
require __DIR__.'/../src/Import.php';
66

7-
class ImportExtended extends Nicklayb\LaravelDbImport\Import
7+
class BasicImport extends Nicklayb\LaravelDbImport\Import
88
{
9+
}
10+
11+
class ExtendedImport extends Nicklayb\LaravelDbImport\Import
12+
{
13+
protected $ignoreTables = [ 'migrations' ];
14+
protected $lastTables = [ 'relation_one', 'relation_two' ];
15+
protected $selects = [
16+
'users' => [
17+
'id', 'firstname', 'lastname'
18+
]
19+
];
20+
protected $resetPassword = [
21+
'users:password' => 'test'
22+
];
23+
924
public function filterUsers($query)
1025
{
1126
return $query;
@@ -16,60 +31,148 @@ public function manipulateUsers($user)
1631
$user['key'] = 'value';
1732
return $user;
1833
}
34+
35+
public function preImport()
36+
{
37+
return [
38+
'pre_task' => function () {
39+
//
40+
}
41+
];
42+
}
43+
44+
public function postImport()
45+
{
46+
return [
47+
'post_task' => function () {
48+
//
49+
}
50+
];
51+
}
1952
}
2053

2154
class ImportTest extends TestCase
2255
{
23-
protected $import;
56+
protected $basicImport;
57+
protected $extendedImport;
2458

2559
public function __construct()
2660
{
2761
parent::__construct();
28-
$this->import = new ImportExtended;
62+
$this->basicImport = new BasicImport;
63+
$this->extendedImport = new ExtendedImport;
64+
}
65+
66+
public function testHasIgnoreTable()
67+
{
68+
$this->assertTrue($this->extendedImport->hasIgnoreTable('migrations'));
69+
}
70+
71+
public function testHasIgnoreTableInexistant()
72+
{
73+
$this->assertFalse($this->extendedImport->hasIgnoreTable('products'));
74+
}
75+
76+
public function testHasLastTable()
77+
{
78+
$this->assertTrue($this->extendedImport->hasLastTable('relation_one'));
79+
}
80+
81+
public function testHasLastTableInexistant()
82+
{
83+
$this->assertFalse($this->extendedImport->hasLastTable('products'));
84+
}
85+
86+
public function testHasPasswordReset()
87+
{
88+
$this->assertTrue($this->extendedImport->hasPasswordResets());
89+
}
90+
91+
public function testHasPasswordResetInexistant()
92+
{
93+
$this->assertFalse($this->basicImport->hasPasswordResets());
2994
}
3095

3196
public function testQualifiedManipulationName()
3297
{
3398
$expected = 'manipulateUsers';
34-
$this->assertEquals($expected, $this->import->getManipulationName('users'));
99+
$this->assertEquals($expected, $this->extendedImport->getManipulationName('users'));
100+
}
101+
102+
public function testGetPasswordResetValues()
103+
{
104+
$expected = ['password' => 'test'];
105+
$this->assertEquals($expected, $this->extendedImport->getPasswordResetValues('users'));
106+
}
107+
108+
public function testHasSelects()
109+
{
110+
$this->assertTrue($this->extendedImport->hasSelects('users'));
111+
}
112+
113+
public function testHasSelectsInexistant()
114+
{
115+
$this->assertFalse($this->extendedImport->hasSelects('products'));
116+
}
117+
118+
/**
119+
* @depends testHasSelects
120+
* @depends testHasSelectsInexistant
121+
*/
122+
public function testGetSelects()
123+
{
124+
$expected = [
125+
'id', 'firstname', 'lastname'
126+
];
127+
$this->assertEquals($expected, $this->extendedImport->getSelects('users'));
128+
}
129+
130+
/**
131+
* @depends testHasSelects
132+
* @depends testHasSelectsInexistant
133+
*/
134+
public function testGetSelectsInexistant()
135+
{
136+
$expected = [ '*' ];
137+
$this->assertEquals($expected, $this->extendedImport->getSelects('products'));
35138
}
36139

37140
/**
38141
* @depends testQualifiedManipulationName
39142
*/
40143
public function testHasTableManipulation()
41144
{
42-
$this->assertTrue($this->import->hasManipulation('users'));
145+
$this->assertTrue($this->extendedImport->hasManipulation('users'));
43146
}
44147

45148
/**
46149
* @depends testQualifiedManipulationName
47150
*/
48151
public function testHasInexistantTableManipulation()
49152
{
50-
$this->assertFalse($this->import->hasManipulation('products'));
153+
$this->assertFalse($this->extendedImport->hasManipulation('products'));
51154
}
52155

53156
public function testQualifiedFilterName()
54157
{
55158
$expected = 'filterUsers';
56-
$this->assertEquals($expected, $this->import->getFilterName('users'));
159+
$this->assertEquals($expected, $this->extendedImport->getFilterName('users'));
57160
}
58161

59162
/**
60163
* @depends testQualifiedFilterName
61164
*/
62165
public function testHasTableFilter()
63166
{
64-
$this->assertTrue($this->import->hasTableFilter('users'));
167+
$this->assertTrue($this->extendedImport->hasTableFilter('users'));
65168
}
66169

67170
/**
68171
* @depends testQualifiedFilterName
69172
*/
70173
public function testHasInexistantTableFilter()
71174
{
72-
$this->assertFalse($this->import->hasTableFilter('products'));
175+
$this->assertFalse($this->extendedImport->hasTableFilter('products'));
73176
}
74177

75178
/**
@@ -86,7 +189,7 @@ public function testExecuteManipulation()
86189
'key' => 'value'
87190
];
88191

89-
$this->assertEquals($expected, $this->import->executeManipulation($table, $base));
192+
$this->assertEquals($expected, $this->extendedImport->executeManipulation($table, $base));
90193
}
91194

92195
/**
@@ -100,6 +203,12 @@ public function testExecuteInexistantManipulation()
100203
$base = [ 'root' => 'element' ];
101204
$expected = [ 'root' => 'element' ];
102205

103-
$this->assertEquals($expected, $this->import->executeManipulation($table, $base));
206+
$this->assertEquals($expected, $this->extendedImport->executeManipulation($table, $base));
207+
}
208+
209+
public function testCountImportTasks()
210+
{
211+
$expected = 2;
212+
$this->assertEquals($expected, $this->extendedImport->countImportTasks());
104213
}
105214
}

0 commit comments

Comments
 (0)