22
33namespace Tests \Support ;
44
5+ use CodeIgniter \Publisher \Publisher ;
56use CodeIgniter \Test \CIUnitTestCase ;
67use org \bovigo \vfs \vfsStream ;
78use org \bovigo \vfs \vfsStreamDirectory ;
89use Tatter \Assets \Asset ;
910use Tatter \Assets \Config \Assets as AssetsConfig ;
11+ use Tatter \Frontend \FrontendBundle ;
12+ use Tatter \Frontend \FrontendPublisher ;
1013
1114abstract class TestCase extends CIUnitTestCase
1215{
@@ -31,8 +34,8 @@ protected function setUp(): void
3134
3235 $ this ->root = vfsStream::setup ('root ' );
3336
34- // Create the config (if a trait has not already)
35- $ this ->config = Asset:: config ();
37+ // Create the config
38+ $ this ->config = config (' Assets ' );
3639 $ this ->config ->directory = $ this ->root ->url () . DIRECTORY_SEPARATOR ;
3740 $ this ->config ->useTimestamps = false ; // These make testing much harder
3841
@@ -41,4 +44,61 @@ protected function setUp(): void
4144 // Add VFS as an allowed Publisher directory
4245 config ('Publisher ' )->restrictions [$ this ->config ->directory ] = '* ' ;
4346 }
47+
48+ /**
49+ * Preps the config and VFS.
50+ */
51+ protected function tearDown (): void
52+ {
53+ parent ::tearDown ();
54+
55+ $ this ->root = null ; // @phpstan-ignore-line
56+ $ this ->resetServices ();
57+ }
58+
59+ /**
60+ * @param class-string<FrontendPublisher> $class
61+ * @param string[] $expected
62+ */
63+ public function assertPublishesFiles (string $ class , array $ expected ): void
64+ {
65+ $ publisher = new $ class ();
66+ $ result = $ publisher ->publish ();
67+
68+ // Verify that publication succeeded
69+ $ this ->assertTrue ($ result );
70+ $ this ->assertSame ([], $ publisher ->getErrors ());
71+ $ this ->assertNotSame ([], $ publisher ->getPublished ());
72+
73+ // Check for each of the expected files
74+ foreach ($ expected as $ path ) {
75+ $ file = $ this ->config ->directory . $ this ->config ->vendor . $ path ;
76+ $ this ->assertFileExists ($ file );
77+ }
78+ }
79+
80+ /**
81+ * @param class-string<FrontendBundle> $class
82+ * @param string[] $expectedHeadFiles
83+ * @param string[] $expectedBodyFiles
84+ */
85+ public function assertBundlesFiles (string $ class , array $ expectedHeadFiles , array $ expectedBodyFiles ): void
86+ {
87+ // Make sure everything is published
88+ foreach (Publisher::discover () as $ publisher ) {
89+ $ publisher ->publish ();
90+ }
91+
92+ $ bundle = new $ class ();
93+ $ head = $ bundle ->head ();
94+ $ body = $ bundle ->body ();
95+
96+ foreach ($ expectedHeadFiles as $ file ) {
97+ $ this ->assertStringContainsString ($ file , $ head );
98+ }
99+
100+ foreach ($ expectedBodyFiles as $ file ) {
101+ $ this ->assertStringContainsString ($ file , $ body );
102+ }
103+ }
44104}
0 commit comments