Skip to content

Commit 225b39a

Browse files
committed
test: fix
1 parent bb41542 commit 225b39a

File tree

2 files changed

+4
-77
lines changed

2 files changed

+4
-77
lines changed

src/BladeInlineScriptsProvider.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,11 @@ public function boot(): void
2121
$this->publishes([
2222
__DIR__.'/../resources/js/theme-switch-two-states/theme-init.js' => resource_path('js/theme-switch-two-states/theme-init.js'),
2323
__DIR__.'/../resources/js/theme-switch-two-states/theme-switch.js' => resource_path('js/theme-switch-two-states/theme-switch.js'),
24-
], ['theme-switch-2-states-js', 'theme-switch-2-states-php', 'theme-switch-2-states-all']);
25-
26-
// The PHP classes need JS files to also be published because they reference them.
27-
$this->publishes([
28-
__DIR__.'/../stubs/ThemeSwitchTwoStates/ThemeInitScript.php' => base_path('app/Blade/ThemeSwitchTwoStates/ThemeInitScript.php'),
29-
__DIR__.'/../stubs/ThemeSwitchTwoStates/ThemeSwitchScript.php' => base_path('app/Blade/ThemeSwitchTwoStates/ThemeSwitchScript.php'),
30-
], ['theme-switch-2-states-php', 'theme-switch-2-states-all']);
24+
], ['theme-switch-2-states-js', 'theme-switch-2-states-all']);
3125

3226
$this->publishes([
3327
__DIR__.'/../tests/js/theme-switch-two-states/theme-init.test.js' => base_path('tests/js/theme-switch-two-states/theme-init.test.js'),
3428
__DIR__.'/../tests/js/theme-switch-two-states/theme-switch.test.js' => base_path('tests/js/theme-switch-two-states/theme-switch.test.js'),
3529
], ['theme-switch-2-states-js-tests', 'theme-switch-2-states-all']);
36-
37-
$this->publishes([
38-
__DIR__.'/../tests/Unit/ThemeSwitchTwoStates/ThemeInitScriptTest.php' => base_path('tests/Unit/ThemeSwitchTwoStates/ThemeInitScriptTest.php'),
39-
__DIR__.'/../tests/Unit/ThemeSwitchTwoStates/ThemeSwitchScriptTest.php' => base_path('tests/Unit/ThemeSwitchTwoStates/ThemeSwitchScriptTest.php'),
40-
], ['theme-switch-2-states-php-tests', 'theme-switch-2-states-all']);
4130
}
4231
}

tests/Unit/BladeInlineScriptsProviderTest.php

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,6 @@
8888
->and($jsSwitchFile)->not->toBeNull();
8989
});
9090

91-
test('boot method publishes theme-switch-two-states PHP stub classes', function (): void {
92-
// Arrange
93-
$app = new Application();
94-
$provider = new BladeInlineScriptsProvider($app);
95-
96-
// Act
97-
$provider->boot();
98-
99-
// Assert
100-
$published = ServiceProvider::$publishes[BladeInlineScriptsProvider::class] ?? [];
101-
102-
$expectedClassPublishes = [];
103-
foreach ($published as $source => $destination) {
104-
if (str_contains($source, 'stubs/ThemeSwitchTwoStates')) {
105-
$expectedClassPublishes[$source] = $destination;
106-
}
107-
}
108-
109-
expect($expectedClassPublishes)->not->toBeEmpty();
110-
111-
// Check specific PHP stub files are published
112-
$sourceFiles = array_keys($expectedClassPublishes);
113-
$themeInitClass = collect($sourceFiles)->first(fn ($file) => str_contains($file, 'ThemeInitScript.php'));
114-
$themeSwitchClass = collect($sourceFiles)->first(fn ($file) => str_contains($file, 'ThemeSwitchScript.php'));
115-
116-
expect($themeInitClass)->not->toBeNull()
117-
->and($themeSwitchClass)->not->toBeNull();
118-
});
119-
12091
test('boot method publishes theme-switch-two-states JS test files', function (): void {
12192
// Arrange
12293
$app = new Application();
@@ -146,35 +117,6 @@
146117
->and($themeSwitchTest)->not->toBeNull();
147118
});
148119

149-
test('boot method publishes theme-switch-two-states PHP test files', function (): void {
150-
// Arrange
151-
$app = new Application();
152-
$provider = new BladeInlineScriptsProvider($app);
153-
154-
// Act
155-
$provider->boot();
156-
157-
// Assert
158-
$published = ServiceProvider::$publishes[BladeInlineScriptsProvider::class] ?? [];
159-
160-
$expectedPhpTestPublishes = [];
161-
foreach ($published as $source => $destination) {
162-
if (str_contains($source, 'tests/Unit/ThemeSwitchTwoStates')) {
163-
$expectedPhpTestPublishes[$source] = $destination;
164-
}
165-
}
166-
167-
expect($expectedPhpTestPublishes)->not->toBeEmpty();
168-
169-
// Check specific PHP test files are published
170-
$sourceFiles = array_keys($expectedPhpTestPublishes);
171-
$themeInitTest = collect($sourceFiles)->first(fn ($file) => str_contains($file, 'ThemeInitScriptTest.php'));
172-
$themeSwitchTest = collect($sourceFiles)->first(fn ($file) => str_contains($file, 'ThemeSwitchScriptTest.php'));
173-
174-
expect($themeInitTest)->not->toBeNull()
175-
->and($themeSwitchTest)->not->toBeNull();
176-
});
177-
178120
test('boot method sets up correct publish groups', function (): void {
179121
// Arrange
180122
$app = new Application();
@@ -187,19 +129,15 @@
187129
$groups = ServiceProvider::$publishGroups ?? [];
188130

189131
expect($groups)->toHaveKey('theme-switch-2-states-js')
190-
->and($groups)->toHaveKey('theme-switch-2-states-php')
191132
->and($groups)->toHaveKey('theme-switch-2-states-js-tests')
192-
->and($groups)->toHaveKey('theme-switch-2-states-php-tests')
193133
->and($groups)->toHaveKey('theme-switch-2-states-all');
194134

195135
// Verify 'theme-switch-2-states-all' includes all the files
196136
$allGroupFiles = $groups['theme-switch-2-states-all'] ?? [];
197137
$jsFiles = $groups['theme-switch-2-states-js'] ?? [];
198-
$phpFiles = $groups['theme-switch-2-states-php'] ?? [];
199138
$jsTestFiles = $groups['theme-switch-2-states-js-tests'] ?? [];
200-
$phpTestFiles = $groups['theme-switch-2-states-php-tests'] ?? [];
201139

202-
$expectedAllFiles = array_merge($jsFiles, $phpFiles, $jsTestFiles, $phpTestFiles);
140+
$expectedAllFiles = array_merge($jsFiles, $jsTestFiles);
203141

204142
expect(count($allGroupFiles))->toBe(count($expectedAllFiles));
205143
});
@@ -218,10 +156,10 @@
218156
foreach ($published as $source => $destination) {
219157
if (str_contains($source, 'resources/js')) {
220158
expect($destination)->toContain('resources/js/theme-switch-two-states');
221-
} elseif (str_contains($source, 'stubs/ThemeSwitchTwoStates')) {
222-
expect($destination)->toContain('app/Blade/ThemeSwitchTwoStates');
223159
} elseif (str_contains($source, 'tests/js')) {
224160
expect($destination)->toContain('tests/js/theme-switch-two-states');
161+
} else {
162+
expect(false)->toBeTrue(); // Fail the test if an unexpected file is found
225163
}
226164
}
227165
});

0 commit comments

Comments
 (0)