Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 0cbe828

Browse files
committed
Added safery check and more tests
1 parent df99889 commit 0cbe828

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

php-loader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@ const phpLoader = {
2626
}).filter((file) => {
2727
return path.extname(file.path) === '.php';
2828
}).filter((file) => {
29-
if (typeof options.includeOnly === 'undefined') return true;
29+
if (! options || typeof options.includeOnly === 'undefined') {
30+
return true;
31+
}
32+
3033
var filename = path.basename(file.path, '.php');
3134
return options.includeOnly.includes(filename);
3235
}).filter((file) => {
33-
if (typeof options.exclude === 'undefined') return true;
36+
if (! options || typeof options.exclude === 'undefined') {
37+
return true;
38+
}
39+
3440
var filename = path.basename(file.path, '.php');
3541
return !options.exclude.includes(filename);
3642
}).forEach((file) => {

test/fixtures/php/en/auth.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'login' => 'Login',
5+
];

test/php.test.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ describe('it should load php language files', function () {
88
it('should load regular php translation', function () {
99
let content = phpLoader.execute('./test/fixtures/php', {}, loaderMock);
1010

11-
assert.deepEqual(content.en, {
11+
assert.deepStrictEqual(content.en, {
12+
auth: {
13+
login: 'Login',
14+
},
1215
translation: {
1316
validation: {
1417
required: 'this field is required',
@@ -17,11 +20,38 @@ describe('it should load php language files', function () {
1720
}
1821
});
1922
});
23+
24+
it('should be able to includeOnly options', function () {
25+
let content = phpLoader.execute('./test/fixtures/php', {
26+
includeOnly: ['auth']
27+
}, loaderMock);
28+
29+
assert.deepStrictEqual(content.en, {
30+
auth: {
31+
login: 'Login',
32+
}
33+
});
34+
});
35+
36+
it('should be able to exclude options', function () {
37+
let content = phpLoader.execute('./test/fixtures/php', {
38+
exclude: ['translation']
39+
}, loaderMock);
40+
41+
assert.deepStrictEqual(content.en, {
42+
auth: {
43+
login: 'Login',
44+
}
45+
});
46+
});
2047

2148
it('should load both languages', function () {
2249
let content = phpLoader.execute('./test/fixtures/php', {}, loaderMock);
2350

24-
assert.deepEqual(content.en, {
51+
assert.deepStrictEqual(content.en, {
52+
auth: {
53+
login: 'Login',
54+
},
2555
translation: {
2656
validation: {
2757
required: 'this field is required',

0 commit comments

Comments
 (0)