You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
(14) |
Oct
(22) |
Nov
(21) |
Dec
(7) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(4) |
Feb
(26) |
Mar
(62) |
Apr
(60) |
May
(73) |
Jun
(41) |
Jul
(64) |
Aug
(39) |
Sep
(19) |
Oct
(18) |
Nov
(55) |
Dec
(24) |
| 2005 |
Jan
(35) |
Feb
(122) |
Mar
(130) |
Apr
(62) |
May
(57) |
Jun
(103) |
Jul
(71) |
Aug
(142) |
Sep
(67) |
Oct
(27) |
Nov
(49) |
Dec
(56) |
| 2006 |
Jan
(42) |
Feb
(65) |
Mar
(30) |
Apr
(43) |
May
(13) |
Jun
(25) |
Jul
(5) |
Aug
(14) |
Sep
(18) |
Oct
(55) |
Nov
(126) |
Dec
(82) |
| 2007 |
Jan
(83) |
Feb
(83) |
Mar
(173) |
Apr
(30) |
May
(64) |
Jun
(156) |
Jul
(50) |
Aug
(29) |
Sep
(25) |
Oct
(26) |
Nov
(51) |
Dec
(9) |
| 2008 |
Jan
(36) |
Feb
(71) |
Mar
(93) |
Apr
(123) |
May
(34) |
Jun
(14) |
Jul
(21) |
Aug
(26) |
Sep
(49) |
Oct
(38) |
Nov
(19) |
Dec
(46) |
| 2009 |
Jan
(18) |
Feb
(16) |
Mar
(46) |
Apr
(4) |
May
(18) |
Jun
(9) |
Jul
(11) |
Aug
(4) |
Sep
(31) |
Oct
(19) |
Nov
(4) |
Dec
(11) |
| 2010 |
Jan
(15) |
Feb
(9) |
Mar
|
Apr
(20) |
May
(5) |
Jun
(8) |
Jul
(2) |
Aug
(9) |
Sep
(6) |
Oct
(21) |
Nov
(20) |
Dec
(11) |
| 2011 |
Jan
(11) |
Feb
(5) |
Mar
(6) |
Apr
(1) |
May
(12) |
Jun
(4) |
Jul
(1) |
Aug
(3) |
Sep
(4) |
Oct
(3) |
Nov
(3) |
Dec
(5) |
| 2012 |
Jan
(28) |
Feb
(7) |
Mar
(3) |
Apr
|
May
(5) |
Jun
(6) |
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(4) |
Nov
(5) |
Dec
(4) |
| 2013 |
Jan
|
Feb
|
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(5) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(7) |
Dec
|
| 2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2016 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(3) |
Oct
|
Nov
(1) |
Dec
|
| 2017 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Marcus B. <ma...@la...> - 2003-11-13 04:12:10
|
Hi...
Jason Sweat wrote:
> Just a check to make sure I am headed in the right direction:
You certainly seem to be.
> /**
> *
> * @package DataCache
> * @subpackage tests
> */
Surprising. Do you find it useful to PHPDoc your test cases?
> function Setup() {
> $this->c =& new DataCacheDaoFile(TEST_APPLICATION);
> $id = TEST_DAOFILE_BLANK;
> if (file_exists(DATACACHE_PATH.TEST_APPLICATION."/$id.php")) {
> unlink(DATACACHE_PATH.TEST_APPLICATION."/$id.php");
> }
> }
This is certainly the right way to use setUp().
> function TestTimeStamp() {
> $id = 'time';
> $ts = mktime();
> $this->AssertTrue($this->c->SetCache($id,$ts.$ts));
> $this->AssertTrue(1 >= abs($this->c->GetCacheTime($id) - $ts));
> $this->AssertEqual($this->c->GetCache($id), $ts.$ts);
> }
You could create a separate assert method for this, such as...
function assertNow($timing, $message = '%s') {
$message = sprintf($message, 'Within one second of now');
$this->assertTrue(1 >= abs($timing - mktime()), $message);
}
function testTimeStamp() {
$id = 'time';
$this->AssertTrue($this->c->SetCache($id,$ts.$ts));
$this->AssertNow($this->c->GetCacheTime($id));
$this->AssertEqual($this->c->GetCache($id), $ts.$ts);
}
>
> //run if stand alone
> if (!isset($this)) {
> $test = &new TestDataCacheDaoFile();
> $test->run(new HtmlReporter());
> }
Sneaky :).
yours, Marcus
--
Marcus Baker, ma...@la..., no...@ap...
|
|
From: Marcus B. <ma...@la...> - 2003-11-01 15:36:04
|
Hi...
A minor point and one you are already familiar with I am sure:
Jason Sweat wrote:
> function TestRemovePattern()
> {
...
> }
You can break tests down into smaller methods. It is only the ones that
start "test" that have an effect on the test suite. Something like...
function testIt() {
$this->loadData();
$this->assertThisAndThat(...);
}
function loadData() {
$this->database->query('more foo');
}
yours, Marcus
--
Marcus Baker, ma...@la..., no...@ap...
|
|
From: Jason S. <jsw...@ya...> - 2003-11-01 03:13:37
|
--- Jochen Buennagel wrote:
> Jason Sweat wrote:
> > Just a check to make sure I am headed in the right direction:
> > ...
>
> Looks sweet, except you have WAY too few occurences of "foo" and "bar"
> in your test data...
I did manage to get a "foobar" into this latest test :)
>
> Do you develop test-driven, i.e. write the test cases before the actual
> code? Doesn't look like it to me, and if you don't, then you should
> definitely have a look at TDD (Kent Beck's Books on the subject springs
> to mind), as it is really worthwhile.
I did write the tests I posted earlier after the code, however, there were two
additional methods that I had not yet coded. I went ahead an wrote the tests
first, and I think it definitly helped for the coding itself. Tests below :)
A couple of more thoughts I had on the subject of tests:
1) how would one go about testing for header('Location: ...); ?
2) code that does exit; will probably also be hard to test
Also, I can see how this testing works nicly for building a library of utility
classes, however, much of my coding is building View and Action classes in a
MVC framework that are essentially glue between other classes. I think my
limited understanding of Mocks is what is preventing me from thinking of a
creative solution to test these kind of classes.
Also, Also, how does one go about testing classes that integrate with third
party libraries like JpGraph? I could probably test for the existance of a
cached file, however, knowing if the graph looks right and has correct data is
a completly different issue. Any thoughts there?
Thanks.
Jason
/**
* test removing cached data works
*
* @return void
*/
function TestRemove()
{
$data = TEST_APPLICATION.mktime();
$id = 'to_be_removed';
$this->AssertTrue($this->c->SetCache($id, $data));
$this->AssertIdentical($data, $this->c->GetCache($id));
$this->AssertTrue($this->c->RemoveCache($id));
$r = $this->c->GetCache($id);
$this->AssertError("identifier '$id' does not have a valid cache");
}
/**
* test removing cached data works
*
* @return void
*/
function TestRemovePattern()
{
$data = TEST_APPLICATION.mktime();
$id1 = 'ato_be_removed';
$id2 = 'bto_be_removed';
$id3 = 'foobar';
$this->AssertTrue($this->c->SetCache($id1.'1', $data.'1'));
$this->AssertTrue($this->c->SetCache($id1.'2', $data.'2'));
$this->AssertTrue($this->c->SetCache($id2.'1', $data.'1'));
$this->AssertTrue($this->c->SetCache($id2.'2', $data.'2'));
$this->AssertIdentical($data.'1', $this->c->GetCache($id1.'1'));
$this->AssertIdentical($data.'2', $this->c->GetCache($id1.'2'));
$this->AssertIdentical($data.'1', $this->c->GetCache($id2.'1'));
$this->AssertIdentical($data.'2', $this->c->GetCache($id2.'2'));
$this->AssertTrue($this->c->RemovePatternCache(substr($id1,0,3)));
$r = $this->c->GetCache($id1.'1');
$this->AssertError("identifier '{$id1}1' does not have a valid cache");
$r = $this->c->GetCache($id1.'2');
$this->AssertError("identifier '{$id1}2' does not have a valid cache");
$this->AssertIdentical($data.'1', $this->c->GetCache($id2.'1'));
$this->AssertIdentical($data.'2', $this->c->GetCache($id2.'2'));
$this->AssertTrue($this->c->RemovePatternCache(substr($id2,0,5)));
$r = $this->c->GetCache($id2.'1');
$this->AssertError("identifier '{$id2}1' does not have a valid cache");
$r = $this->c->GetCache($id2.'2');
$this->AssertError("identifier '{$id2}2' does not have a valid cache");
$this->AssertFalse($this->c->RemovePatternCache($id3));
$this->AssertError("identifier pattern '$id3' does not have any valid cached
data");
}
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
|
|
From: Marcus B. <ma...@la...> - 2003-10-31 03:30:36
|
Hi all. Finally got to Beta status sort of. :( The web tester gets form submission, but only for text fields. Apart from very simple login screens this makes it pretty useless. I have moved it into Beta because of all of the unit tester/mock objects fixes and because the core interfaces are now frozen on these. As it rolls on to version 1.0 I will be trying to make it more usable, more consistent and more robust. Any help here would be much appreciated even if it is just in the form of damning criticism. yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |
|
From: <jb...@bu...> - 2003-10-30 19:53:33
|
Marcus Baker wrote: > Sadly no. I can barely find time to keep to the release schedule, let > alone produce more supporting material :(. Well, another site about patterns fared pretty well using a wiki, so maybe that could work? Jochen (Bunny) |
|
From: Marcus B. <ma...@la...> - 2003-10-30 19:46:05
|
Hi... Jochen Buennagel wrote: >> Perhaps I should start a mock/test refactoring pattern page on the >> lastcraft site? > > > I gather that this was a retorical question? ;-) Sadly no. I can barely find time to keep to the release schedule, let alone produce more supporting material :(. > Jochen > (Bunny) yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |
|
From: Jason S. <jsw...@ya...> - 2003-10-29 18:21:16
|
--- Marcus Baker <ma...@la...> wrote: > I haven't got time to look at it right now. I'll return to it in a > couple of days if that's OK. Sounds good, comments welcome when available ;) __________________________________ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/ |
|
From: Jochen B. <jb...@bu...> - 2003-10-29 14:35:52
|
Marcus Baker wrote: > Perhaps I should start a mock/test refactoring pattern page on the > lastcraft site? I gather that this was a retorical question? ;-) I wish a productive day, Jochen (Bunny) |
|
From: Marcus B. <ma...@la...> - 2003-10-29 14:22:50
|
Hi... Jason Sweat wrote: > One more thought I would like to have clarified on this subject: > You should never test private methods, only the public API for an object. That > way you are free to refactor the private methods without altering your test > case. Good question and a hot topic of debate. When you have finished a module I would say definitely leave out the private method tests. The same with protected ones unless you are specifically testing a subclass. When I am actually coding and am getting confused, I will write quick private method tests, just to see what is going on. > Jason yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |
|
From: Marcus B. <ma...@la...> - 2003-10-29 14:20:26
|
Hi... Jason Sweat wrote: > When constructing a test for this kind of a system, I assume it is fine to > write unit test cases for each of the DAOs, however when it comes to the > DataCache class itself, is it better to test the DAOs first, then the DataCache > as written, or is it better to mock the DAOs and test the outer class by > itself? > > Any guidlines or rules of thumb that you use in these cases? Whilst I am unsure of the design there are just no rules. Usually I will mock at least the database connection and the system configuration file simply for speed. I don't want to mess with real datbases when coding. This is a real hidden benefit of stubs/mocks. They can be a useful prototyping tool in themselves. Once things start to settle down I tend to start at the top level, mocking everything below. The mocks I am forced to create drive teh interfaces of the lowest level classes, effectively creating a spec. It is more iterative than this of course, but this is a common trick. I'll even use the partial mocks to stub out methods of a class I have not written yet. In short I will mock too much at the start (because it's quicker and I am lazy), gradually replacing any mocks that are really the job of the system I am testing and so should be part of the test. After this process I have a few classes with tests that do not overlap too much. At this point I start putting in the real end to end system tests. At this point a few glitches will show up, but it is rare that it takes more than an hour to get the real "live" tests working including any dummy data. Because these type of tests run rahter slower, I put them in their own test suite. The catch in this wonderful scheme is that I am extremely familiar with mock objects now, having used continually for over 18 months. If you haven't used them a great deal you probably won't have things so light and easy. > > Thanks. > > Jason If the individual DAOs are inherited from the superclass, I would create a particular DAO first, then another, then refactor the commonality (using just the other two test sets). Finally you can move the tests into the superclass test and partial mock those parts that were in the original subclass test. Slightly "by the book" refactoring wise, but safe. I'll try and show an example when I next get time. Perhaps I should start a mock/test refactoring pattern page on the lastcraft site? yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |
|
From: Marcus B. <ma...@la...> - 2003-10-29 14:05:10
|
Hi... Jason Sweat wrote: > Just a check to make sure I am headed in the right direction: I haven't got time to look at it right now. I'll return to it in a couple of days if that's OK. yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |
|
From: Jason S. <jsw...@ya...> - 2003-10-29 13:35:56
|
One more thought I would like to have clarified on this subject: You should never test private methods, only the public API for an object. That way you are free to refactor the private methods without altering your test case. Or am I mistaken? Thanks, Jason --- Jason Sweat <jsw...@ya...> wrote: > This project that I am working on is a DataCache. I wanted to be able to > implement it either using the file system or using a database, so I decided > to > make a DAO to support either of these options, and have a DataCache class > that > decides which of the DAOs to use. > > When constructing a test for this kind of a system, I assume it is fine to > write unit test cases for each of the DAOs, however when it comes to the > DataCache class itself, is it better to test the DAOs first, then the > DataCache > as written, or is it better to mock the DAOs and test the outer class by > itself? > > Any guidlines or rules of thumb that you use in these cases? > > Thanks. > > Jason > > __________________________________ > Do you Yahoo!? > Exclusive Video Premiere - Britney Spears > http://launch.yahoo.com/promos/britneyspears/ > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Simpletest-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simpletest-support __________________________________ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/ |
|
From: Jason S. <jsw...@ya...> - 2003-10-29 12:59:13
|
This project that I am working on is a DataCache. I wanted to be able to implement it either using the file system or using a database, so I decided to make a DAO to support either of these options, and have a DataCache class that decides which of the DAOs to use. When constructing a test for this kind of a system, I assume it is fine to write unit test cases for each of the DAOs, however when it comes to the DataCache class itself, is it better to test the DAOs first, then the DataCache as written, or is it better to mock the DAOs and test the outer class by itself? Any guidlines or rules of thumb that you use in these cases? Thanks. Jason __________________________________ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/ |
|
From: Jason S. <jsw...@ya...> - 2003-10-29 12:55:19
|
Just a check to make sure I am headed in the right direction:
TestDataCacheDaoFile.php:
<?php
/**
* test harness for DataCacheDaoFile class tests
*
* @author Jason E. Sweat
* @since 2003-10-28
* @package DataCache
* @subpackage tests
* @version
* <pre>
* $Log: $
* </pre>
*/
error_reporting(E_ALL);
/**
* relative path to SimpleTest
*/
@define('SIMPLE_TEST', '../simpletest/');
/**
* SimpleTest base class
*/
require_once SIMPLE_TEST.'unit_tester.php';
/**
* SimpleTest reporter class
*/
require_once SIMPLE_TEST.'reporter.php';
/**
* DataCache class to be tested
*/
require_once '../DataCacheDaoFile.php';
/**
* Application Identifier to use for the tests
*/
@define('TEST_APPLICATION', 'SimpleTests');
/**
*
*/
define('TEST_DAOFILE_BLANK', 'empty');
/**
* still not working
* with funky chars ~!@#$%^&*()_+`-={}|\][:"<>?';/.,
*
*/
define('TEST_DAOFILE_STRING', <<<EOS
has both '
and " in it
on multiple lines
EOS
);
/**
*
* @package DataCache
* @subpackage tests
*/
class TestDataCacheDaoFile extends UnitTestCase
{
/**
* @var object $c the data cache object
*/
var $c;
/**
* constructor
*
* @return void
*/
function TestDataCacheDaoFile() {
$this->UnitTestCase();
}
/**
* initialization of test function
*
* @return void
*/
function Setup() {
$this->c =& new DataCacheDaoFile(TEST_APPLICATION);
$id = TEST_DAOFILE_BLANK;
if (file_exists(DATACACHE_PATH.TEST_APPLICATION."/$id.php")) {
unlink(DATACACHE_PATH.TEST_APPLICATION."/$id.php");
}
}
/**
* test php environment is setup correctly
*
* @return void
*/
function TestEnv() {
$this->AssertTrue(defined('DATACACHE_PATH'));
$this->AssertTrue(is_dir(DATACACHE_PATH));
$this->AssertEqual(substr(DATACACHE_PATH,-1,1), '/');
}
/**
* test creation of a directory when instanciated
*
* @return void
*/
function TestDirCreation() {
$id = 'mkdir';
$this->AssertFalse(is_dir(DATACACHE_PATH.TEST_APPLICATION.$id));
$o =& new DataCacheDaoFile(TEST_APPLICATION.$id);
$this->AssertTrue(is_dir(DATACACHE_PATH.TEST_APPLICATION.$id));
$this->AssertTrue(rmdir(DATACACHE_PATH.TEST_APPLICATION.$id));
}
/**
* test when data not already cached
*
* @return void
*/
function TestEmptyCache() {
$id = TEST_DAOFILE_BLANK;
$this->AssertFalse($this->c->IsCached($id));
$r = $this->c->GetCache($id);
$this->AssertError("identifier '$id' does not have a valid cache");
}
/**
* test timestamp
*
* @return void
*/
function TestTimeStamp() {
$id = 'time';
$ts = mktime();
$this->AssertTrue($this->c->SetCache($id,$ts.$ts));
$this->AssertTrue(1 >= abs($this->c->GetCacheTime($id) - $ts));
$this->AssertEqual($this->c->GetCache($id), $ts.$ts);
}
/**
* test caching different types
*
* @return void
*/
function TestCache() {
$data = array(
'str1' => 'a simple string'
,'str2' => "a multi-\nline string"
,'str3' => 'a "double quote" string'
,'str4' => "a 'single quote' string"
,'str5' => TEST_DAOFILE_STRING
,'int' => mktime()
,'array' => array('one', 'two', 'three')
,'object' => new DataCacheDaoFile(TEST_APPLICATION)
);
$this->AssertTrue($this->c->SetCache('data', $data));
$this->AssertIdentical($this->c->GetCache('data'), $data);
$this->AssertTrue($this->c->SetCache('data', $data, false));
$this->AssertIdentical($this->c->GetCache('data'), $data);
}
/**
* test file compression
*
* @return void
*/
function TestZip() {
ob_start();
phpinfo();
$data = ob_get_contents();
ob_end_clean();
$this->AssertTrue($this->c->SetCache('zip', $data));
$this->AssertTrue($this->c->SetCache('nozip', $data, false));
$this->AssertTrue( filesize(DATACACHE_PATH.TEST_APPLICATION.'/nozip.php') >
filesize(DATACACHE_PATH.TEST_APPLICATION.'/zip.php'));
}
}
//run if stand alone
if (!isset($this)) {
$test = &new TestDataCacheDaoFile();
$test->run(new HtmlReporter());
}
#?>
DataCacheDaoFile.php:
<?php
/**
* DataCacheDaoFile class definiton
*
* concrete file based DAO for the DataCache class
*
* A PHP Class to implement server side data caching
* Copyright (C) 2003 Jason E. Sweat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author Jason E. Sweat
* @since 2003-10-26
* @package DataCache
* @subpackage DAO
* @version
* <pre>
* $Log: $
* </pre>
*/
/**
* location where cache files are kept
*
* assumed in the rest of the code to be full path with a trailing slash
*/
define('DATACACHE_PATH', '/home/sweatje/phpc/cache/data/');
/**
* template for caching data as readable php code
*/
define('DATACACHE_TEMPLATE', <<<EOS
<?php
\$m_cache_data = unserialize(stripslashes('%s'));
#?>
EOS
);
/**
* template for caching data as zipped data
*/
define('DATACACHE_ZIP_TEMPLATE', <<<EOS
<?php
\$m_cache_data = unserialize(gzuncompress(base64_decode('%s')));
#?>
EOS
);
/**
* concrete file based DAO for the DataCache class
*
* @package DataCache
* @subpackage DAO
*/
class DataCacheDaoFile
{
/**
* @private
* @var string _msAppl the name of the application
*/
var $_msAppl;
/**
* constructor
*
* @param string $psAppl the application identifier
* @return void
*/
function DataCacheDaoFile($psAppl)
{
if (!is_dir(DATACACHE_PATH.$psAppl)) {
umask(0007);
mkdir(DATACACHE_PATH.$psAppl);
}
$this->_msAppl = $psAppl;
}
/**
* return the full path and file name for a cache file
*
* @private
* @param string $psId identifier for the data being cached
* @return string the file path and name
*/
function _GetFileName($psId)
{
return DATACACHE_PATH.$this->_msAppl.'/'.$psId.'.php';
}
/**
* cache a particular piece of data
*
* @param string $psId identifier for the data being cached
* @param mixed $pmValue value to cache
* @param boolean $pbZip optional - compress the data, defaults to true
* @return boolean sucess
*/
function SetCache($psId, $pmValue, $pbZip=true)
{
$s_file = $this->_GetFileName($psId);
$s_template = ($pbZip) ? DATACACHE_ZIP_TEMPLATE : DATACACHE_TEMPLATE;
$s_data = ($pbZip) ? base64_encode(gzcompress(serialize($pmValue)))
: addslashes(serialize($pmValue));
$r_fh = fopen($s_file, 'w');
flock($r_fh, LOCK_EX);
$b_ret = fwrite($r_fh,
sprintf($s_template,
$s_data
)
);
flock($r_fh, LOCK_UN);
fclose($r_fh);
return $b_ret;
}
/**
* check to see if a cached data is valid
*
* @param string $psId identifier for the data being cached
* @return boolean result of check
*/
function IsCached($psId)
{
return file_exists($this->_GetFileName($psId));
}
/**
* retrieve some cached data
*
* @param string $psId identifier for the data being cached
* @return mixed the data cached
*/
function GetCache($psId)
{
if ($this->IsCached($psId)) {
require $this->_GetFileName($psId);
return $m_cache_data;
} else {
trigger_error("identifier '$psId' does not have a valid cache");
}
}
/**
* retrieve time when data was cached
*
* @param string $psId identifier for the data being cached
* @return mixed the data cached
*/
function GetCacheTime($psId)
{
if ($this->IsCached($psId)) {
return filemtime($this->_GetFileName($psId));
} else {
trigger_error("identifier '$psId' does not have a valid cache");
}
}
}
#?>
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
|
|
From: Marcus B. <ma...@la...> - 2003-10-21 02:58:22
|
Hi... Marcus Baker wrote: >> This is not true, however. The last parameter was NULL. So, I think >> the message should have been: >> >> Fail: ./cases/wact_validate.inc.php->validationtestcase- >> >testnumericrulefailure->Arguments for [adderror] were [String: >> core, String: NOT_NUMERIC, Array: 1 items, NULL] > Fixed. The error reporting has been refactored (a process actually started before the bug came in) and is now usable. There is still work to be done here (see the TODO), but this should do until Beta1. yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |
|
From: Marcus B. <ma...@la...> - 2003-10-21 02:52:56
|
Jeff Moore wrote: > Now, I am not sure exactly what is not matching in my expectOnce > statement. It would be nice if the failure message were more elaborate: Done. In CVS now and will roll out in Beta1. yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |
|
From: Marcus B. <ma...@la...> - 2003-10-19 20:25:40
|
Hi... Jeff Moore wrote: > Ok, I found my issue. Excellent. Wish I had read this before posting my last :). > The failure message was: > > Fail: ./cases/wact_validate.inc.php->validationtestcase- > >testnumericrulefailure->Arguments for [adderror] were [String: core, > String: NOT_NUMERIC, Array: 1 items] > > This is not true, however. The last parameter was NULL. So, I think > the message should have been: > > Fail: ./cases/wact_validate.inc.php->validationtestcase- > >testnumericrulefailure->Arguments for [adderror] were [String: core, > String: NOT_NUMERIC, Array: 1 items, NULL] Which is indeed a bug. This looks like another PHP quirk with the way it treats NULL values in arrays in some functions, but not others. You are right about SimpleTest being fussy about the number of incoming parameters and this is deliberate. That it doesn't report the NULL (it should) will need investigation. > So, for the last parameter that defaults to NULL, simpletest can detect > if the parameter was left off completely (thus leaving the 4th > parameter to default to NULL), or if a NULL was actually passed in the > 4th parameter. (not something I expected to make a difference in PHP) > The check for NULL is intended because it could be masking a more serious error in code. It looks like the implementation of this is incomplete. Thanks for pointing this out. > Anyway, it would be nice if the Failure message could give a more > complete accounting of the differences between what was expected and > what was received. I am working on it, but also trying to keep the corpse of my social life warm as best I can. > > Sorry to bug you with my learning issues. :) > Hm. It's a bug pure and simple. yours, Marcus p.s. Any features you would like added before I push the tool into Beta? -- Marcus Baker, ma...@la..., no...@ap... |
|
From: Jeff M. <je...@pr...> - 2003-10-19 11:23:07
|
I started doing some test first design and wrote the following test:
Mock::generate('ErrorList');
Mock::generatePartial(
'Validator',
'ValidatorTestVersion',
array('createErrorList'));
class ValidationTestCase extends UnitTestCase {
var $validator;
var $ErrorList;
function DataSpaceTestCase($name = 'ValidationTestCase') {
$this->UnitTestCase($name);
}
function setUp() {
$this->ErrorList =& new MockErrorList($this);
$this->validator =& new ValidatorTestVersion($this);
$this->validator->setReturnReference('createErrorList',
$this->ErrorList);
}
function tearDown() {
$this->validator->tally();
$this->ErrorList->tally();
unset ( $this->validator );
unset ( $this->ErrorList );
}
function testNumericRuleFailure() {
$this->validator->addRule(new NumericDigitsRule('testfield', 3,
2));
$Data =& new DataSpace();
$Data->set('testfield', 'not a number');
$this->ErrorList->expectOnce('addError', array('core',
'NOT_NUMERIC', array('Field'=>'testfield')));
$this->validator->validate($Data);
$this->assertFalse($this->validator->IsValid());
}
}
Then, I went and implemented the NumericDigitsRule class. However, my
test fails with the following message:
Fail:
./cases/wact_validate.inc.php->validationtestcase-
>testnumericrulefailure->Arguments for [adderror] were [String: core,
String: NOT_NUMERIC, Array: 1 items]
Now, I am not sure exactly what is not matching in my expectOnce
statement. It would be nice if the failure message were more elaborate:
Fail:
./cases/wact_validate.inc.php->validationtestcase-
>testnumericrulefailure->Arguments for [adderror] were [String: core,
String: NOT_NUMERIC, Array: 1 items] expecting [String: core, String:
NOT_NUMERIC, array: 1 items], third parameter does not match.
BTW, strategic var_dumps on the addError call show the parameters to
addError on the failing case to be:
string(4) "core" string(11), "NOT_NUMERIC", array(1) { ["Field"]=>
string(9) "testfield" }
I am not exactly sure why the test case is failing. I am probably
missing something stupid. I do have other similar cases that are
passing:
function testRequiredRuleFailure() {
$this->validator->addRule(new RequiredRule('testfield'));
$Data =& new DataSpace();
$this->ErrorList->expectOnce('addError', array('core',
'MISSING', array('Field'=>'testfield')));
$this->validator->validate($Data);
$this->assertFalse($this->validator->IsValid());
}
Hmmm.
|
|
From: Jeff M. <je...@pr...> - 2003-10-19 05:52:34
|
Ok, I found my issue.
The Mock function I was using for testing was:
function addError($Group, $Id, $FieldList, $Values = NULL)
My problem had to do with the last parameter.
The failure message was:
Fail:
./cases/wact_validate.inc.php->validationtestcase-
>testnumericrulefailure->Arguments for [adderror] were [String: core,
String: NOT_NUMERIC, Array: 1 items]
This is not true, however. The last parameter was NULL. So, I think
the message should have been:
Fail:
./cases/wact_validate.inc.php->validationtestcase-
>testnumericrulefailure->Arguments for [adderror] were [String: core,
String: NOT_NUMERIC, Array: 1 items, NULL]
Changing my expectOnce from
$this->ErrorList->expectOnce('addError', array('core', 'NOT_NUMERIC',
array('Field'=>'testfield')));
To
$this->ErrorList->expectOnce('addError', array('core', 'NOT_NUMERIC',
array('Field'=>'testfield'),NULL));
Made the test pass.
It seems that simpletest is able to detect how many actual parameters
were passed.
The following pair works:
$this->ErrorList->expectOnce('addError', array('core', 'NOT_NUMERIC',
array('Field'=>'testfield')));
$ErrorList->addError(..., ..., ...);
The following pair works:
$this->ErrorList->expectOnce('addError', array('core', 'NOT_NUMERIC',
array('Field'=>'testfield'),NULL));
addError(..., ..., ..., NULL);
But this does not work:
$this->ErrorList->expectOnce('addError', array('core', 'NOT_NUMERIC',
array('Field'=>'testfield')));
$ErrorList->addError(..., ..., ..., NULL);
So, for the last parameter that defaults to NULL, simpletest can detect
if the parameter was left off completely (thus leaving the 4th
parameter to default to NULL), or if a NULL was actually passed in the
4th parameter. (not something I expected to make a difference in PHP)
Anyway, it would be nice if the Failure message could give a more
complete accounting of the differences between what was expected and
what was received.
Sorry to bug you with my learning issues. :)
|
|
From: Jeff M. <je...@pr...> - 2003-10-18 20:47:39
|
Well, I am starting to get into SimpleTest on WACT. I am very impressed by SimpleTest so far. I had a long question written up, but by the time I finished writing it, I had answered it my self. :) |
|
From: Marcus B. <ma...@la...> - 2003-10-15 23:55:39
|
Hi. Zbynek Winkler wrote: > I am using some global variables in my scripts. It seems to me that when > being tested the files are included in some local scope which means that > any global variable defined in the file is now a local varible of the > scope used to include the file. This way using "global $variable;" in a > function does not work because the global variable $variable is not global. You are correct. It is the GroupTest::addTestFile() method (it does an include() within that method). Either mark the variable as global everywhere (as Jason suggests), or include the test cases file in the group test file as you would normally and use GroupTest::addTestCase() on each test case by name. The first option is safest, but the second saves changing the code under test. > Zbynek > yours, Marcus -- Marcus Baker, ma...@la..., no...@ap... |
|
From: Marcus B. <ma...@la...> - 2003-10-15 23:47:22
|
Hi...
Zbynek Winkler wrote:
>> ini_set("allow_call_time_pass_reference", "1");
>
>
> will not work because this option can be changed only in
> PHP_INI_SYSTEM|PHP_INI_PERDIR and not PHP_INI_USER. Look at the table at
> http://www.php.net/manual/en/function.ini-set.php for more info. You can
> see a warning (that is if you've turned them on ;-)).
Ouch! I had the ini file set to allow them and so recieved no warning.
Unfortunately I use this to get a reference through an optional
parameter so as to inject mocks. I'll see if I can refactor the code,
but the problem will disappear in PHP 5.
It actually only affects the running of SimpleTest's own tests in any
case so a workaround is to enable it in the ini file whilst upgrading
SimpleTest and, once all the tests are OK, turn it off again.
>
> Zbynek
>
Thanks for pointing that out.
yours, Marcus
--
Marcus Baker, ma...@la..., no...@ap...
|
|
From: Jason S. <jsw...@ya...> - 2003-10-15 18:39:33
|
Do global $variable; in your original include file to make sure they are always global in scope. And stop using them ;) Jason --- Zbynek Winkler <zw...@us...> wrote: > Hi, > > I am using some global variables in my scripts. It seems to me that when > being tested the files are included in some local scope which means that > any global variable defined in the file is now a local varible of the > scope used to include the file. This way using "global $variable;" in a > function does not work because the global variable $variable is not global. > > Is there a workaround for this? > > Zbynek > > -- > http://zw.matfyz.cz/ http://robotika.cz/ > Faculty of Mathematics and Physics, Charles University, Prague, Czech > Republic > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > SourceForge.net hosts over 70,000 Open Source Projects. > See the people who have HELPED US provide better services: > Click here: http://sourceforge.net/supporters.php > _______________________________________________ > Simpletest-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simpletest-support __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com |
|
From: Zbynek W. <zw...@us...> - 2003-10-15 18:27:44
|
Hi, I am using some global variables in my scripts. It seems to me that when being tested the files are included in some local scope which means that any global variable defined in the file is now a local varible of the scope used to include the file. This way using "global $variable;" in a function does not work because the global variable $variable is not global. Is there a workaround for this? Zbynek -- http://zw.matfyz.cz/ http://robotika.cz/ Faculty of Mathematics and Physics, Charles University, Prague, Czech Republic |
|
From: Zbynek W. <zw...@ro...> - 2003-10-15 18:01:41
|
Hi,
the setting in "simpletest\test\unit_tests.php"
> ini_set("allow_call_time_pass_reference", "1");
will not work because this option can be changed only in
PHP_INI_SYSTEM|PHP_INI_PERDIR and not PHP_INI_USER. Look at the table at
http://www.php.net/manual/en/function.ini-set.php for more info. You can
see a warning (that is if you've turned them on ;-)).
Zbynek
--
<zwin at robotika.cz>
http://zw.matfyz.cz/ http://robotika.cz/
Faculty of Mathematics and Physics, Charles University, Prague, Czech Republic
|