File tree 2 files changed +48
-2
lines changed
2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -74,4 +74,27 @@ public function user_can_queue_invoices_export()
74
74
return true;
75
75
});
76
76
}
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.
Original file line number Diff line number Diff line change @@ -54,4 +54,27 @@ public function user_can_queue_the_users_import()
54
54
return true;
55
55
});
56
56
}
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.
You can’t perform that action at this time.
0 commit comments