@@ -14,7 +14,7 @@ const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation();
1414const runMock = jest . spyOn ( main , 'run' ) ;
1515
1616// Other utilities
17- const timeRegex = / ^ \d { 2 } : \d { 2 } : \d { 2 } / ;
17+ // const timeRegex = /^\d{2}:\d{2}:\d{2}/;
1818
1919describe ( 'action' , ( ) => {
2020 beforeEach ( ( ) => {
@@ -58,9 +58,11 @@ describe('action', () => {
5858 getInputMock . mockImplementation ( name => {
5959 switch ( name ) {
6060 case 'sapi' :
61- throw new Error (
62- 'Need to input a valid sapi: cli, fpm, micro, embed'
63- ) ;
61+ return 'cl' ;
62+ case 'php-version' :
63+ return '8.2' ;
64+ case 'extensions' :
65+ return 'mbstring' ;
6466 default :
6567 return '' ;
6668 }
@@ -69,10 +71,30 @@ describe('action', () => {
6971 await main . run ( ) ;
7072 expect ( runMock ) . toHaveReturned ( ) ;
7173
72- // Verify that all of the core library functions were called correctly
73- expect ( setFailedMock ) . toHaveBeenNthCalledWith (
74- 1 ,
75- 'Need to input a valid sapi: cli, fpm, micro, embed'
76- ) ;
74+ // Verify that all the core library functions were called correctly
75+ expect ( setFailedMock ) . toHaveBeenNthCalledWith ( 1 , 'Invalid sapi' ) ;
7776 } ) ;
77+
78+ it . each `
79+ sapi | output
80+ ${ 'clvvi,micro' } | ${ 'Invalid sapi: clvvi' }
81+ ${ 'micro,clhhi' } | ${ 'Invalid sapi: clhhi' }
82+ ${ 'mieecro' } | ${ 'Invalid sapi: mieecro' }
83+ ` (
84+ 'tests the action with sapi=$sapi, php_version=$php_version, and extensions=$extensions' ,
85+ async ( { sapi, output } ) => {
86+ // Set the action's inputs as return values from core.getInput()
87+ getInputMock . mockImplementation ( name => {
88+ switch ( name ) {
89+ case 'sapi' :
90+ return sapi ;
91+ default :
92+ return '' ;
93+ }
94+ } ) ;
95+
96+ await main . run ( ) ;
97+ expect ( setFailedMock ) . toHaveBeenNthCalledWith ( 1 , output ) ;
98+ }
99+ ) ;
78100} ) ;
0 commit comments