Skip to content

Commit 2ca577f

Browse files
fkupperpatrickbrouwers
authored andcommitted
Support regular expression file name/path matching (SpartnerNL#73)
* Support regular expression file name/path matching Update related to PR SpartnerNL/Laravel-Excel#2279 * Support regular expression file name/path matching
1 parent d079fc0 commit 2ca577f

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

3.1/exports/testing.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,27 @@ public function user_can_queue_invoices_export()
7474
return true;
7575
});
7676
}
77-
```
77+
```
78+
79+
## Testing exports with dynamic file name/path
80+
81+
If you have dynamic naming for files or paths, you can use a regular expression to represent those while testing:
82+
83+
```php
84+
/**
85+
* @test
86+
*/
87+
public function user_can_store_invoices_export()
88+
{
89+
Excel::fake();
90+
91+
$this->actingAs($this->givenUser())
92+
->get('/invoices/store/xlsx');
93+
94+
// Tells the mock to use regular expressions
95+
Excel::matchByRegex();
96+
// For a given dynamic named file 'invoices_2019.xlsx'
97+
Excel::assertStored('/invoices_\d{4}\.xlsx/', 'diskName');
98+
}
99+
```
100+
Please note that your expression must match only one file/path. If more than one match is found, the test will fail.

3.1/imports/testing.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,27 @@ public function user_can_queue_the_users_import()
5454
return true;
5555
});
5656
}
57-
```
57+
```
58+
59+
## Testing imports with dynamic file name/path
60+
61+
If you have dynamic naming for files or paths, you can use a regular expression to represent those while testing:
62+
63+
```php
64+
/**
65+
* @test
66+
*/
67+
public function user_can_import_users()
68+
{
69+
Excel::fake();
70+
71+
$this->actingAs($this->givenUser())
72+
->get('/users/import/xlsx');
73+
74+
// Tells the mock to use regular expressions
75+
Excel::matchByRegex();
76+
// For a given dynamic named file 'dynamic_1234_filename.xlsx'
77+
Excel::assertImported('/\w{7}_\d{4}\_\w{8}\.xlsx/', 'diskName');
78+
}
79+
```
80+
Please note that your expression must match only one file/path. If more than one match is found, the test will fail.

0 commit comments

Comments
 (0)