Test Failed
Branch develop (e68766)
by Abhishek Kumar
03:33
created

ImportTest::fetch_import()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tests;
4
5
use Orchestra\Testbench\TestCase;
6
use Illuminate\Http\File;
7
use Illuminate\Http\UploadedFile;
8
use Illuminate\Foundation\Testing\RefreshDatabase;
9
use Illuminate\Foundation\Testing\WithoutMiddleware;
10
use Illuminate\Support\Facades\Queue;
11
use Illuminate\Support\Facades\Route;
12
use Illuminate\Support\Facades\Storage;
13
use Ladybirdweb\ImportExport\Facades\Import;
14
use Ladybirdweb\ImportExport\Models\Import as ModelImport;
15
16
class ImportTest extends TestCase
17
{
18
	use RefreshDatabase;
0 ignored issues
show
introduced by
The trait Illuminate\Foundation\Testing\RefreshDatabase requires some properties which are not provided by Tests\ImportTest: $connectionsToTransact, $dropViews
Loading history...
19
20
	protected $import;
21
22
	protected function setUp ()
23
	{
24
	    parent::setUp();
25
26
	    Route::middleware('web')->group(function() {
27
		    
28
			Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']);
29
30
		});
31
32
		Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv');
33
34
		$this->import = ModelImport::create([
35
			'file' => 'imports/test.csv',
36
			'file_rows' => 104,
37
			'db_cols' => [ 'name', 'email', 'password'],
38
			'model_map' => ['email', 'name', 'password']
39
		]);
40
	}
41
42
	/**
43
	* @test
44
	*/
45
	public function create_new_import_success()
46
	{
47
		$import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']);
0 ignored issues
show
Bug introduced by
The method createImport() does not exist on Ladybirdweb\ImportExport\Facades\Import. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
		/** @scrutinizer ignore-call */ 
48
  $import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']);
Loading history...
48
49
		$this->assertInstanceOf(ModelImport::class, $import);
50
	}
51
52
	/**
53
	* @test
54
	*/
55
	public function fetch_import()
56
	{
57
		$import = Import::getImport($this->import->id);
0 ignored issues
show
Bug introduced by
The method getImport() does not exist on Ladybirdweb\ImportExport\Facades\Import. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
		/** @scrutinizer ignore-call */ 
58
  $import = Import::getImport($this->import->id);
Loading history...
58
59
		$this->assertInstanceOf(ModelImport::class, $import);
60
	}
61
62
	/**
63
	* @test
64
	*/
65
	public function get_few_rows_from_uploaded_file()
66
	{
67
		$csv_data = Import::getImportFileData($this->import->id);
0 ignored issues
show
Bug introduced by
The method getImportFileData() does not exist on Ladybirdweb\ImportExport\Facades\Import. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
		/** @scrutinizer ignore-call */ 
68
  $csv_data = Import::getImportFileData($this->import->id);
Loading history...
68
69
		$this->assertInternalType( 'array', $csv_data );
70
	}
71
72
	/**
73
	* @test
74
	*/
75
	public function store_data_map_with_csv_cols()
76
	{
77
		$import = Import::setDataMap(['email', 'name', 'password'], $this->import->id);
0 ignored issues
show
Bug introduced by
The method setDataMap() does not exist on Ladybirdweb\ImportExport\Facades\Import. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
		/** @scrutinizer ignore-call */ 
78
  $import = Import::setDataMap(['email', 'name', 'password'], $this->import->id);
Loading history...
78
79
		$this->assertInstanceOf(ModelImport::class, $import);
80
	}
81
82
	/**
83
	* @test
84
	*/
85
	public function sucess_to_dispatch_given_job_class()
86
	{
87
		$import = $id = $this->import;
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
88
89
		Queue::fake();
90
91
		Import::dispatchImportJob( FakeJob::class, $import );
0 ignored issues
show
Bug introduced by
The method dispatchImportJob() does not exist on Ladybirdweb\ImportExport\Facades\Import. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
		Import::/** @scrutinizer ignore-call */ 
92
          dispatchImportJob( FakeJob::class, $import );
Loading history...
92
93
		Queue::assertPushedOn('importing', FakeJob::class);
94
	}
95
96
	/**
97
	* @test
98
	*/
99
	public function check_import_progress()
100
	{
101
		$response = $this->json( 'GET', '/import/1/progress' );
102
103
		$response->assertStatus(200);
104
105
		$response->assertJsonFragment( ['status' => 200] );
106
107
		$response->assertJsonFragment( ['progress'] );
108
	}
109
110
	/**
111
	* @test
112
	*/
113
	public function remove_import()
114
	{
115
		$this->assertTrue(Import::removeImport($this->import->id));
0 ignored issues
show
Bug introduced by
The method removeImport() does not exist on Ladybirdweb\ImportExport\Facades\Import. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
		$this->assertTrue(Import::/** @scrutinizer ignore-call */ removeImport($this->import->id));
Loading history...
116
	}
117
}
118