| Conditions | 1 |
| Paths | 1 |
| Total Lines | 105 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 28 | public function testKnockoutForm() |
||
| 29 | { |
||
| 30 | $page = $this->get('KnockoutFormTestController'); |
||
| 31 | $this->assertEquals(200, $page->getStatusCode(), "a page should load"); |
||
| 32 | $body = $page->getBody(); |
||
| 33 | |||
| 34 | $this->assertStringContainsString( |
||
| 35 | 'data-bind="submit: addToCart2"', |
||
| 36 | $body, |
||
| 37 | 'form element has submit binding to javascript function' |
||
| 38 | ); |
||
| 39 | $this->assertStringContainsString( |
||
| 40 | '<input data-bind="textInput: spaceship2, hasFocus: true"', |
||
| 41 | $body, |
||
| 42 | 'Databind attribute in input element' |
||
| 43 | ); |
||
| 44 | $this->assertStringContainsString( |
||
| 45 | "setKnockout:{value:'Enterprise\'s Voyage'}", |
||
| 46 | $body, |
||
| 47 | 'Comma escaped in HTML for javascript' |
||
| 48 | ); |
||
| 49 | $this->assertStringContainsString( |
||
| 50 | '<select data-bind="value: menu"', |
||
| 51 | $body, |
||
| 52 | 'Databind attribute applied to select element' |
||
| 53 | ); |
||
| 54 | $this->assertStringContainsString( |
||
| 55 | '<input data-bind="textInput: seatNumber, setKnockout:{value:4}"', |
||
| 56 | $body, |
||
| 57 | 'KnockoutNumericField works' |
||
| 58 | ); |
||
| 59 | $this->assertStringContainsString( |
||
| 60 | '<input data-bind="enable: canSaveInterGalacticAction, css:{ \'FormAction_Disabled\': !canSaveInterGalacticAction() }" type="submit"', |
||
| 61 | $body, |
||
| 62 | 'Databind attribute in submit button' |
||
| 63 | ); |
||
| 64 | $this->assertStringContainsString( |
||
| 65 | '<input data-bind="textInput: email, setKnockout:{value:\'[email protected]\'}"', |
||
| 66 | $body, |
||
| 67 | 'Databind attribute applied to input element for email field' |
||
| 68 | ); |
||
| 69 | $this->assertStringContainsString( |
||
| 70 | 'class="email text"', |
||
| 71 | $body, |
||
| 72 | 'KnockoutEmailField has a class of "email text"' |
||
| 73 | ); |
||
| 74 | $this->assertStringContainsString( |
||
| 75 | '<textarea data-bind="textInput: comments"', |
||
| 76 | $body, |
||
| 77 | 'Databind attribute applied to the textareafield' |
||
| 78 | ); |
||
| 79 | $this->assertStringContainsString( |
||
| 80 | 'class="knockouttextarea textarea"', |
||
| 81 | $body, |
||
| 82 | 'KnockoutTextareaField has a class of "textarea text"' |
||
| 83 | ); |
||
| 84 | $this->assertStringContainsString( |
||
| 85 | 'data-bind="checked: accessories, setKnockout:{value:\'Zero Gravity Pillow\'}, blah: someOtherFunction"', |
||
| 86 | $body, |
||
| 87 | 'Databind attribute applied to the radio buttons' |
||
| 88 | ); |
||
| 89 | $this->assertStringContainsString( |
||
| 90 | 'class="radio"', |
||
| 91 | $body, |
||
| 92 | 'KnockoutOptionsetField has a class of "radio"' |
||
| 93 | ); |
||
| 94 | $this->assertStringContainsString( |
||
| 95 | 'data-bind="enable: canSaveInterGalacticAction', |
||
| 96 | $body, |
||
| 97 | 'KnockoutFormAction has an observable of "canSaveInterGalacticAction"' |
||
| 98 | ); |
||
| 99 | $this->assertStringContainsString( |
||
| 100 | 'data-bind="textInput: password', |
||
| 101 | $body, |
||
| 102 | 'KnockoutConfirmedPasswordField has a child with an observable of "password"' |
||
| 103 | ); |
||
| 104 | $this->assertStringContainsString( |
||
| 105 | 'data-bind="textInput: confirmedPassword', |
||
| 106 | $body, |
||
| 107 | 'KnockoutConfirmedPasswordField has a child with an observable of "confirmedPassword"' |
||
| 108 | ); |
||
| 109 | $this->assertStringContainsString( |
||
| 110 | 'data-bind="checked: checkboxField"', |
||
| 111 | $body, |
||
| 112 | 'KnockoutCheckboxField has an observable of "checkboxField"' |
||
| 113 | ); |
||
| 114 | $this->assertStringContainsString( |
||
| 115 | 'data-bind="checked: switchField"', |
||
| 116 | $body, |
||
| 117 | 'KnockoutSwitchField has an observable of "switchField"' |
||
| 118 | ); |
||
| 119 | $this->assertStringContainsString( |
||
| 120 | ' <button data-bind="click: function(){ compositeButtonField(!compositeButtonField());', |
||
| 121 | $body, |
||
| 122 | 'KnockoutToggleCompositeButtonField has a button that shows/hides based upon the observable of "compositeButtonField"' |
||
| 123 | ); |
||
| 124 | $this->assertStringContainsString( |
||
| 125 | '<div data-bind="visible: compositeButtonField"', |
||
| 126 | $body, |
||
| 127 | 'KnockoutToggleCompositeButtonField has an observable of "compositeButtonField"' |
||
| 128 | ); |
||
| 129 | $this->assertSame( |
||
| 130 | substr_count($body, 'label class="form-check-label left"'), |
||
| 131 | 1, |
||
| 132 | 'the label element with class "left" appears once' |
||
| 133 | ); |
||
| 138 |