Skip to content

Commit

Permalink
Add test for violation of void return type
Browse files Browse the repository at this point in the history
  • Loading branch information
asmblah committed Mar 24, 2024
1 parent 94c85c8 commit 3304bf7
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/integration/types/voidTypeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

var expect = require('chai').expect,
nowdoc = require('nowdoc'),
tools = require('../tools');
phpCommon = require('phpcommon'),
tools = require('../tools'),
PHPFatalError = phpCommon.PHPFatalError;

describe('PHP void return type integration', function () {
it('should allow functions that have no explicit return or return void', async function () {
Expand Down Expand Up @@ -50,4 +52,27 @@ EOS
'return void': 101
});
});

it('should raise an error when a value is returned with void return type', async function () {
var php = nowdoc(function () {/*<<<EOS
<?php
// -- Some padding to inflate line numbers a bit --
function myFunction(): void {
return 21;
}
myFunction();
EOS
*/;}); //jshint ignore:line

expect(function () {
// Void return violations are caught at transpile time.
tools.asyncTranspile('/path/to/my_module.php', php);
}).to.throw(
PHPFatalError,
'PHP Fatal error: A void function must not return a value in /path/to/my_module.php on line 6'
);
});
});

0 comments on commit 3304bf7

Please sign in to comment.