Last active
March 13, 2016 05:34
-
-
Save roryl/8b646c334f8d5658e9fe to your computer and use it in GitHub Desktop.
Lucee Interfaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component implements="IMyInterface,IOtherInterface" { | |
public function myFunc(required string myString){ | |
return arguments.myString; | |
} | |
public function myOtherFunc(required array myArray){ | |
return myArray; | |
} | |
public function someOtherFunc(){ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface { | |
public function myFunc(required string myString){ | |
} | |
public function myOtherFunc(required array myArray){ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 interfaceTest(){ | |
var myObj = new MyInterfaceImpl(); | |
} | |
function interfaceFailTest(){ | |
expect(function(){ | |
var myObj = new MyInterfaceFail(); | |
}).toThrow(); | |
} | |
function useInterfaceTest(){ | |
var myObj = new MyInterfaceImpl(); | |
var useObj = new usesInterface(myObj); | |
} | |
function useInterfaceFailTest(){ | |
var myObj = new emptyComponent(); | |
expect(function(){ | |
var useObj = new usesInterface(myObj); | |
}).toThrow(""); | |
} | |
function returnInterfaceTest(){ | |
var myObj = new returnInterface().getObject(); | |
} | |
function returnInterfaceFailTest(){ | |
expect(function(){ | |
var myObj = new returnInterfaceFail().getObject(); | |
}) | |
} | |
function implementsMultipleTest(){ | |
var myObj = new implementsMultiple(); | |
var useObj = new usesInterface(myObj); | |
} | |
function guardInterfaceTest(){ | |
var myObj = new MyInterfaceImpl(); | |
var useObj = new usesInterfaceGuard(myObj); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface { | |
public function someOtherFunc(){ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component implements="IMyInterface" { | |
public function myFunc(required string myString){ | |
return arguments.myString; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component implements="IMyInterface" { | |
public function myFunc(required string myString){ | |
return arguments.myString; | |
} | |
public function myOtherFunc(required array myArray){ | |
return myArray; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public function init(){ | |
return this; | |
} | |
public IMyInterface function getObject(){ | |
return new MyInterfaceImpl(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public function init(){ | |
return this; | |
} | |
public IMyInterface function getObject(){ | |
return new emptyComponent(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public function init(required IMyInterface object){ | |
//Will error if the object passed in did not implement IMyInterface | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public function init(required IMyInterface object){ | |
//Throws an error if the argument does not implement the IOtherInterface | |
structKeyExists(getMetaData(arguments.object).implements,"IOtherInterface"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment