Skip to content

Instantly share code, notes, and snippets.

@roryl
Last active July 20, 2018 07:24
Show Gist options
  • Save roryl/5a127d2d99c09924b3aa to your computer and use it in GitHub Desktop.
Save roryl/5a127d2d99c09924b3aa to your computer and use it in GitHub Desktop.
Lucee Book examples for creating components
component {
public function init(){
myObj = new components.subComponent();
}
}
import components.subComponent;
component {
public function init(){
myObj = new subComponent();
}
}
/**
* My xUnit Test
*/
component extends="testbox.system.BaseSpec"{
/*********************************** LIFE CYCLE Methods ***********************************/
// executes before all test cases
function beforeTests(){
}
// executes after all test cases
function afterTests(){
}
// executes before every test case
function setup( currentMethod ){
}
// executes after every test case
function teardown( currentMethod ){
}
/*********************************** TEST CASES BELOW ***********************************/
// Remember that test cases MUST start or end with the keyword 'test'
function emptyComponentTest(){
new empty_component();
}
function singleFunctionTest(){
new single_function();
}
function defaultConstructorTest(){
new default_constructor();
}
function RequiredAndTypedArgumentsTest(){
new required_and_typed_arguments();
}
function requiredArgumentsTest(){
new required_arguments();
}
function typedArgumentsTest(){
new typed_arguments();
}
// function componentImplicitPathTest(){
// new component_implicit_path();
// }
// function componentImportedPathTest(){
// new component_imported_path();
// }
function createObjectTest(){
include template="create_object.cfm";
}
function newObjectTest(){
include template="new_object.cfm";
}
}
<cfscript>
myObj = createObject("default_constructor");
</cfscript>
component {
public function myFunc(required string argumentName1="test", required struct argumentName2={key:"value"}){
}
}
component {
function init(){
//Do something on instantiation
return this;
}
}
<cfscript>
myObj = new default_constructor();
</cfscript>
component {
public function myFunc(required string argumentName1, required struct argumentName2){
}
}
component {
public function myFunc(required argumentName1, required argumentName2){
}
}
component {
public void function myFunction(){
}
}
component {
public function myFunc(string argumentName1, struct argumentName2){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment