Skip to content

Commit 84ab120

Browse files
committed
Use orchestra testbench
1 parent b3151f5 commit 84ab120

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"Flynsarmy\\CsvSeeder\\": "src/"
1919
}
2020
},
21-
"minimum-stability": "dev"
21+
"minimum-stability": "dev",
22+
"require-dev": {
23+
"orchestra/testbench": "^6.0@dev"
24+
}
2225
}

tests/CsvTest.php

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
<?php
1+
<?php namespace Flynsarmy\CsvSeeder\Tests;
22

3-
class CsvTest extends TestCase
3+
class CsvTest extends \Orchestra\Testbench\TestCase
44
{
55
/**
6-
* @before
6+
* Setup the test environment.
77
*/
8-
public function runDatabaseMigrations()
8+
protected function setUp(): void
99
{
10-
// Create our testing DB tables
11-
$this->artisan('migrate', [
12-
'--path' => 'vendor/flynsarmy/csv-seeder/tests/migrations',
13-
]);
10+
parent::setUp();
11+
12+
$this->loadMigrationsFrom(__DIR__ . '/migrations');
13+
14+
$this->artisan('migrate');
1415

1516
$this->beforeApplicationDestroyed(function () {
1617
$this->artisan('migrate:rollback');
1718
});
1819
}
1920

2021
/**
21-
* Setup the test environment.
22+
* Define environment setup.
23+
*
24+
* @param \Illuminate\Foundation\Application $app
2225
*
2326
* @return void
2427
*/
25-
public function setUp()
28+
protected function getEnvironmentSetUp($app)
2629
{
27-
parent::setUp();
28-
2930
// Use an in-memory DB
30-
$this->app['config']->set('database.default', 'csvSeederTest');
31-
$this->app['config']->set('database.connections.csvSeederTest', [
31+
$app['config']->set('database.default', 'csvSeederTest');
32+
$app['config']->set('database.connections.csvSeederTest', [
3233
'driver' => 'sqlite',
3334
'database' => ':memory:',
3435
'prefix' => '',
3536
]);
3637
}
3738

38-
public function testBOMIsStripped()
39+
/** @test */
40+
public function it_strips_BOM()
3941
{
4042
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
4143

@@ -53,7 +55,8 @@ public function testBOMIsStripped()
5355
$this->assertEquals($expected, $actual);
5456
}
5557

56-
public function testMappings()
58+
/** @test */
59+
public function it_maps_correctly()
5760
{
5861
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
5962
$row = [1, 'ignored', 'first', 'last'];
@@ -103,7 +106,7 @@ public function testMappings()
103106
$this->assertEquals($expected, $actual);
104107
}
105108

106-
public function testCanOpenCSV()
109+
public function it_can_open_CSV()
107110
{
108111
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
109112

@@ -113,28 +116,29 @@ public function testCanOpenCSV()
113116
$this->assertInternalType($expected, $actual);
114117

115118
// Test a non-openable CSV
116-
$expected = FALSE;
119+
$expected = false;
117120
$actual = $seeder->openCSV(__DIR__.'/csvs/csv_that_does_not_exist.csv');
118121
$this->assertEquals($expected, $actual);
119122
}
120123

121-
public function testImport()
124+
/** @test */
125+
public function it_imports()
122126
{
123127
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
124-
$seeder->table = 'users';
128+
$seeder->table = 'tests_users';
125129
$seeder->filename = __DIR__.'/csvs/users.csv';
126130
$seeder->hashable = '';
127131
$seeder->run();
128132

129133
// Make sure the rows imported
130-
$this->seeInDatabase('users', [
134+
$this->assertDatabaseHas('tests_users', [
131135
'id' => 1,
132136
'first_name' => 'Abe',
133137
'last_name' => 'Abeson',
134138
'email' => 'abe.abeson@foo.com',
135139
'age' => 50,
136140
]);
137-
$this->seeInDatabase('users', [
141+
$this->assertDatabaseHas('tests_users', [
138142
'id' => 3,
139143
'first_name' => 'Charly',
140144
'last_name' => 'Charlyson',
@@ -143,23 +147,24 @@ public function testImport()
143147
]);
144148
}
145149

146-
public function testIgnoredColumnImport()
150+
/** @test */
151+
public function it_ignores_columns_on_import()
147152
{
148153
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
149-
$seeder->table = 'users';
154+
$seeder->table = 'tests_users';
150155
$seeder->filename = __DIR__.'/csvs/users_with_ignored_column.csv';
151156
$seeder->hashable = '';
152157
$seeder->run();
153158

154159
// Make sure the rows imported
155-
$this->seeInDatabase('users', [
160+
$this->assertDatabaseHas('tests_users', [
156161
'id' => 1,
157162
'first_name' => 'Abe',
158163
'last_name' => 'Abeson',
159164
'email' => 'abe.abeson@foo.com',
160165
'age' => 50,
161166
]);
162-
$this->seeInDatabase('users', [
167+
$this->assertDatabaseHas('tests_users', [
163168
'id' => 3,
164169
'first_name' => 'Charly',
165170
'last_name' => 'Charlyson',
@@ -168,41 +173,43 @@ public function testIgnoredColumnImport()
168173
]);
169174
}
170175

171-
public function testHash()
176+
/** @test */
177+
public function it_hashes()
172178
{
173179
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
174-
$seeder->table = 'users';
180+
$seeder->table = 'tests_users';
175181
$seeder->filename = __DIR__.'/csvs/users.csv';
176182

177183
// Assert unhashed passwords
178184
$seeder->hashable = '';
179185
$seeder->run();
180-
$this->seeInDatabase('users', [
186+
$this->assertDatabaseHas('tests_users', [
181187
'id' => 1,
182188
'password' => 'abeabeson',
183189
]);
184190

185191
// Reset users table
186-
DB::table('users')->truncate();
192+
\DB::table('tests_users')->truncate();
187193

188194
// Assert hashed passwords
189195
$seeder->hashable = 'password';
190196
$seeder->run();
191197
// Row 1 should still be in DB...
192-
$this->seeInDatabase('users', [
198+
$this->assertDatabaseHas('tests_users', [
193199
'id' => 1,
194200
]);
195201
// ... But passwords were hashed
196-
$this->missingFromDatabase('users', [
202+
$this->assertDatabaseMissing('tests_users', [
197203
'id' => 1,
198204
'password' => 'abeabeson',
199205
]);
200206
}
201207

202-
public function testOffset()
208+
/** @test */
209+
public function it_offsets()
203210
{
204211
$seeder = new \Flynsarmy\CsvSeeder\CsvSeeder;
205-
$seeder->table = 'users';
212+
$seeder->table = 'tests_users';
206213
$seeder->filename = __DIR__.'/csvs/users.csv';
207214
$seeder->hashable = '';
208215
$seeder->offset_rows = 4;
@@ -214,12 +221,12 @@ public function testOffset()
214221
$seeder->run();
215222

216223
// Assert offset occurred
217-
$this->missingFromDatabase('users', [
224+
$this->assertDatabaseMissing('tests_users', [
218225
'id' => 1,
219226
]);
220227

221228
// Assert mapping worked
222-
$this->seeInDatabase('users', [
229+
$this->assertDatabaseHas('tests_users', [
223230
'id' => 5,
224231
'first_name' => 'Echo',
225232
'last_name' => '',

tests/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/migrations/2014_10_12_000000_create_users_table.php renamed to tests/migrations/2014_10_12_000000_create_tests_users_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
use Illuminate\Database\Migrations\Migration;
33

4-
class CreateUsersTable extends Migration
4+
class CreateTestsUsersTable extends Migration
55
{
66
/**
77
* Run the migrations.
@@ -10,7 +10,7 @@ class CreateUsersTable extends Migration
1010
*/
1111
public function up()
1212
{
13-
Schema::create('users', function ($table) {
13+
Schema::create('tests_users', function ($table) {
1414
$table->increments('id');
1515
$table->string('first_name')->default('');
1616
$table->string('last_name')->default('');
@@ -27,6 +27,6 @@ public function up()
2727
*/
2828
public function down()
2929
{
30-
Schema::drop('users');
30+
Schema::drop('tests_users');
3131
}
3232
}

0 commit comments

Comments
 (0)