|
2 | 2 |
|
3 | 3 | use PHPUnit\Framework\TestCase;
|
4 | 4 |
|
| 5 | +require __DIR__.'/../src/Import.php'; |
| 6 | + |
| 7 | +class BasicImport extends Nicklayb\LaravelDbImport\Import |
| 8 | +{ |
| 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' => 'test', |
| 22 | + 'users:super_secret_password' => 'new secret' |
| 23 | + ]; |
| 24 | + |
| 25 | + public function filterUsers($query) |
| 26 | + { |
| 27 | + return $query; |
| 28 | + } |
| 29 | + |
| 30 | + public function manipulateUsers($user) |
| 31 | + { |
| 32 | + $user['key'] = 'value'; |
| 33 | + return $user; |
| 34 | + } |
| 35 | + |
| 36 | + public function preImport() |
| 37 | + { |
| 38 | + return [ |
| 39 | + 'pre_task' => function () { |
| 40 | + // |
| 41 | + } |
| 42 | + ]; |
| 43 | + } |
| 44 | + |
| 45 | + public function postImport() |
| 46 | + { |
| 47 | + return [ |
| 48 | + 'post_task' => function () { |
| 49 | + // |
| 50 | + } |
| 51 | + ]; |
| 52 | + } |
| 53 | +} |
| 54 | + |
5 | 55 | class ImportTest extends TestCase
|
6 | 56 | {
|
7 |
| - public function testImport() |
| 57 | + protected $basicImport; |
| 58 | + protected $extendedImport; |
| 59 | + |
| 60 | + public function __construct() |
8 | 61 | {
|
9 |
| - $stub = $this->getMockForAbstractClass('Nicklayb\LaravelDbImport\Import'); |
10 |
| - $stub->expects($this->any()) |
11 |
| - ->method('countImportTasks') |
12 |
| - ->will($this->returnValue(0)); |
| 62 | + parent::__construct(); |
| 63 | + $this->basicImport = new BasicImport; |
| 64 | + $this->extendedImport = new ExtendedImport; |
| 65 | + } |
13 | 66 |
|
14 |
| - $this->assertTrue($stub->concreteMethod()); |
| 67 | + public function testHasIgnoreTable() |
| 68 | + { |
| 69 | + $this->assertTrue($this->extendedImport->hasIgnoreTable('migrations')); |
| 70 | + } |
| 71 | + |
| 72 | + public function testHasIgnoreTableInexistant() |
| 73 | + { |
| 74 | + $this->assertFalse($this->extendedImport->hasIgnoreTable('products')); |
| 75 | + } |
| 76 | + |
| 77 | + public function testHasLastTable() |
| 78 | + { |
| 79 | + $this->assertTrue($this->extendedImport->hasLastTable('relation_one')); |
| 80 | + } |
| 81 | + |
| 82 | + public function testHasLastTableInexistant() |
| 83 | + { |
| 84 | + $this->assertFalse($this->extendedImport->hasLastTable('products')); |
| 85 | + } |
| 86 | + |
| 87 | + public function testHasPasswordReset() |
| 88 | + { |
| 89 | + $this->assertTrue($this->extendedImport->hasPasswordResets()); |
| 90 | + } |
| 91 | + |
| 92 | + public function testHasPasswordResetInexistant() |
| 93 | + { |
| 94 | + $this->assertFalse($this->basicImport->hasPasswordResets()); |
| 95 | + } |
| 96 | + |
| 97 | + public function testQualifiedManipulationName() |
| 98 | + { |
| 99 | + $expected = 'manipulateUsers'; |
| 100 | + $this->assertEquals($expected, $this->extendedImport->getManipulationName('users')); |
| 101 | + } |
| 102 | + |
| 103 | + public function testGetPasswordResetValues() |
| 104 | + { |
| 105 | + $expected = [ |
| 106 | + 'super_secret_password' => 'new secret', |
| 107 | + 'password' => 'test' |
| 108 | + ]; |
| 109 | + $this->assertEquals($expected, $this->extendedImport->getPasswordResetValues('users')); |
| 110 | + } |
| 111 | + |
| 112 | + public function testHasSelects() |
| 113 | + { |
| 114 | + $this->assertTrue($this->extendedImport->hasSelects('users')); |
| 115 | + } |
| 116 | + |
| 117 | + public function testHasSelectsInexistant() |
| 118 | + { |
| 119 | + $this->assertFalse($this->extendedImport->hasSelects('products')); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @depends testHasSelects |
| 124 | + * @depends testHasSelectsInexistant |
| 125 | + */ |
| 126 | + public function testGetSelects() |
| 127 | + { |
| 128 | + $expected = [ |
| 129 | + 'id', 'firstname', 'lastname' |
| 130 | + ]; |
| 131 | + $this->assertEquals($expected, $this->extendedImport->getSelects('users')); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * @depends testHasSelects |
| 136 | + * @depends testHasSelectsInexistant |
| 137 | + */ |
| 138 | + public function testGetSelectsInexistant() |
| 139 | + { |
| 140 | + $expected = [ '*' ]; |
| 141 | + $this->assertEquals($expected, $this->extendedImport->getSelects('products')); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * @depends testQualifiedManipulationName |
| 146 | + */ |
| 147 | + public function testHasTableManipulation() |
| 148 | + { |
| 149 | + $this->assertTrue($this->extendedImport->hasManipulation('users')); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * @depends testQualifiedManipulationName |
| 154 | + */ |
| 155 | + public function testHasInexistantTableManipulation() |
| 156 | + { |
| 157 | + $this->assertFalse($this->extendedImport->hasManipulation('products')); |
| 158 | + } |
| 159 | + |
| 160 | + public function testQualifiedFilterName() |
| 161 | + { |
| 162 | + $expected = 'filterUsers'; |
| 163 | + $this->assertEquals($expected, $this->extendedImport->getFilterName('users')); |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * @depends testQualifiedFilterName |
| 168 | + */ |
| 169 | + public function testHasTableFilter() |
| 170 | + { |
| 171 | + $this->assertTrue($this->extendedImport->hasTableFilter('users')); |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * @depends testQualifiedFilterName |
| 176 | + */ |
| 177 | + public function testHasInexistantTableFilter() |
| 178 | + { |
| 179 | + $this->assertFalse($this->extendedImport->hasTableFilter('products')); |
| 180 | + } |
| 181 | + |
| 182 | + /** |
| 183 | + * @depends testQualifiedFilterName |
| 184 | + * @depends testHasTableFilter |
| 185 | + * @depends testHasInexistantTableFilter |
| 186 | + */ |
| 187 | + public function testExecuteManipulation() |
| 188 | + { |
| 189 | + $table = 'users'; |
| 190 | + $base = [ 'root' => 'element' ]; |
| 191 | + $expected = [ |
| 192 | + 'root' => 'element', |
| 193 | + 'key' => 'value' |
| 194 | + ]; |
| 195 | + |
| 196 | + $this->assertEquals($expected, $this->extendedImport->executeManipulation($table, $base)); |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * @depends testQualifiedFilterName |
| 201 | + * @depends testHasTableFilter |
| 202 | + * @depends testHasInexistantTableFilter |
| 203 | + */ |
| 204 | + public function testExecuteInexistantManipulation() |
| 205 | + { |
| 206 | + $table = 'products'; |
| 207 | + $base = [ 'root' => 'element' ]; |
| 208 | + $expected = [ 'root' => 'element' ]; |
| 209 | + |
| 210 | + $this->assertEquals($expected, $this->extendedImport->executeManipulation($table, $base)); |
| 211 | + } |
| 212 | + |
| 213 | + public function testCountImportTasks() |
| 214 | + { |
| 215 | + $expected = 2; |
| 216 | + $this->assertEquals($expected, $this->extendedImport->countImportTasks()); |
15 | 217 | }
|
16 | 218 | }
|
0 commit comments