Skip to content

Instantly share code, notes, and snippets.

@tamakiii
Created January 6, 2015 07:18
Show Gist options
  • Save tamakiii/cff61a78f8245b127e16 to your computer and use it in GitHub Desktop.
Save tamakiii/cff61a78f8245b127e16 to your computer and use it in GitHub Desktop.
snippet ->
options word
$this->${1:...}
snippet []
options word
array(${1});
snippet instanceof
options word
${1:...} instanceof ${2:...}
snippet interface_file
<?php
namespace ${1:...};
/**
* ${2}
*/
interface ${3:...}
{
${0}
}
snippet interface_method
alias method_interface
alias public_interface_method
/**
* ${0}
*/
${1:public} function ${2:...}(${3});
snippet class_file
<?php
namespace ${1:...};
/**
* ${2}
*/
class ${3:...}
{
${0}
}
snippet class_method
alias method_class
alias public_class_method
/**
* ${4}
*/
${1:public} function ${2:...}(${3})
{
${0}
}
snippet class_var
alias var_class
/**
* @var ${1}
*/
${2:private} $${3:...};
snippet doc_param
alias @param
/**
* @param ${1} $${2}
*/
snippet doc_param_return
alias @param_return
alias @pr
/**
* @param ${1} $${2}${0}
* @return ${3}
*/
snippet closure
function(${1}) ${2: use } {
${3:TARGET}
};
snippet if
options head
if (${1:#:...}) {
${0}
}
snippet else
else {
${0:TARGET}
}
snippet elseif
elseif (${1:#:condition}) {
${0:TARGET}
}
snippet for
options head
for ($${1:i}=${2:0}; $$1 < ${3}; $$1++) {
${0:TARGET}
}
snippet foreach
foreach ($${1:#:variable} as $${2:#:key}${3: =>} $${4:#:value}) {
${0:TARGET}
}
snippet var_dump
alias dump
options head
var_dump(${0});
snippet content_type
header("Content-type: ${1:text/plain;}");${0}
snippet throw
options head
throw new ${1}Exception(${2:"${3:#:Error Processing Request}"}${4:});
${0}
snippet phake_mock
alias mock_phake
Phake::mock('${1}');
snippet phake_when
alias when_phake
Phake::when(${1})
->${2}(${3})
->then${4}(${5});
snippet phake_verify
alias verify_phake
Phake::verify($${1:#:mock}, Phake::times(${2:#:0}))
->${3}(${4});
snippet test_class
<?php
namespace ${1:...};
use ${2:...};
${3:use Phake;}
/**
* Tests for ${4}.
*/
class ${5:...} extends \PHPUnit_Framework_TestCase
{
/**
* Set up
*/
public function setUp()
{
${6}
}
}
snippet test_interface
<?php
namespace ${1:...};
use Phake;
/**
* Tests for ${2}.
*/
class ${3:...} extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function ${5:canUse}()
{
Phake::mock('${6:...}');
}
}
snippet test_method
alias @test
/**
* @test
*/
public function ${1:...}()
{
${0}
}
snippet test_data_provider
alias data_provider_method
/**
* @return array
*/
public function ${1:...}DataProvider()
{
return array(
array(${0}),
);
}
snippet test_assert_instanceof
alias assert_instanceof
$this->assertInstanceOf(
'${1:...}',
${0:...}
);
snippet test_assert_same
alias assert_same
$this->assertSame(
${1:...},
${2:...}
);
snippet test_assert_true
alias assert_true
$this->asssertTrue(${1:...});
snippet test_assert_false
alias assert_false
$this->asssertFalse(${1:...});
snippet service_provider
<?php
namespace ${1};
/**
* ${2}service provider.
*/
class ${3}ServiceProvider implements \Pimple\ServiceProviderInterface
{
/**
* @param \Pimple\Container $container
*/
public function register(\Pimple\Container $container)
{
${0}
}
}
@tamakiii
Copy link
Author

tamakiii commented Jan 6, 2015

基本的な使い方

  • .vimrcNeoBundle 'https://github.com/Shougo/neosnippet.vim' と書いて使う
  • :ft = php で動作する
  • キーワードを打って Control+nControl+p で移動する
  • tabで補完

難のある所

  • tabが他と喧嘩するかも
  • tabのタゲが何かアレなときがある
    • 基本的に1つの補完をすべて入力してから次の補完に入るような手順を取るように身体を作る
  • "-" を補完キーワードに入れると、例えば interface-file だと全部を入力するとダメで、interface まで打って Control+n で選択→tabしないとダメ

よく使うスニペット

補完キーワード 用途
[] array();
-> $this->
interface_file 新規インターフェースの作成
class_file 新規クラスの作成
closure クロージャ
service_provider Pimpleの新規サービスプロバイダの作成
mock_phake Phake::mock('...');
when_phake Phake::when($...)->...->then...();
test_class 新規テストクラスの作成
test_interface 新規インターフェースクラスのテストクラスの作成
@test テストメソッドの作成
assert_... PHPUnitのアサーション

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment