Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Roni's avatar
Level 33

Setup Aliases for a more TDD workflow with PHP Storm

I love PHP storm, however one of the most frustrating aspects of it is syncing. Here are some solutions that really help...

So here is a gist of my bash aliases I used to get around this problem. Specifically the list command. These commands will create the files via artisan but also instantly set focus on them in the phpstorm ide so you don't have to manually sync to open them.

Hope this saves a few people a ton of hours googling.

This works on mac os 10.13.4 for other platforms I'm not really sure.


export PATH="~/.composer/vendor/bin:$PATH"
export EDITOR='subl -w'

#COMMANDS
alias ..="cd .."
alias ...="cd ../.."
alias md='mkdir -pv'
alias h='cd ~'
alias c='clear'
alias l='ls -laF'
alias flush-cache='sudo killall -HUP mDNSResponder;say DNS cache has been flushed'

#PROMPT
export PS1="\[$(tput bold)\]\[$(tput setaf 2)\]\W \[$(tput setaf 153)\]‣ \[$(tput sgr0)\]\[$(tput sgr0)\]"

#UTILITY

alias copy-key='pbcopy < ~/.ssh/id_rsa.pub'
alias edit-commands='subl ~/.settings/.bash_aliases;'
alias reload-commands='c; source ~/.settings/.bash_aliases; echo "Done."'

#ARTISAN COMMANDS
alias art='php artisan'


alias tinker='art tinker'
alias yw='c;yarn run watch'
alias dev='c;yarn run development'
alias prod='c;yarn run production'

alias last_file='lastFileFunction(){
    
    dirname=$(ls -dt * | head -1)
    echo $dirname
    

    unset -f lastFileFunction
};lastFileFunction'


#GIT
alias gts='git status'
alias gtk='git checkout'
alias gtm='git checkout master'
alias gtc='git commit -a'
alias gtp='git push origin'
alias gta='git add .'
alias gtl='git log --pretty=format:"%h : %an : %ar : %s"'
alias gtrevert='git add -A .;git stash;git stash drop stash@{0}'


alias gtep='function __complete_episode(){ 
    
    echo processing $(($*))
    git add .
    git commit -m "completed episode $*"
    git push origin master

    c

    echo "start working on episode $(($*+1))"
    
    unset -f __complete_episode
}; __complete_episode'


#NPM
alias update-npm='c; echo "Updating NPM ..."; npm install npm@latest -g;c;echo "New NPM Version:"; npm -v'


#LARAVEL 
alias list='listFunction(){

    c
    echo "Laravel Helpers List"
    echo "--------------------"
    echo ""
    echo "ft => Feature Test"
    echo "ut => Unit Test"
    echo ""
    echo "pc => Plain Controller"
    echo "rc => Resourcefull Controller"
    echo ""
    echo "pm => Plain Model (Model with migration comming for now mn)"
    echo ""
    echo "pe => Event"
    echo "fr => Form Request"
    echo "mw => Middleware"
    echo "sp => Service Provider"
    echo "mf => Model Factory"
    echo "pr => Rule"
    echo ""
    echo "nv => New View File {path/to/name or path.name or name.blade.php}"
    echo ""
    echo "mn => New Migration, jsut the name of the table create_<posts>_table"
    echo "mp => Plain Migration, mp add_something_to_posts posts"
    echo ""

unset -f listFunction   
}; listFunction'


