Skip to content

Commit 120ead2

Browse files
committed
Tidied up and consolidated snippets for PHPUnit
1 parent 3b7c903 commit 120ead2

File tree

3 files changed

+77
-122
lines changed

3 files changed

+77
-122
lines changed

UltiSnips/php-phpunit.snippets

Lines changed: 0 additions & 76 deletions
This file was deleted.

UltiSnips/php.snippets

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,29 @@ snippet inheritdoc "@inheritdoc docblock"
363363
*/
364364
endsnippet
365365

366+
# PHPUnit snippets
367+
snippet testcase "class XYZTest extends \PHPUnit_Framework_TestCase { ... }"
368+
<?php
369+
370+
namespace `!p
371+
relpath = os.path.relpath(path)
372+
m = re.search(r'[A-Z].+(?=/)', relpath)
373+
if m:
374+
snip.rv = m.group().replace('/', '\\')
375+
`;
376+
377+
/**
378+
* @author `!v g:snips_author`
379+
*/
380+
class `!p
381+
snip.rv = re.match(r'.*(?=\.)', fn).group()
382+
` extends \PHPUnit_Framework_TestCase
383+
{
384+
public function test${1}()
385+
{
386+
${0:${VISUAL}}
387+
}
388+
}
389+
endsnippet
390+
366391
# :vim:ft=snippets:

snippets/php.snippets

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ snippet ns
2727
snippet use
2828
use ${1:Foo\Bar\Baz};
2929
${0}
30-
snippet c
30+
snippet c
3131
class ${1:`vim_snippets#Filename()`}
3232
{
3333
${0}
@@ -571,71 +571,77 @@ snippet CSVIterator
571571

572572
} // end class
573573

574-
snippet is
574+
snippet is "isset()"
575575
isset($1{VISUAL})
576-
577-
# phpunit
578-
snippet ase
576+
# phpunit
577+
snippet ase "$this->assertEquals()"
579578
$this->assertEquals(${1:expected}, ${2:actual});
580-
581-
snippet asne
579+
snippet asne "$this->assertNotEquals()"
582580
$this->assertNotEquals(${1:expected}, ${2:actual});
583-
584-
snippet asf
585-
$this->assertFalse(${1:Something});
586-
587-
snippet ast
588-
$this->assertTrue(${1:Something});
589-
590-
snippet asfex
591-
$this->assertFileExists(${1:path/to/file});
592-
593-
snippet asfnex
594-
$this->assertFileNotExists(${1:path/to/file});
595-
596-
snippet ascon
597-
$this->assertContains(${1:Search Value}, ${2:Array or Iterator});
598-
599-
snippet ashk
600-
$this->assertArrayHasKey(${1:key}, ${2:array});
601-
602-
snippet asnhk
603-
this->assertArrayNotHasKey(${1:value}, ${2:array});
604-
605-
snippet ascha
606-
$this->assertClassHasAttribute('${1:Attribute Name}', '${2:ClassName}');
607-
608-
snippet asi
581+
snippet asf "$this->assertFalse()"
582+
$this->assertFalse(${1});
583+
snippet ast "$this->assertTrue()"
584+
$this->assertTrue(${1});
585+
snippet asfex "$this->assertFileExists()"
586+
$this->assertFileExists(${1:'path/to/file'});
587+
snippet asfnex "$this->assertFileNotExists()"
588+
$this->assertFileNotExists(${1:'path/to/file'});
589+
snippet ascon "$this->assertContains()"
590+
$this->assertContains(${1:$needle}, ${2:$haystack});
591+
snippet ashk "$this->assertArrayHasKey()"
592+
$this->assertArrayHasKey(${1:$key}, ${2:$array});
593+
snippet asnhk "$this->assertArrayNotHasKey()"
594+
this->assertArrayNotHasKey(${1:$key}, ${2:$array});
595+
snippet ascha "$this->assertClassHasAttribute()"
596+
$this->assertClassHasAttribute(${1:$attributeName}, '${2:$className}');
597+
snippet asi "$this->assertInstanceOf(...)"
609598
$this->assertInstanceOf(${1:expected}, ${2:actual});
610-
611-
snippet tc
612-
public function test${1:name_of_the_test}()
599+
snippet test "public function testXYZ() { ... }"
600+
public function test${1}()
601+
{
602+
${0}
603+
}
604+
snippet setup "protected function setUp() { ... }"
605+
protected function setUp()
613606
{
614-
${0:code}
607+
${0}
615608
}
616-
snippet te
609+
snippet teardown "protected function tearDown() { ... }"
610+
protected function tearDown()
611+
{
612+
${0}
613+
}
614+
snippet exp "phpunit expects"
615+
expects($this->${1:once}())
616+
->method('${2}')
617+
->with($this->equalTo(${3})${4})
618+
->will($this->returnValue(${5}));
619+
snippet testcmt "phpunit comment with group"
620+
/**
621+
* @group ${1}
622+
*/
623+
snippet fail "$this->fail()"
624+
$this->fail(${1});
625+
snippet marki "$this->markTestIncomplete()"
626+
$this->markTestIncomplete(${1});
627+
snippet marks "$this->markTestSkipped()"
628+
$this->markTestSkipped(${1});
629+
# end of phpunit snippets
630+
snippet te "throw new Exception()"
617631
throw new ${1:Exception}("${2:Error Processing Request}");
618-
619632
snippet fpc "file_put_contents" b
620633
file_put_contents(${1:file}, ${2:content}${3:, FILE_APPEND});$0
621-
622634
snippet sr "str_replace"
623635
str_replace(${1:search}, ${2:replace}, ${3:subject})$0
624-
625636
snippet ia "in_array"
626637
in_array(${1:needle}, ${2:haystack})$0
627-
628638
snippet is "isset"
629639
isset(${1:var})$0
630-
631640
snippet isa "isset array"
632641
isset($${1:array}[${2:key}])$0
633-
634642
snippet in "is_null"
635643
is_null($${1:var})$0
636-
637644
snippet fe "file_exists"
638645
file_exists(${1:file})$0
639-
640646
snippet id "is_dir"
641647
is_dir(${1:path})$0

0 commit comments

Comments
 (0)