મુખ્ય સામગ્રીને બાયપાસ કરો

Playground CLI સાથે PHPUnit ચલાવવું

Playground CLI માં php સબકમાન્ડ (subcommand) શામેલ છે, જે PHP સ્ક્રિપ્ટ્સને સીધા પ્લેગ્રાઉન્ડ વાતાવરણમાં ચલાવે છે. તમારા પ્લગઇન અથવા થીમને પ્લેગ્રાઉન્ડ ફાઇલસિસ્ટમ (filesystem) માં માઉન્ટ (mount) કરીને, તમે સ્થાનિક ડેટાબેઝ વિના PHPUnit ચલાવી શકો છો. દરેક રન સ્વચ્છ વર્ડપ્રેસ ઇન્સ્ટોલેશનથી શરૂ થાય છે, તેથી પરીક્ષણો સંપૂર્ણપણે અલગ (isolated) રહે છે.

આ માર્ગદર્શિકા ધારે છે કે તમારા પ્લગઇન અથવા થીમમાં Composer દ્વારા PHPUnit ઇન્સ્ટોલ કરેલું છે (composer require --dev phpunit/phpunit). નીચે વપરાયેલ vendor/bin/phpunit પાથ સામાન્ય (standard) Composer સેટઅપ ધારે છે.

પરીક્ષણો ચલાવવા​

તમારા પ્લગઇન અથવા થીમની ડિરેક્ટરીમાંથી નીચેનો કમાન્ડ ચલાવો. themes/THEME_NAME ને તમારા પ્લગઇન અથવા થીમના પાથથી બદલો:

npx @wp-playground/cli@latest php \
--auto-mount \
-- \
/wordpress/wp-content/themes/THEME_NAME/vendor/bin/phpunit \
-c /wordpress/wp-content/themes/THEME_NAME/phpunit.xml.dist

--auto-mount ફ્લેગ (flag) શોધી કાઢે છે કે વર્તમાન ડિરેક્ટરી પ્લગઇન છે, થીમ છે કે વર્ડપ્રેસ ઇન્સ્ટોલેશન છે, અને તેને /wordpress/wp-content/ હેઠળ યોગ્ય પાથ પર માઉન્ટ કરે છે. -- CLI ફ્લેગ્સને PHP ઇન્ટરપ્રેટર (interpreter) ને મોકલાતા આર્ગ્યુમેન્ટ્સ (arguments) થી અલગ કરે છે, અને તમે તમારા PHPUnit કન્ફિગરેશન દ્વારા સપોર્ટેડ કોઈપણ આર્ગ્યુમેન્ટ્સ પાસ કરી શકો છો.

પ્લગઇન માટે, પાથમાં તેના બદલે plugins/ નો ઉપયોગ થશે:

npx @wp-playground/cli@latest php \
--auto-mount \
-- \
/wordpress/wp-content/plugins/MY_PLUGIN/vendor/bin/phpunit \
-c /wordpress/wp-content/plugins/MY_PLUGIN/phpunit.xml.dist

સ્થાનિક ડિરેક્ટરીને પ્લેગ્રાઉન્ડ ફાઇલસિસ્ટમની અંદરના પાથ સાથે સ્પષ્ટ રીતે જોડવા (map) માટે તમે --mount નો ઉપયોગ પણ કરી શકો છો:

npx @wp-playground/cli@latest php \
--mount=.:/wordpress/wp-content/plugins/MY_PLUGIN \
-- \
/wordpress/wp-content/plugins/MY_PLUGIN/vendor/bin/phpunit \
-c /wordpress/wp-content/plugins/MY_PLUGIN/phpunit.xml.dist

PHP અને વર્ડપ્રેસ વર્ઝન પસંદ કરવા​

ચોક્કસ વર્ઝન સામે પરીક્ષણ કરવા માટે --php અને --wp ફ્લેગ્સનો ઉપયોગ કરો:

npx @wp-playground/cli@latest php \
--auto-mount \
--php=8.1 \
--wp=6.5 \
-- \
/wordpress/wp-content/plugins/MY_PLUGIN/vendor/bin/phpunit \
-c /wordpress/wp-content/plugins/MY_PLUGIN/phpunit.xml.dist

સપોર્ટેડ PHP વર્ઝન 7.4 થી 8.5 સુધીના છે. વર્ડપ્રેસ માટે, તમે ચોક્કસ વર્ઝન નંબર, latest, nightly, અથવા beta નો ઉપયોગ કરી શકો છો.

આગળનાં પગલાં​