alias ft='{ f=$(cat -); php artisan make:test ${f}Test; pstorm tests/Feature/${f}Test.php;}<<<'
alias ut='{ f=$(cat -); php artisan make:test ${f}Test --unit; pstorm tests/Unit/${f}Test.php;}<<<'
alias pc='{ f=$(cat -); php artisan make:controller ${f}Controller; pstorm app/Http/Controllers/${f}Controller.php;}<<<'
alias rc='{ f=$(cat -); php artisan make:controller ${f}Controller -r; app/Http/Controllers/${f}Controller.php;}<<<'
alias pm='{ f=$(cat -); php artisan make:model ${f}; pstorm app/${f}.php;}<<<'
alias pe='{ f=$(cat -); php artisan make:event ${f}; pstorm app/Events/${f}.php;}<<<'
alias fr='{ f=$(cat -); php artisan make:request ${f}Request; pstorm app/Http/Requests/${f}Request.php;}<<<'
alias mw='{ f=$(cat -); php artisan make:middleware ${f}; pstorm app/Http/Middleware/${f}.php;}<<<'
alias sp='{ f=$(cat -); php artisan make:provider ${f}Provider; pstorm app/Providers/${f}Provider.php;}<<<'
alias mf='{ f=$(cat -); php artisan make:factory ${f}Factory; pstorm database/factories/${f}Factory.php;}<<<'
alias pr='{ f=$(cat -); php artisan make:rule ${f}Rule; pstorm database/factories/${f}Rule.php;}<<<'
alias nv='{ f=$(cat -); php artisan make:view ${f};}<<<'

alias mn='function __migrate-new-make(){
    tab=$(php artisan make:migration create_$*_table --create=$* --table=$*); 
    pstorm database/migrations/${tab:19}.php; 
    unset -f __migrate-new-make; 
}; __migrate-new-make'

alias mp='function __migrate-make(){
    tab=$(php artisan make:migration  --table=); 
    pstorm database/migrations/${tab:19}.php; 
    unset -f __migrate-make; 
}; __migrate-make'



alias migrate='php artisan migrate'
alias fresh='redis-cli flushall; php artisan migrate:fresh'
alias rlist='php artisan route:list'

alias cda='composer dump-autoload -o'

#TESTING PHPUNIT
alias phpspec='c;vendor/bin/phpspec'
alias phpunit='c;vendor/bin/phpunit'
alias p='c;php -n vendor/bin/phpunit'
alias pf='c;php -n vendor/bin/phpunit --filter '
alias px='phpunit'
alias pfx='phpunit --filter '


This relies on one artisan command for making a view,


<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class MakeViewCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'make:view 
                        {name : The path to the new view not including /resources/views/}
                        {--force : Overwrite existing file by default}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create empty view in resources views, ';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $name = str_replace('.','/',str_replace('.blade.php','',$this->argument('name')));

        $viewNames = pathinfo($name);

        $this->createDirectories($viewNames['dirname']);
        $this->exportView($viewNames['dirname'], $viewNames['filename']);

        $this->info($name.'.blade.php created successfully.');

    }

    protected function createDirectories($path)
    {
        if (! is_dir($directory = resource_path('views/'.$path))) {
            mkdir($directory, 0755, true);
        }

    }

    protected function exportView($path, $filename)
    {
        if (file_exists($view = resource_path('views/'.$path.'/'.$filename.'.blade.php')) && ! $this->option('force')) {
            if (! $this->confirm("The [{$path}/{$filename}] view already exists. Do you want to replace it?")) {
                $this->error($view.'.blade.php not created!');
                die();
            }else{
                exec("rm $view");
//                unlink($view);
            }
        }
        touch($view);

        file_put_contents($view,"@extends('layouts.app')\n\n@section('content')\n\n@endsection");
        exec("pstorm {$view}");
    }
}

If anyone has something better or awesome to add, or would like to help make this less brittle, please feel free to add it here, or send me a message. Here are the gist links.

.bash_aliases https://gist.github.com/roni-estein/2351dfae05e062841335f0169f5a3651

MakeViewCommand https://gist.github.com/roni-estein/e4cf9a16d1b3056ab68cca79ded4314e

0 likes
1 reply
EmBee's avatar

I installed my first alias yesterday. Simply made php artisan to artisan. But in php strom this dont work. Only in my mac terminal. What can this be? My site runs under site.test with Laravel Valet.

Please or to participate in this conversation.