Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make tests fail by default & PSR1 compliance. #13

Closed
wants to merge 5 commits into from

2 participants

Stuart Grimshaw Stuart Herbert
Stuart Grimshaw

I've changed the default content to something that will cause the test to be visible in the test results rather than comments which would show as a passing test by default. It's surrounded by a tab stop so a dev can easily land on it & overwrite with their actual test.

I understand this is quite different from the initial implementation but I think it's more robust.

I've also added another tab stop in the tests for a @covers statement and made the methods it produces PSR1 compliant.

Stuart Grimshaw Stubbs Changed the default content of tests to be a call to markTestIncomplete.
I've changed the default content to something that will cause the test
to be visible in the test results rather than comments which would show
as a passing test by default.

I understand this is quite different from the initial implementation but
I think it's more robust.

I've also added another tab stop in the tests for a @covers statement
and made the methods it produces PSR1 compliant.
3bf16af
Stuart Herbert

I like the idea of making tests fail by default, and the @covers statement. I haven't spotted what you've changed to make it more PSR1-compliant.

I'm not happy with losing the comments inside the test methods, and can't accept the pull request as a result.

Stuart Grimshaw

The PSR1 change is just moving the opening curly brace on to the same line as the method definition.

I understand about the comments, what if I made each comment an incomplete test statement, might seem a bit overkill though?

Stuart Grimshaw

So, in the process of trying to work out why php-cs-fixer wasn't fixing my code with opening braces on the next line I've been reading PSR1 & 2 and it would appear there is a problem with the sniffs I'm using. PSR2 says the exact opposite, braces MUST be on the next line.

Stuart Grimshaw Stubbs Added a new snippets file for small snippets, mostly assertions. Adde…
…d a complete 'expects' snippet with multiple tab stops
eaceb24
Stuart Herbert

I've added in:

  • markTestIncomplete() for both snippets
  • @covers tag for both snippets

Will that cover it?

Stuart Grimshaw
Stuart Grimshaw Stubbs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 8, 2012
  1. Stuart Grimshaw

    Changed the default content of tests to be a call to markTestIncomplete.

    Stubbs authored
    I've changed the default content to something that will cause the test
    to be visible in the test results rather than comments which would show
    as a passing test by default.
    
    I understand this is quite different from the initial implementation but
    I think it's more robust.
    
    I've also added another tab stop in the tests for a @covers statement
    and made the methods it produces PSR1 compliant.
Commits on Nov 20, 2012
  1. Stuart Grimshaw

    Added a new snippets file for small snippets, mostly assertions. Adde…

    Stubbs authored
    …d a complete 'expects' snippet with multiple tab stops
Commits on Nov 29, 2012
  1. Stuart Grimshaw
  2. Stuart Grimshaw

    Merge branch 'master' of git://github.com/stuartherbert/sublime-phpunit

    Stubbs authored
    Conflicts:
    	phpunit-test-with-data.sublime-snippet
    	phpunit-test.sublime-snippet
Commits on Nov 30, 2012
  1. Stuart Grimshaw
