4
4
5
5
use Blueprint \Blueprint ;
6
6
use Blueprint \Concerns \HandlesImports ;
7
- use Blueprint \Concerns \HandlesTraits ;
8
7
use Blueprint \Contracts \Generator ;
9
8
use Blueprint \Contracts \Model as BlueprintModel ;
10
9
use Blueprint \Models \Column ;
26
25
27
26
class PestTestGenerator extends AbstractClassGenerator implements Generator
28
27
{
29
- use HandlesImports, HandlesTraits ;
28
+ use HandlesImports;
30
29
31
30
const TESTS_VIEW = 1 ;
32
31
@@ -42,6 +41,8 @@ class PestTestGenerator extends AbstractClassGenerator implements Generator
42
41
43
42
protected array $ types = ['controllers ' , 'tests ' ];
44
43
44
+ protected array $ traits = [];
45
+
45
46
public function output (Tree $ tree ): array
46
47
{
47
48
$ this ->tree = $ tree ;
@@ -204,6 +205,9 @@ protected function buildTestCases(Controller $controller): string
204
205
$ class = $ this ->buildFormRequestName ($ controller , $ name );
205
206
$ test_case = $ this ->buildFormRequestTestCase ($ controller ->fullyQualifiedClassName (), $ name , config ('blueprint.namespace ' ) . '\\Http \\Requests \\' . $ class ) . PHP_EOL . PHP_EOL . $ test_case ;
206
207
208
+ $ this ->addImport ($ controller , 'JMac \\Testing \\Traits\AdditionalAssertions ' );
209
+ $ this ->addTrait ($ controller , 'AdditionalAssertions ' );
210
+
207
211
if ($ statement ->data ()) {
208
212
foreach ($ statement ->data () as $ data ) {
209
213
[$ qualifier , $ column ] = $ this ->splitField ($ data );
@@ -653,4 +657,23 @@ private function buildLines($lines): string
653
657
{
654
658
return str_pad (' ' , 4 ) . implode (PHP_EOL . str_pad (' ' , 4 ), $ lines );
655
659
}
660
+
661
+ protected function addTrait (BlueprintModel $ model , $ trait ): void
662
+ {
663
+ $ this ->traits [$ model ->name ()][] = $ trait ;
664
+ }
665
+
666
+ protected function buildTraits (BlueprintModel $ model ): string
667
+ {
668
+ if (empty ($ this ->traits [$ model ->name ()])) {
669
+ return '' ;
670
+ }
671
+
672
+ $ traits = collect ($ this ->traits [$ model ->name ()])
673
+ ->unique ()
674
+ ->sort ()
675
+ ->implode ('::class)->use( ' );
676
+
677
+ return "pest()->use( {$ traits }::class); " ;
678
+ }
656
679
}
0 commit comments