21307 Posts in 5737 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 507 Views |
-
Dates, Created, Now() and automated testing....

17 December 2010 at 12:27pm Last edited: 17 December 2010 12:28pm
I am doing work on automated testing at the moment and there is large areas of the code that rely on the 'Created' field in tables. This, as far as I can tell, is always going to use now() in mysql to write it, how can I go about changing it so that it returns my "fake date" that I am using elsewhere.
To note I am currently using a very simple date class to get now (time()) and then overriding the object to allow setting a var and then returning that instead. Am I to do the same thing for MySQLDatabase? overide it (TestMySQLDatabase, function now())?
Are there other areas to do this for? Is there anyinformation on the how to do this for automated testing?
-
Re: Dates, Created, Now() and automated testing....

17 December 2010 at 10:50pm
ok so I have my own ...
class TestMySQLDatabase extends MySQLDatabase {
function now(){
global $dm;//return 'NOW()';
return DateManager::mysqlDateQuoted($dm->getCurrentDateTime());
}}
and I'm using it this way...
global $databaseConfig;
$oldConfig = $databaseConfig;$databaseConfig = array(
"type" => 'TestMySQLDatabase',
"server" => 'localhost',
"username" => $oldConfig['username'],
"password" => $oldConfig['password'],
"database" => $oldConfig['database'],
"path" => '',
);DB::connect($databaseConfig);
$do = new SomeDataObject();
$do->SomeField = $somevalue;
$do->write();$databaseConfig = $oldConfig;
DB::connect($databaseConfig);But this is the one I was looking for...
$mockDate = $this->Date.' 00:00:00';
SS_Datetime::set_mock_now($mockDate);DataObjects now with created & lastedited times under my control... Silverstripe again streets ahead!
| 507 Views | ||
|
Page:
1
|
Go to Top |

