Skip to content

Commit

Permalink
TESTBOX-392
Browse files Browse the repository at this point in the history
BoxLang classes support
  • Loading branch information
lmajano committed Sep 4, 2024
1 parent 7c5fd3f commit 5ed5afe
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 72 deletions.
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

----

TestBox is a Behavior Driven Development (BDD) and Test Driven Development (TDD) framework for ColdFusion (CFML). It also includes mocking and stubbing capabilities via its internal MockBox library.
TestBox is a Behavior Driven Development (BDD) and Test Driven Development (TDD) framework for [BoxLang JVM Language](https://www.boxlang.io) and ColdFusion (CFML). It also includes mocking and stubbing capabilities via its internal MockBox library.

## License

Expand Down Expand Up @@ -70,15 +70,15 @@ Join us in our Ortus Community and become a valuable member of this project [Tes

## Requirements

* BoxLang 1+
* Lucee 5+
* Adobe ColdFusion 2018+

## Installation

You can visit the TestBox documentation page to view all of its features and
capabilities. To install TestBox just drop it in your web root as `/testbox` or
create a mapping in your CFML administrator or `Application.cfc` that points to the
directory you installed TestBox and create the mapping `/testbox` that points to it.
create a mapping `/testbox` that points to it.

You can also use [CommandBox](https://www.ortussolutions.com/products/commandbox) to install and leverage TestBox for commandline executions, test generations, watchers and much more:

Expand Down
33 changes: 33 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"app":{
"cfengine":"boxlang@be",
"serverHomeDirectory":".engine/boxlang"
},
"name":"coldbox-boxlang",
"force":true,
"openBrowser":false,
"web":{
"directoryBrowsing":true,
"http":{
"port":"8599"
},
"rewrites":{
"enable":true
},
"aliases":{
"/testbox":"./"
}
},
"JVM":{
"heapSize":"1024"
},
"cfconfig":{
"file":".cfconfig.json"
},
"env":{
"BOXLANG_DEBUG": true
},
"scripts" : {
"onServerInitialInstall":"install bx-compat"
}
}
2 changes: 1 addition & 1 deletion system/Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright Since 2005 TestBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* This is the base Application.cfc for the TestBox testing suite
* This is the base Application for the TestBox testing suite
* Whenever you are running tests from within TestBox Core
*/
component {
Expand Down
16 changes: 8 additions & 8 deletions system/BaseSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ component {
/**
* Add custom matchers to your expectations
*
* @matchers The structure of custom matcher functions to register or a path or instance of a CFC containing all the matcher functions to register
* @matchers The structure of custom matcher functions to register or a path or instance of a class containing all the matcher functions to register
*/
function addMatchers( required any matchers ){
// register structure
Expand All @@ -796,7 +796,7 @@ component {
return this;
}

// Build the Matcher CFC
// Build the Matcher
var oMatchers = "";
if ( isSimpleValue( arguments.matchers ) ) {
oMatchers = new "#arguments.matchers#"( );
Expand All @@ -821,7 +821,7 @@ component {
/**
* Add custom assertions to the $assert object
*
* @assertions The structure of custom assertion functions to register or a path or instance of a CFC containing all the assertion functions to register
* @assertions The structure of custom assertion functions to register or a path or instance of a class containing all the assertion functions to register
*/
function addAssertions( required any assertions ){
// register structure
Expand All @@ -831,7 +831,7 @@ component {
return this;
}

// Build the Custom Assertion CFC
// Build the Custom Assertion
var oAssertions = "";
if ( isSimpleValue( arguments.assertions ) ) {
oAssertions = new "#arguments.assertions#"( );
Expand Down Expand Up @@ -886,7 +886,7 @@ component {
}

/**
* Run a BDD test in this target CFC
* Run a BDD test in this target
*
* @spec The spec definition to test
* @suite The suite definition this spec belongs to
Expand Down Expand Up @@ -1265,7 +1265,7 @@ component {
}

/**
* Runs a xUnit style test method in this target CFC
* Runs a xUnit style test method in this target
*
* @spec The spec definition to test
* @testResults The testing results object
Expand Down Expand Up @@ -1465,7 +1465,7 @@ component {
/************************************** MOCKING METHODS *********************************************/

/**
* Make a private method on a CFC public with or without a new name and returns the target object
* Make a private method on a class public with or without a new name and returns the target object
*
* @target The target object to expose the method
* @method The private method to expose
Expand Down Expand Up @@ -1627,7 +1627,7 @@ component {
* Create an empty stub object that you can use for mocking
*
* @callLogging Add method call logging for all mocked methods. Defaults to true
* @extends Make the stub extend from certain CFC
* @extends Make the stub extend from certain class
* @implements Make the stub adhere to an interface
*/
function createStub(
Expand Down
2 changes: 1 addition & 1 deletion system/CollectionExpectation.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright Since 2005 TestBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* The CollectionExpectation CFC holds a collection and behaves like an expectation
* The CollectionExpectation holds a collection and behaves like an expectation
* that automatically unrolls the collection to verify every element
*/
component accessors="true" {
Expand Down
4 changes: 2 additions & 2 deletions system/Expectation.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright Since 2005 TestBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* The Expectation CFC holds a current expectation with all the required matcher methods to provide you
* The Expectation class holds a current expectation with all the required matcher methods to provide you
* with awesome BDD expressions and testing.
*/
component accessors="true" {
Expand Down Expand Up @@ -113,7 +113,7 @@ component accessors="true" {
// throw exception
throw(
type = "InvalidMethod",
message = "The dynamic/static method: #arguments.missingMethodName# does not exist in this CFC",
message = "The dynamic/static method: #arguments.missingMethodName# does not exist in this class",
detail = "Available methods are #structKeyArray( this ).toString()#"
);
}
Expand Down
4 changes: 2 additions & 2 deletions system/MockBox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ component accessors=true {
return createMock( className = "testbox.system.mockutils.Stub", callLogging = arguments.callLogging );
}
// Generate the class + Create it + Remove it
return prepareMock( variables.mockGenerator.generateCFC( argumentCollection = arguments ) );
return prepareMock( variables.mockGenerator.generateClass( argumentCollection = arguments ) );
}

/**
Expand Down Expand Up @@ -624,7 +624,7 @@ component accessors=true {
)
)
) {
// If an object and CFC, just use serializeJSON
// If an object and a class, just use serializeJSON
serializedArgs &= serializeJSON( getMetadata( argOrderedTree[ arg ] ) );
} else {
// Get obj rep
Expand Down
49 changes: 30 additions & 19 deletions system/TestBox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ component accessors="true" {
property name="codename";
// The main utility object
property name="utility";
// The CFC bundles to test
// The class bundles to test
property name="bundles";
// The labels used for the testing
property name="labels";
Expand All @@ -38,8 +38,8 @@ component accessors="true" {
/**
* Constructor
*
* @bundles The path, list of paths or array of paths of the spec bundle CFCs to run and test
* @directory The directory to test which can be a simple mapping path or a struct with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the CFC found, it must return true to process or false to continue process ]
* @bundles The path, list of paths or array of paths of the spec bundle classes to run and test
* @directory The directory to test which can be a simple mapping path or a struct with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the class found, it must return true to process or false to continue process ]
* @directories Same as @directory, but accepts an array or list
* @reporter The type of reporter to use for the results, by default is uses our 'simple' report. You can pass in a core reporter string type or an instance of a testbox.system.reports.IReporter
* @labels The list or array of labels that a suite or spec must have in order to execute.
Expand Down Expand Up @@ -114,6 +114,17 @@ component accessors="true" {
);
} );

directoryList( modulesPath, true, "path", "ModuleConfig.bx" )
.map( ( item ) => item.replaceNoCase( "ModuleConfig.bx", "" ) )
.each( ( path ) => {
registerModule(
"testbox" & arguments.path
.replaceNoCase( variables.TESTBOX_PATH, "" )
.reReplace( "[\\\/]", ".", "all" )
.reReplace( "\.$", "", "all" )
);
} );

// Activate Modules
variables.modules.registry.each( ( moduleName, config ) => activateModule( moduleName ) );

Expand Down Expand Up @@ -249,7 +260,7 @@ component accessors="true" {
/**
* Register a directory to test
*
* @directory A directory to test which can be a simple mapping path or a struct with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the CFC found, it must return true to process or false to continue process ]
* @directory A directory to test which can be a simple mapping path or a struct with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the class found, it must return true to process or false to continue process ]
*/
any function addDirectory( required any directory, boolean recurse = true ){
// inflate directory?
Expand All @@ -271,7 +282,7 @@ component accessors="true" {
/**
* Constructor
*
* @directories A set of directories to test which can be a list of simple mapping paths or an array of structs with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the CFC found, it must return true to process or false to continue process ]
* @directories A set of directories to test which can be a list of simple mapping paths or an array of structs with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the class found, it must return true to process or false to continue process ]
*/
any function addDirectories( required any directories, boolean recurse = true ){
if ( isSimpleValue( arguments.directories ) ) {
Expand All @@ -286,7 +297,7 @@ component accessors="true" {
/**
* Add bundles to the TestBox `bundles` target to test
*
* @bundles The path, list of paths or array of paths of the spec bundle CFCs to run and test
* @bundles The path, list of paths or array of paths of the spec bundle classess to run and test
*/
any function addBundles( required any bundles ){
if ( isSimpleValue( arguments.bundles ) ) {
Expand All @@ -302,16 +313,16 @@ component accessors="true" {
* Run me some testing goodness, this can use the constructed object variables or the ones
* you can send right here.
*
* @bundles The path, list of paths or array of paths of the spec bundle CFCs to run and test
* @directory The directory to test which can be a simple mapping path or a struct with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the CFC found, it must return true to process or false to continue process ]
* @bundles The path, list of paths or array of paths of the spec bundle classes to run and test
* @directory The directory to test which can be a simple mapping path or a struct with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the class found, it must return true to process or false to continue process ]
* @reporter The type of reporter to use for the results, by default is uses our 'simple' report. You can pass in a core reporter string type or an instance of a testbox.system.reports.IReporter. You can also pass a struct if the reporter requires options: {type="", options={}}
* @labels The list or array of labels that a suite or spec must have in order to execute.
* @excludes The list or array of labels that a suite or spec must not have in order to execute.
* @options A structure of configuration options that are optionally used to configure a runner.
* @testBundles A list or array of bundle names that are the ones that will be executed ONLY!
* @testSuites A list or array of suite names that are the ones that will be executed ONLY!
* @testSpecs A list or array of test names that are the ones that will be executed ONLY!
* @callbacks A struct of listener callbacks or a CFC with callbacks for listening to progress of the testing: onBundleStart,onBundleEnd,onSuiteStart,onSuiteEnd,onSpecStart,onSpecEnd
* @callbacks A struct of listener callbacks or a class with callbacks for listening to progress of the testing: onBundleStart,onBundleEnd,onSuiteStart,onSuiteEnd,onSpecStart,onSpecEnd
* @eagerFailure If this boolean is set to true, then execution of more bundle tests will stop once the first failure/error is detected. By default this is false.
*/
any function run(
Expand Down Expand Up @@ -346,15 +357,15 @@ component accessors="true" {
/**
* Run me some testing goodness but give you back the raw TestResults object instead of a report
*
* @bundles The path, list of paths or array of paths of the spec bundle CFCs to run and test
* @directory The directory to test which can be a simple mapping path or a struct with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the CFC found, it must return true to process or false to continue process ]
* @bundles The path, list of paths or array of paths of the spec bundle classes to run and test
* @directory The directory to test which can be a simple mapping path or a struct with the following options: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the class found, it must return true to process or false to continue process ]
* @labels The list or array of labels that a suite or spec must have in order to execute.
* @excludes The list or array of labels that a suite or spec must not have in order to execute.
* @options A structure of configuration options that are optionally used to configure a runner.
* @testBundles A list or array of bundle names that are the ones that will be executed ONLY!
* @testSuites A list or array of suite names that are the ones that will be executed ONLY!
* @testSpecs A list or array of test names that are the ones that will be executed ONLY!
* @callbacks A struct of listener callbacks or a CFC with callbacks for listening to progress of the testing: onBundleStart,onBundleEnd,onSuiteStart,onSuiteEnd,onSpecStart,onSpecEnd
* @callbacks A struct of listener callbacks or a class with callbacks for listening to progress of the testing: onBundleStart,onBundleEnd,onSuiteStart,onSuiteEnd,onSpecStart,onSpecEnd
* @eagerFailure If this boolean is set to true, then execution of more bundle tests will stop once the first failure/error is detected. By default this is false.
*/
testbox.system.TestResult function runRaw(
Expand Down Expand Up @@ -486,7 +497,7 @@ component accessors="true" {
/**
* Run me some testing goodness, remotely via SOAP, Flex, REST, URL
*
* @bundles The path or list of paths of the spec bundle CFCs to run and test
* @bundles The path or list of paths of the spec bundle classes to run and test
* @directory The directory mapping to test: directory = the path to the directory using dot notation (myapp.testing.specs)
* @recurse Recurse the directory mapping or not, by default it does
* @reporter The type of reporter to use for the results, by default is uses our 'simple' report. You can pass in a core reporter string type or a class path to the reporter to use.
Expand Down Expand Up @@ -693,11 +704,11 @@ component accessors="true" {
/***************************************** PRIVATE ************************************************************/

/**
* This method executes the tests in a bundle CFC according to type. If the testing was ok a true is returned.
* This method executes the tests in a bundle class according to type. If the testing was ok a true is returned.
*
* @bundlePath The path of the Bundle CFC to test.
* @bundlePath The path of the Bundle class to test.
* @testResults The testing results object to keep track of results
* @callbacks The callbacks struct or CFC
* @callbacks The callbacks struct or class
*
* @throws BundleRunnerMajorException
*/
Expand Down Expand Up @@ -760,9 +771,9 @@ component accessors="true" {
}

/**
* Creates and returns a bundle CFC with spec capabilities if not inherited.
* Creates and returns a bundle class with spec capabilities if not inherited.
*
* @bundlePath The path to the Bundle CFC
* @bundlePath The path to the Bundle class
*
* @throws AbstractComponentException - When an abstract component exists as a spec
*/
Expand Down Expand Up @@ -806,7 +817,7 @@ component accessors="true" {
/**
* Get an array of spec paths from a directory
*
* @directory The directory information struct to test: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the CFC found, it must return true to process or false to continue process ]
* @directory The directory information struct to test: [ mapping = the path to the directory using dot notation (myapp.testing.specs), recurse = boolean, filter = closure that receives the path of the class found, it must return true to process or false to continue process ]
*/
private function getSpecPaths( required directory ){
var results = [];
Expand Down
2 changes: 1 addition & 1 deletion system/TestResult.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ component accessors="true" {
property name="coverageEnabled" type="boolean";
property name="coverageData" type="struct";

// CFML Engine Information
// Engine Information
property name="CFMLEngine";
property name="CFMLEngineVersion";

Expand Down
4 changes: 2 additions & 2 deletions system/compat/runner/DirectoryTestSuite.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
name ="excludes"
required="false"
default =""
hint ="list of Tests, in cfc notation, to exclude. uses ListContains so it's as greedy as possible. Currently does not support ant-style syntax or whole-directory filtering"
hint ="list of Tests, in class notation, to exclude. uses ListContains so it's as greedy as possible. Currently does not support ant-style syntax or whole-directory filtering"
>

<cfscript>
Expand All @@ -39,7 +39,7 @@
name ="getComponentPath"
access ="remote"
returntype="string"
hint ="Given a directory path, returns the corresponding CFC package according to CFMX"
hint ="Given a directory path, returns the corresponding class package according to CFMX"
output ="false"
>
<cfargument name="path" type="string" required="true"/>
Expand Down
4 changes: 2 additions & 2 deletions system/compat/runner/Results.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ component {
private function filterExcludes( required path ){
var excludes = getOptions().excludes;

var cfcName = listFirst( getFileFromPath( arguments.path ), "." );
var className = listFirst( getFileFromPath( arguments.path ), "." );

return ( listFindNoCase( excludes, cfcName ) ? false : true );
return ( listFindNoCase( excludes, className ) ? false : true );
}

}
Loading

0 comments on commit 5ed5afe

Please sign in to comment.