The PHP constants used throughout Redaxscript prevent us moving towards unit testing. We need some kind of testable "constants" object...
https://gist.github.com/GaryA/7975594
http://codepad.org/nObiuyh4
Conversation from Facebook:
Hey Henry, I have an idea for replacing the constnats defined in startup.php, see what you think... https://gist.github.com/GaryA/7975594
Henry Ruhs
17:40
Henry Ruhs
hello gary
just checked it out
without a use case or lets say way to use it i cannot understand what this is for
and you repeat yourself very often
constants are for a reason constants and not globals, you should only read and not write them
Gary Aylward
17:44
Gary Aylward
I agree - so why is there an undefine() function in startup.php? Which doesn't work BTW
Henry Ruhs
17:44
Henry Ruhs
there is an undefine to set a constant to ''
instead of being undefined what caused errors once you are checking it
Gary Aylward
17:46
Gary Aylward
But undefine fails if the constant is already defined. I found this when running with all errors reported - only happens under certain circumstances, I think it's to do with RENDER_BREAK...
Henry Ruhs
17:46
Henry Ruhs
of course it fails then
undefine is just to define a constant to be empty
our "constant" class should be a static holder for the constants
like constant::firstTable
or like constant::now
for the unit test we need to set the constants to dummy values
so the constant class needs to have a setter of course
anything else is not needed i think
Gary Aylward
17:49
Gary Aylward
But then you can only run a test once - since you can't change the values of the constants
Henry Ruhs
17:49
Henry Ruhs
you have to run it in multiple instances, yeah
maby we also write a "clear" method then
Gary Aylward
17:50
Gary Aylward
Perhaps what we need is read-only data in a class, so the data can only be set by the constructor, with a get method to allow read-nly access?
Henry Ruhs
17:50
Henry Ruhs
but i found it confusing if some code was able to change a "constant" because i always want to have it the same value
readonly by default, yeah
thats also good
and for unit test we can disable this
we do not need the undefine() stuff then
if constant does not exists we return false
Gary Aylward
17:52
Gary Aylward
We really need a set method that is only available in uit testing - I'm not sure that's possible though
If a constant doesn't exist shouldn't we return NULL ?
Henry Ruhs
17:52
Henry Ruhs
we should, yeah
ok, so do a get and a set
get and set method, thats it
KISS principle
let me write some "idea" code
hold one
Gary Aylward
17:55
Gary Aylward
As much as I hate global constants etc, perhaps we could have a TEST constant set during testing which is checked by the set method - if TEST is not defined, set fails
Henry Ruhs
18:02
Henry Ruhs
http://codepad.org/nObiuyh4
that would be inside migrate.php
could you please open an issue on Github
and put your gist and this link into
i guess its for 2.1.0
refactor