gerardroche / sublime-phpunit

PHPUnit Sublime Text integration.
https://www.gerardroche.com
GNU General Public License v3.0
74 stars 11 forks source link

Support running in iTerm #86

Closed gerardroche closed 5 years ago

gerardroche commented 5 years ago

Re: https://twitter.com/paulredmond/status/1058048109975035904

ghost commented 5 years ago

I was coming here to request this feature and see you're already planning on implementing this.

Do you have an ETA on this?

gerardroche commented 5 years ago

I don't work on OS X so this hasn't been a priority. I also need to get my hands on a Mac to test it. I'm going to take a look now and maybe you can test and tweak it.

gerardroche commented 5 years ago

There's a WIP in the osx branch. I've no idea if it works, I'll need to get my hands on a Mac. To try it, set the strategy setting to "iterm":

Menu > Preferences > Settings

{
    "phpunit.strategy": "iterm"
}

If it doesn't work, try tweaking this piece of code:

        if self.view.settings().get('phpunit.strategy') == 'iterm':
            osx_iterm_script = os.path.join(
                os.path.dirname(os.path.realpath(__file__)), 'bin', 'osx_iterm')

            print('env =', env)
            print('working dir =', working_dir)
            print('cmd =', cmd)
            print('osx_iterm_script =', osx_iterm_script)

            cmd = [osx_iterm_script] + cmd
            print('full cmd =', cmd)

            self.window.run_command('exec', {
                'env': env,
                'cmd': cmd,
                'quiet': not is_debug(self.view),
                'shell': False,
                'working_dir': working_dir
            })
        else:

See: https://github.com/gerardroche/sublime-phpunit/blob/8390de6c3cb8e2b3bb677333b3663eca16dd67ea/plugin.py#L572

ghost commented 5 years ago

Thanks for taking the time to add this :)

using the follow code I get this message

[Errno 2] No such file or directory: '/Users/carlos/Library/Application Support/Sublime Text 3/Packages/sublime-phpunit/bin/osx_iterm'
[cmd: ['/Users/carlos/Library/Application Support/Sublime Text 3/Packages/sublime-phpunit/bin/osx_iterm', '/usr/local/bin/phpunit', '--filter', '::(a_user_can_create_a_project)( with data set .+)?$', 'tests/Feature/ProjectsTest.php']]
[dir: /Users/carlos/Code/birdboard]
[path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/gettext/bin:/usr/local/sbin:/Users/carlos/bin:/Users/carlos/.composer/vendor/bin:/usr/local/opt/fzf/bin]
ghost commented 5 years ago

After adding bin/osx_iterm the message changes to

[Errno 13] Permission denied
[cmd: ['/Users/carlos/Library/Application Support/Sublime Text 3/Packages/sublime-phpunit/bin/osx_iterm', '/usr/local/bin/phpunit', '--filter', '::(a_user_can_create_a_project)( with data set .+)?$', 'tests/Feature/ProjectsTest.php']]
[dir: /Users/carlos/Code/birdboard]
[path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/gettext/bin:/usr/local/sbin:/Users/carlos/bin:/Users/carlos/.composer/vendor/bin:/usr/local/opt/fzf/bin]
gerardroche commented 5 years ago

You have PHPUnitKit cloned into the directory "sublime-phpunit". Rename it "PHPUnitKit".

Instead of:

/Users/carlos/Library/Application Support/Sublime Text 3/Packages/sublime-phpunit

Rename the folder to:

/Users/carlos/Library/Application Support/Sublime Text 3/Packages/PHPUnitKit
gerardroche commented 5 years ago

If there's still a permissions issue, check what permissions the osx_iterm script has. Perhaps on clone or pull the permissions changed.

gerardroche commented 5 years ago

The current script permissions are set to chmod 744, you maybe need chmod 774 or chmod 777, though I'm not sure why that would be.

gerardroche commented 5 years ago

Try chmod 755 which will give it the permissions -rwxr-xr-x.

ghost commented 5 years ago

Yep changing the permissions did the trick.

A few issues though, running Test Nearest is running the whole test suite and iTerm is staying in the background, is there a way to bring it to the front?

And for some reason MacVim is opening.

debug

env = {}
working dir = /Users/carlos/Code/birdboard
cmd = ['/Users/carlos/Code/birdboard/vendor/bin/phpunit', '--filter', '::(a_user_can_create_a_project)( with data set .+)?$', 'tests/Feature/ProjectsTest.php']
osx_iterm_script = /Users/carlos/Library/Application Support/Sublime Text 3/Packages/PHPUnitKit/bin/osx_iterm
full cmd = ['/Users/carlos/Library/Application Support/Sublime Text 3/Packages/PHPUnitKit/bin/osx_iterm', '/Users/carlos/Code/birdboard/vendor/bin/phpunit', '--filter', '::(a_user_can_create_a_project)( with data set .+)?$', 'tests/Feature/ProjectsTest.php']

iterm

gerardroche commented 5 years ago

Hmm. Can you maybe try add activate to the iTerm2 section in the osx script:

Change

#!/usr/bin/osascript

on run argv
  tell application "iTerm2"
    set _window to (current window)
    if _window is equal to missing value then
      create window with default profile
    end if
    tell current window
      tell current session
        write text (item 1 of argv)
      end tell
    end tell
  end tell

  tell application "MacVim"
    activate
  end tell
end run

To

#!/usr/bin/osascript

on run argv
  tell application "iTerm2"
    activate
    set _window to (current window)
    if _window is equal to missing value then
      create window with default profile
    end if
    tell current window
      tell current session
        write text (item 1 of argv)
      end tell
    end tell
  end tell

  tell application "MacVim"
    activate
  end tell
end run

Also try removing the last part:

  tell application "MacVim"
    activate
  end tell

We're not using MacVim.

Or try modifying the last section to:

  tell application "iTerm2"
    activate
  end tell

iterm scripting: https://iterm2.com/documentation-scripting.html

ghost commented 5 years ago

Great :) MacVim isn't opening and iTerm is coming to the front.

Any idea why --filterisn't being applied?

gerardroche commented 5 years ago

Are all of the arguments being passed to command-line? For example, are you able to run a single test case? I think iTerm2 might only be receiving the first argument, which is the path to phpunit. Try running a single test case.

Try changing

        write text (item 1 of argv)

to

        repeat with arg in argv
          write text arg
        end repeat
gerardroche commented 5 years ago

Did you manage to get it working? I've updated the osx branch with fixes above: https://github.com/gerardroche/sublime-phpunit/pull/88. If you could test it that would be great.