This page is out of date. Refresh to see the latest.
99 PHPUnit-Assertions.sublime-completions
View
@@ -0,0 +1,99 @@
+{
+ "scope": "source.php",
+
+ "completions":
+ [
+ "phpunit",
+
+ { "trigger": "assAHK", "contents": "\\$this->assertArrayHasKey('${1:key}',\\$${2:array}${3:, '${4}'});" },
+ { "trigger": "assANHK", "contents": "\\$this->assertArrayNotHasKey('${1:key}',\\$${2:array}, '${3}');" },
+ { "trigger": "assAC", "contents": "\\$this->assertAttributeContains(${1:needle},\\$${2:haystackAttributeName},\\$${3:haystackClassOrObject}, '${4}', ${5:FALSE}, ${6:TRUE});" },
+ { "trigger": "assACO", "contents": "\\$this->assertAttributeContainsOnly(${1:type},\\$${2:haystackAttributeName},\\$${3:haystackClassOrObject}, $isNativeType = NULL, '${4}');" },
+ { "trigger": "assACo", "contents": "\\$this->assertAttributeCount(${1:expectedCount},\\$${2:haystackAttributeName},\\$${3:haystackClassOrObject}, '${4}');" },
+ { "trigger": "assAE", "contents": "\\$this->assertAttributeEmpty(${1:haystackAttributeName},\\$${2:haystackClassOrObject}, '${3}');" },
+ { "trigger": "assAEq", "contents": "\\$this->assertAttributeEquals(${1:expected},\\$${2:actualAttributeName},\\$${3:actualClassOrObject}, '${4}', ${5:0}, ${6:10}, ${7:FALSE}, ${8:FALSE});" },
+ { "trigger": "assAGT", "contents": "\\$this->assertAttributeGreaterThan(${1:expected},\\$${2:actualAttributeName},\\$${3:actualClassOrObject}, '${4}');" },
+ { "trigger": "assAGTE", "contents": "\\$this->assertAttributeGreaterThanOrEqual(${1:expected},\\$${2:actualAttributeName},\\$${3:actualClassOrObject}, '${4}');" },
+ { "trigger": "assAIO", "contents": "\\$this->assertAttributeInstanceOf(${1:expected},\\$${2:attributeName},\\$${3:classOrObject}, '${4}');" },
+ { "trigger": "assAIT", "contents": "\\$this->assertAttributeInternalType(${1:expected},\\$${2:attributeName},\\$${3:classOrObject}, '${4}');" },
+ { "trigger": "assALT", "contents": "\\$this->assertAttributeLessThan(${1:expected},\\$${2:actualAttributeName},\\$${3:actualClassOrObject}, '${4}');" },
+ { "trigger": "assALTE", "contents": "\\$this->assertAttributeLessThanOrEqual(${1:expected},\\$${2:actualAttributeName},\\$${3:actualClassOrObject}, '${4}');" },
+ { "trigger": "assANC", "contents": "\\$this->assertAttributeNotContains(${1:needle},\\$${2:haystackAttributeName},\\$${3:haystackClassOrObject}, '${4}', ${5:FALSE}, ${6:TRUE});" },
+ { "trigger": "assANCO", "contents": "\\$this->assertAttributeNotContainsOnly(${1:type},\\$${2:haystackAttributeName},\\$${3:haystackClassOrObject}, ${4:NULL}, '${5}');" },
+ { "trigger": "assANC", "contents": "\\$this->assertAttributeNotCount(${1:expectedCount},\\$${2:haystackAttributeName},\\$${3:haystackClassOrObject}, '${4}');" },
+ { "trigger": "assANE", "contents": "\\$this->assertAttributeNotEmpty(${1:haystackAttributeName},\\$${2:haystackClassOrObject}, '${3}');" },
+ { "trigger": "assANEq", "contents": "\\$this->assertAttributeNotEquals(${1:expected},\\$${2:actualAttributeName},\\$${3:actualClassOrObject}, '${4}', ${5:0}, ${6:10}, ${7:FALSE}, ${8:FALSE});" },
+ { "trigger": "assANIO", "contents": "\\$this->assertAttributeNotInstanceOf(${1:expected},\\$${2:attributeName},\\$${3:classOrObject}, '${4}');" },
+ { "trigger": "assANIT", "contents": "\\$this->assertAttributeNotInternalType(${1:expected},\\$${2:attributeName},\\$${3:classOrObject}, '${4}');" },
+ { "trigger": "assANS", "contents": "\\$this->assertAttributeNotSame(${1:expected},\\$${2:actualAttributeName},\\$${3:actualClassOrObject}, '${4}');" },
+ { "trigger": "assAS", "contents": "\\$this->assertAttributeSame(${1:expected},\\$${2:actualAttributeName},\\$${3:actualClassOrObject}, '${4}');" },
+ { "trigger": "assCHA", "contents": "\\$this->assertClassHasAttribute(${1:attributeName},\\$${2:className}, '${3}');" },
+ { "trigger": "assCHSA", "contents": "\\$this->assertClassHasStaticAttribute(${1:attributeName},\\$${2:className}, '${3}');" },
+ { "trigger": "assCNHA", "contents": "\\$this->assertClassNotHasAttribute(${1:attributeName},\\$${2:className}, '${3}');" },
+ { "trigger": "assCNHSA", "contents": "\\$this->assertClassNotHasStaticAttribute(${1:attributeName},\\$${2:className}, '${3}');" },
+ { "trigger": "assC", "contents": "\\$this->assertContains(${1:needle},\\$${2:haystack}, '${3}', ${4:FALSE}, ${5:TRUE});" },
+ { "trigger": "assCO", "contents": "\\$this->assertContainsOnly(${1:type},\\$${2:haystack}, ${3:isNativeType}, '${4}');" },
+ { "trigger": "assCOIO", "contents": "\\$this->assertContainsOnlyInstancesOf(${1:classname},\\$${2:haystack}, '${3}');" },
+ { "trigger": "assCo", "contents": "\\$this->assertCount(${1:expectedCount},\\$${2:haystack}, '${3}');" },
+ { "trigger": "assEm", "contents": "\\$this->assertEmpty(${1:actual}, '${2}');" },
+ { "trigger": "assEXS", "contents": "\\$this->assertEqualXMLStructure(${1:$expectedElement}, ${2:$actualElement}, ${3:FALSE}, '${4}');" },
+ { "trigger": "assEq", "contents": "\\$this->assertEquals(${1:expected},\\$${2:actual}, '${3}', $(4:delta}, ${5:maxDepth}, ${6:FALSE}, ${7:FALSE});" },
+ { "trigger": "assF", "contents": "\\$this->assertFalse(${1:condition}, '${2}');" },
+ { "trigger": "assFEq", "contents": "\\$this->assertFileEquals(${1:expected},\\$${2:actual}, '${3}', ${4:canonicalize}, ${5:FALSE});" },
+ { "trigger": "assFEx", "contents": "\\$this->assertFileExists(${1:filename}, '${2}');" },
+ { "trigger": "assFNEq", "contents": "\\$this->assertFileNotEquals(${1:expected},\\$${2:actual}, '${3}', ${4:FALSE}, ${5:FALSE});" },
+ { "trigger": "assFNEx", "contents": "\\$this->assertFileNotExists(${1:filename}, '${2}');" },
+ { "trigger": "assGT", "contents": "\\$this->assertGreaterThan(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assGTE", "contents": "\\$this->assertGreaterThanOrEqual(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assIO", "contents": "\\$this->assertInstanceOf(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assIT", "contents": "\\$this->assertInternalType(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assJFEJF", "contents": "\\$this->assertJsonFileEqualsJsonFile(${1:expectedFile},\\$${2:actualFile}, '${3}');" },
+ { "trigger": "assJFNEJF", "contents": "\\$this->assertJsonFileNotEqualsJsonFile(${1:expectedFile},\\$${2:actualFile}, '${3}');" },
+ { "trigger": "assJSEJF", "contents": "\\$this->assertJsonStringEqualsJsonFile(${1:expectedFile},\\$${2:actualJson}, '${3}');" },
+ { "trigger": "assJSEJS", "contents": "\\$this->assertJsonStringEqualsJsonString(${1:expectedJson},\\$${2:actualJson}, '${3}');" },
+ { "trigger": "assJSNEJF", "contents": "\\$this->assertJsonStringNotEqualsJsonFile(${1:expectedFile},\\$${2:actualJson}, '${3}');" },
+ { "trigger": "assJSNEJS", "contents": "\\$this->assertJsonStringNotEqualsJsonString(${1:expectedJson},\\$${2:actualJson}, '${3}');" },
+ { "trigger": "assLT", "contents": "\\$this->assertLessThan(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assLTE", "contents": "\\$this->assertLessThanOrEqual(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assNC", "contents": "\\$this->assertNotContains(${1:needle},\\$${2:haystack}, '${3}', ${4:FALSE}, ${5:TRUE});" },
+ { "trigger": "assNCO", "contents": "\\$this->assertNotContainsOnly(${1:type},\\$${2:haystack}, ${3:isNativeType}, '${4}');" },
+ { "trigger": "assNCnt", "contents": "\\$this->assertNotCount(${1:expectedCount},\\$${2:haystack}, '${3}');" },
+ { "trigger": "assNEm", "contents": "\\$this->assertNotEmpty(${1:actual}, '${2}');" },
+ { "trigger": "assNEq", "contents": "\\$this->assertNotEquals(${1:expected},\\$${2:actual}, '${3}', ${4:delta}, ${5:maxDepth}, ${6:FALSE}, ${7:FALSE});" },
+ { "trigger": "assNIO", "contents": "\\$this->assertNotInstanceOf(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assNIT", "contents": "\\$this->assertNotInternalType(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assNN", "contents": "\\$this->assertNotNull(${1:actual}, '${2}');" },
+ { "trigger": "assNRE", "contents": "\\$this->assertNotRegExp(${1:pattern},\\$${2:string}, '${3}');" },
+ { "trigger": "assNS", "contents": "\\$this->assertNotSame(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assNSS", "contents": "\\$this->assertNotSameSize(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assNT", "contents": "\\$this->assertNotTag(${1:matcher},\\$${2:actual}, '${3}', ${4:TRUE});" },
+ { "trigger": "assN", "contents": "\\$this->assertNull(${1:actual}, '${2}');" },
+ { "trigger": "assOHA", "contents": "\\$this->assertObjectHasAttribute(${1:attributeName},\\$${2:object}, '${3}');" },
+ { "trigger": "assONHA", "contents": "\\$this->assertObjectNotHasAttribute(${1:attributeName},\\$${2:object}, '${3}');" },
+ { "trigger": "assRE", "contents": "\\$this->assertRegExp(${1:pattern},\\$${2:string}, '${3}');" },
+ { "trigger": "assS", "contents": "\\$this->assertSame(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assSS", "contents": "\\$this->assertSameSize(${1:expected},\\$${2:actual}, '${3}');" },
+ { "trigger": "assSC", "contents": "\\$this->assertSelectCount(${1:selector},\\$${2:count},\\$${3:actual}, '${4}', ${5:TRUE});" },
+ { "trigger": "assSEq", "contents": "\\$this->assertSelectEquals(${1:selector},\\$${2:content},\\$${3:count},\\$${4:actual}, '${5}', ${6:TRUE});" },
+ { "trigger": "assSRE", "contents": "\\$this->assertSelectRegExp(${1:selector},\\$${2:content},\\$${3:count},\\$${4:actual}, '${5}', ${6:TRUE});" },
+ { "trigger": "assSENW", "contents": "\\$this->assertStringEndsNotWith(${1:suffix},\\$${2:string}, '${3}');" },
+ { "trigger": "assSEW", "contents": "\\$this->assertStringEndsWith(${1:suffix},\\$${2:string}, '${3}');" },
+ { "trigger": "assSEF", "contents": "\\$this->assertStringEqualsFile(${1:expectedFile},\\$${2:actualString}, '${3}', ${4:FALSE}, ${5:FALSE});" },
+ { "trigger": "assSMF", "contents": "\\$this->assertStringMatchesFormat(${1:format},\\$${2:string}, '${3}');" },
+ { "trigger": "assSMFF", "contents": "\\$this->assertStringMatchesFormatFile(${1:formatFile},\\$${2:string}, '${3}');" },
+ { "trigger": "assSNEF", "contents": "\\$this->assertStringNotEqualsFile(${1:expectedFile},\\$${2:actualString}, '${3}', ${4:FALSE}, ${5:FALSE});" },
+ { "trigger": "assSNMF", "contents": "\\$this->assertStringNotMatchesFormat(${1:format},\\$${2:string}, '${3}');" },
+ { "trigger": "assSNMFF", "contents": "\\$this->assertStringNotMatchesFormatFile(${1:formatFile},\\$${2:string}, '${3}');" },
+ { "trigger": "assSSNW", "contents": "\\$this->assertStringStartsNotWith(${1:prefix},\\$${2:string}, '${3}');" },
+ { "trigger": "assSSW", "contents": "\\$this->assertStringStartsWith(${1:prefix},\\$${2:string}, '${3}');" },
+ { "trigger": "assTag", "contents": "\\$this->assertTag(${1:matcher},\\$${2:actual}, '${3}', ${4:TRUE});" },
+ { "trigger": "assThat", "contents": "\\$this->assertThat(${1:value}, ${2:constraint}, '${3}');" },
+ { "trigger": "assT", "contents": "\\$this->assertTrue(${1:condition}, '${2}');" },
+ { "trigger": "assXFEXF", "contents": "\\$this->assertXmlFileEqualsXmlFile(${1:expectedFile},\\$${2:actualFile}, '${3}');" },
+ { "trigger": "assXFNEXF", "contents": "\\$this->assertXmlFileNotEqualsXmlFile(${1:expectedFile},\\$${2:actualFile}, '${3}');" },
+ { "trigger": "assXSEXF", "contents": "\\$this->assertXmlStringEqualsXmlFile(${1:expectedFile},\\$${2:actualXml}, '${3}');" },
+ { "trigger": "assXSEXS", "contents": "\\$this->assertXmlStringEqualsXmlString(${1:expectedXml},\\$${2:actualXml}, '${3}');" },
+ { "trigger": "assXSNEXF", "contents": "\\$this->assertXmlStringNotEqualsXmlFile(${1:expectedXml},\\$${2:actualXml}, '${3}');" },
+ { "trigger": "assXSNEXS", "contents": "\\$this->assertXmlStringNotEqualsXmlString(${1:expectedXml},\\$${2:actualXml}, '${3}');" }
+ ]
+}
5 README.md
View
@@ -44,6 +44,11 @@ To use any of the snippets, simply type the name of the snippet, then press the
* __phpunit-test__: create a new test method inside your TestCase class
* __phpunit-testcase__: create a new TestCase class to put your tests inside
+Completions
+-----------
+
+This plugin provides completions for all of PHPUnit 3.7's assertions, with tab stops for each parameter.
+
Contributions Welcome
---------------------
23 phpunit-expects.sublime-snippet
View
@@ -0,0 +1,23 @@
+<!--
+ phpunit-test-with-data
+ A time-saving snippet for adding expectations to test cases.
+
+ HOW TO USE
+ This snippet has several tab stops, just keep tabbing till the highlight surrounds
+ the bith you want to change
+
+-->
+<snippet>
+ <content><![CDATA[
+\$${1:objMock}->expects(\$this->${2:once()})
+ ->method('${3:method}')
+${4: ->with(\$this->${5:equalTo}(${6}))}
+${7: ->will(\$this->${8:returnValue}(${9}))};
+]]></content>
+ <!-- Optional: Tab trigger to activate the snippet -->
+ <tabTrigger>phpunit-expects</tabTrigger>
+ <!-- Optional: Scope the tab trigger will be active in -->
+ <scope>source.php</scope>
+ <!-- Optional: Description to show in the menu -->
+ <description>Add an expects assertion to your test.</description>
+</snippet>
19 phpunit-test-with-data.sublime-snippet
View
@@ -17,19 +17,11 @@
* ${3:[testcase-description]}
*
* @dataProvider ${1:[dataProviderMethod]}
- * @covers ${2:Class::Method}
+ * @covers ${4:Class::Method}
* @return void
*/
-public function test${2:[testcase-name]}()
-{
- // setup your test
-
- // pre-conditions
-
- // perform the change
-
- // test the results
- \$this->markTestIncomplete('Not yet implemented');
+public function test${2:[testcase-name]}() {
+ ${5:\$this->markTestIncomplete('Not yet Implemented');}
}
/**
@@ -37,8 +29,7 @@ public function test${2:[testcase-name]}()
*
* @return array
*/
-public function ${1:[dataProviderMethod]}()
-{
+public function ${1:[dataProviderMethod]}() {
return array(
array()
);
@@ -51,4 +42,4 @@ public function ${1:[dataProviderMethod]}()
<scope>source.php</scope>
<!-- Optional: Description to show in the menu -->
<description>Create a skeleton test method with a data provider</description>
-</snippet>
+</snippet>
20 phpunit-test.sublime-snippet
View
@@ -16,24 +16,8 @@
/**
* @covers ${2:Class::Method}
*/
-public function test${1:[testcase-name]}()
-{
- // ----------------------------------------------------------------
- // setup your test
- //
- // explain your test setup here if needed ...
-
- // ----------------------------------------------------------------
- // perform the change
- //
- // explain your test here if needed ...
-
- // ----------------------------------------------------------------
- // test the results
- //
- // explain what you expect to have happened
-
- \$this->markTestIncomplete('Not yet implemented');
+public function test${1:[testcase-name]}() {
+ ${3:\$this->markTestIncomplete('Not yet Implemented');}
}
]]></content>
Something went wrong with that request. Please try again.