Skip to content

Commit

Permalink
Added extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
luisdalmolin committed Jun 1, 2020
1 parent 0e92ed8 commit df5992a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
10 changes: 4 additions & 6 deletions php-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ const phpLoader = {
content = content.replace(/\?>\s*$/, '_')

let langObject = {}
let parsedContent = null

try {
parsedContent = phpArrayParser.parse(content);
let parsedContent = phpArrayParser.parse(content);
langObject[filename.replace('.php', '')] = parsedContent;
} catch (e) {
console.warn('The file "' + file.path + '" could not be parsed', e.message)
}
if (parsedContent !== null) {
langObject[filename.replace('.php', '')] = parsedContent
console.warn('The file "' + file.path + '" could not be parsed', e.message);
}

if (typeof options.namespace !== 'undefined') {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/php-with-one-invalid-file/en/invalid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

return require_once('inexisting-file.php');
8 changes: 8 additions & 0 deletions test/fixtures/php-with-one-invalid-file/en/translation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validation' => [
'required' => 'this field is required',
],
'another' => 'translation',
];
8 changes: 8 additions & 0 deletions test/fixtures/php-with-one-invalid-file/es/translation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'validation' => [
'required' => 'este campo es obrigatorio',
],
'another' => 'traducion',
];
13 changes: 13 additions & 0 deletions test/php.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,17 @@ describe('it should load php language files', function () {
}
});
});

it('should not fail execution with invalid file', function () {
let content = phpLoader.execute('./test/fixtures/php-with-one-invalid-file', {});

assert.deepEqual(content.en, {
translation: {
validation: {
required: 'this field is required',
},
another: 'translation',
}
});
});
});

0 comments on commit df5992a

Please sign in to comment.