Excel File Test
This commit is contained in:
parent
f7fd202d74
commit
dc20a8a75c
40
laravel_app/tests/Feature/ValidateExcelStructureTest.php
Normal file
40
laravel_app/tests/Feature/ValidateExcelStructureTest.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Maatwebsite\Excel\Exceptions\NoTypeDetectedException;
|
||||
use Maatwebsite\Excel\HeadingRowImport;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ValidateExcelStructureTest extends TestCase
|
||||
{
|
||||
public static function excelFileProvider()
|
||||
{
|
||||
//good file - correct data
|
||||
yield ['/Users/guillaume/smartcane/laravel_app/storage/app/livewire-tmp/Fi8skg5XxHVWmJ4LdkzOvvyBYYVsTW-metadGVzdCAoMSkueGxzeA==-.xlsx'];
|
||||
//good file - wrong data
|
||||
yield ['/Users/guillaume/smartcane/laravel_app/storage/app/livewire-tmp/SosZOpFgWrPWELZQrP3tIr69d0sOjf-metad3JvbmcueGxzeA==-.xlsx'];
|
||||
// wrong file
|
||||
yield ['/Users/guillaume/smartcane/laravel_app/storage/app/livewire-tmp/gc4uIBw5Uli7Fk1JJDR9d7eLoPRI0x-metaWGluYXZhbmVfZGVtby5nZW9qc29u-.json'];
|
||||
|
||||
}
|
||||
/** @test
|
||||
* @dataProvider excelFileProvider
|
||||
*/
|
||||
public function it_can_load_an_excel_sheet(string $filename)
|
||||
{
|
||||
$toCheck = ["field","sub_field", "year", "season_start","season_end", "age" , "sub_area", "tonnage_ha"];
|
||||
self::assertFileExists($filename);
|
||||
try {
|
||||
$excelArray = (new HeadingRowImport)->toArray($filename);
|
||||
self::assertNotNull($excelArray);
|
||||
$headers = $excelArray[0][0];
|
||||
self::assertNotEmpty($headers);
|
||||
self::assertEmpty(array_diff($toCheck, $headers));
|
||||
|
||||
}catch (NoTypeDetectedException $exception){
|
||||
self::assertFileExists('/Users/guillaume/smartcane/laravel_app/storage/app/livewire-tmp/gc4uIBw5Uli7Fk1JJDR9d7eLoPRI0x-metaWGluYXZhbmVfZGVtby5nZW9qc29u-.json');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue