Test Failed
Branch develop (17e410)
by Abhishek Kumar
08:42
created

ImportTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A store_data_map_with_csv_cols() 0 5 1
A get_few_rows_from_uploaded_file() 0 5 1
A fetch_import() 0 5 1
A remove_import() 0 3 1
A check_import_progress() 0 9 1
A create_new_import_success() 0 5 1
A setUp() 0 19 1
A getPackageProviders() 0 3 1
A sucess_to_dispatch_given_job_class() 0 9 1
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 getPackageProviders($app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

22
	protected function getPackageProviders(/** @scrutinizer ignore-unused */ $app)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
	{
24
	    return ['Ladybirdweb\ImportExport\ImportExportServiceProvider'];
25
	}
26
27
	protected function setUp ()
28
	{
29
	    parent::setUp();
30
31
	    $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
32
33
	    Route::middleware('web')->group(function() {
34
		    
35
			Route::get( '/import/{id}/progress', [ 'as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'Ladybirdweb\ImportExport\Import@returnImportProgress']);
36
37
		});
38
39
		Storage::putFileAs('imports', new File( storage_path( 'test/test.csv' ) ), 'test.csv');
40
41
		$this->import = ModelImport::create([
42
			'file' => 'imports/test.csv',
43
			'file_rows' => 104,
44
			'db_cols' => [ 'name', 'email', 'password'],
45
			'model_map' => ['email', 'name', 'password']
46
		]);
47
	}
48
49
	/**
50
	* @test
51
	*/
52
	public function create_new_import_success()
53
	{
54
		$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

54
		/** @scrutinizer ignore-call */ 
55
  $import = Import::createImport('imports/test.csv', [ 'name', 'email', 'password']);
Loading history...
55
56
		$this->assertInstanceOf(ModelImport::class, $import);
57
	}
58
59
	/**
60
	* @test
61
	*/
62
	public function fetch_import()
63
	{
64
		$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

64
		/** @scrutinizer ignore-call */ 
65
  $import = Import::getImport($this->import->id);
Loading history...
65
66
		$this->assertInstanceOf(ModelImport::class, $import);
67
	}
68
69
	/**
70
	* @test
71
	*/
72
	public function get_few_rows_from_uploaded_file()
73
	{
74
		$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

74
		/** @scrutinizer ignore-call */ 
75
  $csv_data = Import::getImportFileData($this->import->id);
Loading history...
75
76
		$this->assertInternalType( 'array', $csv_data );
77
	}
78
79
	/**
80
	* @test
81
	*/
82
	public function store_data_map_with_csv_cols()
83
	{
84
		$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

84
		/** @scrutinizer ignore-call */ 
85
  $import = Import::setDataMap(['email', 'name', 'password'], $this->import->id);
Loading history...
85
86
		$this->assertInstanceOf(ModelImport::class, $import);
87
	}
88
89
	/**
90
	* @test
91
	*/
92
	public function sucess_to_dispatch_given_job_class()
93
	{
94
		$import = $id = $this->import;
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
95
96
		Queue::fake();
97
98
		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

98
		Import::/** @scrutinizer ignore-call */ 
99
          dispatchImportJob( FakeJob::class, $import );
Loading history...
99
100
		Queue::assertPushedOn('importing', FakeJob::class);
101
	}
102
103
	/**
104
	* @test
105
	*/
106
	public function check_import_progress()
107
	{
108
		$response = $this->json( 'GET', '/import/1/progress' );
109
110
		$response->assertStatus(200);
111
112
		$response->assertJsonFragment( ['status' => 200] );
113
114
		$response->assertJsonFragment( ['progress'] );
115
	}
116
117
	/**
118
	* @test
119
	*/
120
	public function remove_import()
121
	{
122
		$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

122
		$this->assertTrue(Import::/** @scrutinizer ignore-call */ removeImport($this->import->id));
Loading history...
123
	}
124
}
125