Add watch php files to execute phpunit tests

Hey @TheLarkInn,

Thanks for getting back to me on twitter.

What I was looking for was some type of webpack snippet that I could place in my config file so that I could add the ability to do a npm run tdd from my package.json. In there I would call webpack with some argument that would run the task to sit and watch like webpack --watch --progress --hide-modules tdd and run the task so that I could do the following:

  1. Watch for *.php files in my directory tree of my choosing.
  2. When any file changes, execute the ./vendor/bin/phpunit command
  3. Bonus: If it is also possible to do something where I do webpack –watch –progress –hide-modules tdd –filter=sometest, that would be cool too so that I can run the ./vendor/bin/phpunit –filter=somtest` command.

The motivation here is that @jefferyway has come out with laravel-mix. But currently it lacks the ability to do this, so I was hoping to figure out the webpack.config.js tricks to add this in so I could contribute to that other project.


Author: Fantashit

1 thought on “Add watch php files to execute phpunit tests

  1. @cmosguy Woking “TDD” solution (not an elegant one) for Laravel 5.4 using Webpack and Mix:

    const { mix } = require('laravel-mix');
    mix.js('resources/assets/js/app.js', 'public/js')
       .sass('resources/assets/sass/app.scss', 'public/css');
        plugins: [
            new mix.plugins.BrowserSyncPlugin(Object.assign({
                host: 'localhost',
                port: 3000,
                proxy: '',
                files: [{
                    match: [
                    fn: function(event, file) {
                        if (event === 'change') {
                            var bs = require("browser-sync").get('bs-webpack-plugin');
                            if (process.env.NODE_ENV === 'testing') {
                                const exec = require('child_process').exec;
                                exec('php vendor/bin/phpunit', (error, stdout, stderr) => {
                                    if (error) {
                                        console.error(`exec error: ${error}`);
            }, {name: "bs-webpack-plugin"}))
    	"scripts": {
    		"tdd": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=testing node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

    To start it, just run npm run tdd on console.

Comments are closed.