66
77use BladeUI \Heroicons \BladeHeroiconsServiceProvider ;
88use BladeUI \Icons \BladeIconsServiceProvider ;
9- use Gajus \ Dindent \ Indenter ;
9+ use Illuminate \ Foundation \ Testing \ Concerns \ InteractsWithViews ;
1010use Orchestra \Testbench \TestCase ;
1111use Rawilk \FormComponents \FormComponentsServiceProvider ;
12- use Rawilk \ FormComponents \ Tests \ Concerns \ InteractsWithViews ;
12+ use ReflectionProperty ;
1313
1414abstract class ComponentTestCase extends TestCase
1515{
1616 use InteractsWithViews;
1717
18- // protected function setUp(): void
19- // {
20- // parent::setUp();
21- //
22- // // TODO: get this line to work in github tests workflow for php8 -- prefer lowest test
23- // // $this->artisan('view:clear');
24- // }
18+ protected function setUp (): void
19+ {
20+ parent ::setUp ();
21+
22+ $ this ->initSession ();
23+
24+ // TODO: get this line to work in github tests workflow for php8 -- prefer lowest test
25+ // $this->artisan('view:clear');
26+ }
27+
28+ protected function initSession (): void
29+ {
30+ // This is to avoid "Session store not set on request" errors for some components.
31+ $ session = new ReflectionProperty (app ('request ' ), 'session ' );
32+ $ session ->setAccessible (true );
33+ $ session ->setValue (app ('request ' ), app ('session ' )->driver ('array ' ));
34+ }
2535
2636 protected function flashOld (array $ input ): void
2737 {
@@ -38,33 +48,4 @@ protected function getPackageProviders($app): array
3848 FormComponentsServiceProvider::class,
3949 ];
4050 }
41-
42- public function assertComponentRenders (string $ expected , string $ template , array $ data = []): void
43- {
44- $ indenter = new Indenter ;
45-
46- $ blade = (string ) $ this ->blade ($ template , $ data );
47- $ indented = $ indenter ->indent ($ blade );
48- $ cleaned = str_replace (
49- [' > ' , "\n/> " , ' </div> ' , '> ' , "\n> " ],
50- ['> ' , ' /> ' , "\n</div> " , "> \n " , "> " ],
51- $ indented
52- );
53- $ cleaned = $ this ->trimExcessWhitespace ($ cleaned );
54- $ expected = $ this ->trimExcessWhitespace ($ expected );
55-
56- self ::assertSame ($ expected , $ cleaned );
57- }
58-
59- protected function renderComponent (string $ template , array $ data = []): string
60- {
61- return (string ) $ this ->blade ($ template , $ data );
62- }
63-
64- protected function trimExcessWhitespace (string $ content ): string
65- {
66- return trim (
67- preg_replace ('/\s+/ ' , ' ' , $ content )
68- );
69- }
7051}
0 commit comments