Skip to content

Commit dcab6f8

Browse files
committed
phpspec matcher snippets
1 parent f84d1ef commit dcab6f8

File tree

1 file changed

+190
-6
lines changed

1 file changed

+190
-6
lines changed

UltiSnips/php-phpspec.snippets

Lines changed: 190 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# Snippets for phpspec
1+
# Snippets for phpspec, to use add the following to your .vimrc
2+
# `autocmd BufRead,BufNewFile,BufEnter *Spec.php UltiSnipsAddFiletypes php-phpspec`
23

34
priority -50
45

5-
snippet spec "phpspec class" b
6+
snippet spec "class XYZSpec extends ObjectBehaviour"
67
<?php
78

89
namespace `!p
@@ -22,17 +23,200 @@ class `!p
2223
snip.rv = re.match(r'.*(?=\.)', fn).group()
2324
` extends ObjectBehavior
2425
{
25-
public function it${1:_does_something}()
26+
function it${1}()
2627
{
2728
$0
2829
}
2930
}
3031
endsnippet
3132

32-
snippet it "phpspec function it..." b
33-
public function it${1:_does_something}()
33+
snippet it "function it_does_something() { ... }"
34+
function it${1}()
3435
{
35-
$0
36+
${0:${VISUAL}}
3637
}
3738
endsnippet
3839

40+
snippet let "function let() { ... }"
41+
function let()
42+
{
43+
${0:${VISUAL}}
44+
}
45+
endsnippet
46+
47+
snippet letgo "function letgo() { ... }"
48+
function letgo()
49+
{
50+
${0:${VISUAL}}
51+
}
52+
endsnippet
53+
54+
# Object construction
55+
snippet cw "$this->beConstructedWith($arg)"
56+
$this->beConstructedWith(${1});
57+
endsnippet
58+
59+
snippet ct "$this->beConstructedThrough($methodName, [$arg])"
60+
$this->beConstructedThrough(${1:'methodName'}, [${2:'$arg'}]);
61+
endsnippet
62+
63+
# Identity and comparison matchers
64+
snippet sreturn "$this->XYZ()->shouldReturn('value')"
65+
$this->${1:method}()->shouldReturn(${2:'value'});
66+
endsnippet
67+
68+
snippet snreturn "$this->XYZ()->shouldNotReturn('value')"
69+
$this->${1:method}()->shouldNotReturn(${2:'value'});
70+
endsnippet
71+
72+
snippet sbe "$this->XYZ()->shouldBe('value')"
73+
$this->${1:method}()->shouldBe(${2:'value'});
74+
endsnippet
75+
76+
snippet snbe "$this->XYZ()->shouldNotBe('value')"
77+
$this->${1:method}()->shouldNotBe(${2:'value'});
78+
endsnippet
79+
80+
snippet sequal "$this->XYZ()->shouldEqual('value')"
81+
$this->${1:method}()->shouldEqual(${2:'value'});
82+
endsnippet
83+
84+
snippet snequal "$this->XYZ()->shouldNotEqual('value')"
85+
$this->${1:method}()->shouldNotEqual(${2:'value'});
86+
endsnippet
87+
88+
snippet sbequalto "$this->XYZ()->shouldBeEqualTo('value')"
89+
$this->${1:method}()->shouldBeEqualTo(${2:'value'});
90+
endsnippet
91+
92+
snippet snbequalto "$this->XYZ()->shouldNotBeEqualTo('value')"
93+
$this->${1:method}()->shouldNotBeEqualTo(${2:'value'});
94+
endsnippet
95+
96+
snippet sblike "$this->XYZ()->shouldBeLike('value')"
97+
$this->${1:method}()->shouldBeLike(${2:'value'});
98+
endsnippet
99+
100+
snippet snblike "$this->XYZ()->shouldNotBeLike('value')"
101+
$this->${1:method}()->shouldNotBeLike(${2:'value'});
102+
endsnippet
103+
104+
# Throw matcher
105+
snippet sthrowm "$this->shouldThrow('\Exception')->duringXYZ($arg)"
106+
$this->shouldThrow(${1:'\Exception'})->during${2:Method}(${3:'$arg'});
107+
endsnippet
108+
109+
snippet sthrowi "$this->shouldThrow('\Exception')->duringInstantiation()"
110+
$this->shouldThrow(${1:'\Exception'})->duringInstantiation();
111+
endsnippet
112+
113+
# Type matchers
114+
snippet stype "$this->shouldHaveType('Type')"
115+
$this->shouldHaveType(${1});
116+
endsnippet
117+
118+
snippet sntype "$this->shouldNotHaveType('Type')"
119+
$this->shouldNotHaveType(${1});
120+
endsnippet
121+
122+
snippet srinstance "$this->shouldReturnAnInstanceOf('Type')"
123+
$this->shouldReturnAnInstanceOf(${1});
124+
endsnippet
125+
126+
snippet snrinstance "$this->shouldNotReturnAnInstanceOf('Type')"
127+
$this->shouldNotReturnAnInstanceOf(${1});
128+
endsnippet
129+
130+
snippet sbinstance "$this->shouldBeAnInstanceOf('Type')"
131+
$this->shouldBeAnInstanceOf(${1});
132+
endsnippet
133+
134+
snippet snbinstance "$this->shouldNotBeAnInstanceOf('Type')"
135+
$this->shouldNotBeAnInstanceOf(${1});
136+
endsnippet
137+
138+
snippet simplement "$this->shouldImplement('Type')"
139+
$this->shouldImplement(${1});
140+
endsnippet
141+
142+
snippet snimplement "$this->shouldNotImplement('Type')"
143+
$this->shouldNotImplement(${1});
144+
endsnippet
145+
146+
# Object state matchers
147+
snippet sbstate "$this->shouldBeXYZ()"
148+
$this->shouldBe${1}();
149+
endsnippet
150+
151+
snippet snbstate "$this->shouldNotBeXYZ()"
152+
$this->shouldNotBe${1}();
153+
endsnippet
154+
155+
# Count matchers
156+
snippet scount "$this->XYZ()->shouldHaveCount(7)"
157+
$this->${1:method}()->shouldHaveCount(${2:7});
158+
endsnippet
159+
160+
snippet sncount "$this->XYZ()->shouldNotHaveCount(7)"
161+
$this->${1:method}()->shouldNotHaveCount(${2:7});
162+
endsnippet
163+
164+
# Scalar type matchers
165+
snippet sbscalar "$this->XYZ()->shouldBeString|Array|Bool()"
166+
$this->${1:method}()->shouldBe(${2:'String|Array|Bool'});
167+
endsnippet
168+
169+
snippet snbscalar "$this->XYZ()->shouldNotBeString|Array|Bool()"
170+
$this->${1:method}()->shouldNotBe(${2:'String|Array|Bool'});
171+
endsnippet
172+
173+
# Contain matcher
174+
snippet scontain "$this->XYZ()->shouldContain('value')"
175+
$this->${1:method}()->shouldContain(${2:'value'});
176+
endsnippet
177+
178+
snippet sncontain "$this->XYZ()->shouldNotContain('value')"
179+
$this->${1:method}()->shouldNotContain(${2:'value'});
180+
endsnippet
181+
182+
# Array matchers
183+
snippet skey "$this->XYZ()->shouldHaveKey('key')"
184+
$this->${1:method}()->shouldHaveKey(${2:'key'});
185+
endsnippet
186+
187+
snippet snkey "$this->XYZ()->shouldNotHaveKey('key')"
188+
$this->${1:method}()->shouldNotHaveKey(${2:'key'});
189+
endsnippet
190+
191+
snippet skeyvalue "$this->XYZ()->shouldHaveKeyWithValue('key', 'value')"
192+
$this->${1:method}()->shouldHaveKeyWithValue(${2:'key'}, ${3:'value'});
193+
endsnippet
194+
195+
snippet snkeyvalue "$this->XYZ()->shouldNotHaveKeyWithValue('key', 'value')"
196+
$this->${1:method}()->shouldNotHaveKeyWithValue(${2:'key'}, ${3:'value'});
197+
endsnippet
198+
199+
# String matchers
200+
snippet sstart "$this->XYZ()->shouldStartWith('string')"
201+
$this->${1:method}()->shouldStartWith(${2:'string'});
202+
endsnippet
203+
204+
snippet snstart "$this->XYZ()->shouldNotStartWith('string')"
205+
$this->${1:method}()->shouldNotStartWith(${2:'string'});
206+
endsnippet
207+
208+
snippet send "$this->XYZ()->shouldEndWith('string')"
209+
$this->${1:method}()->shouldEndWith(${2:'string'});
210+
endsnippet
211+
212+
snippet snend "$this->XYZ()->shouldNotEndWith('string')"
213+
$this->${1:method}()->shouldNotEndWith(${2:'string'});
214+
endsnippet
215+
216+
snippet smatch "$this->XYZ()->shouldMatch('/wizard/i')"
217+
$this->${1:method}()->shouldMatch(${2:'/wizard/i'});
218+
endsnippet
219+
220+
snippet snmatch "$this->XYZ()->shouldNotMatch('/wizard/i')"
221+
$this->${1:method}()->shouldNotMatch(${2:'/wizard/i'});
222+
endsnippet

0 commit comments

Comments
 (0)