|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tatter\Assets\Test; |
| 4 | + |
| 5 | +use CodeIgniter\Publisher\Publisher; |
| 6 | +use Tatter\Assets\Bundle; |
| 7 | + |
| 8 | +abstract class BundlesTestCase extends TestCase |
| 9 | +{ |
| 10 | + private $didPublish = false; |
| 11 | + |
| 12 | + /** |
| 13 | + * Publishes all files once so they are |
| 14 | + * available for bundles. |
| 15 | + */ |
| 16 | + protected function setUp(): void |
| 17 | + { |
| 18 | + parent::setUp(); |
| 19 | + |
| 20 | + // Make sure everything is published |
| 21 | + if (! $this->didPublish) { |
| 22 | + foreach (Publisher::discover() as $publisher) { |
| 23 | + $publisher->publish(); // @codeCoverageIgnore |
| 24 | + } |
| 25 | + |
| 26 | + $this->didPublish = true; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @dataProvider bundleProvider |
| 32 | + * |
| 33 | + * @param class-string<Bundle> $class |
| 34 | + * @param string[] $expectedHeadFiles |
| 35 | + * @param string[] $expectedBodyFiles |
| 36 | + */ |
| 37 | + public function testBundlesFiles(string $class, array $expectedHeadFiles, array $expectedBodyFiles): void |
| 38 | + { |
| 39 | + $bundle = new $class(); |
| 40 | + $head = $bundle->head(); |
| 41 | + $body = $bundle->body(); |
| 42 | + |
| 43 | + foreach ($expectedHeadFiles as $file) { |
| 44 | + $this->assertStringContainsString($file, $head); |
| 45 | + } |
| 46 | + |
| 47 | + foreach ($expectedBodyFiles as $file) { |
| 48 | + $this->assertStringContainsString($file, $body); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Returns an array of items to test with each item |
| 54 | + * as a triple of [string bundleClassName, string[] headFileNames, string[] bodyFileNames] |
| 55 | + */ |
| 56 | + abstract public function bundleProvider(): array; |
| 57 | +} |
0 commit comments