0

我正在尝试使用 PHP 进行 TDD,并且正在编写一个基于 Web 的应用程序来访问 MySQL 数据库中的文章;这是测试功能:

class TestArticleTestCase extends UnitTestCase {

...

public function testArticleGenerateInsertSqlString() {
    $testArticle = new Article("12345", "2009-09-13 20:20:20", "Test heading", "Test text");

    ...

}

这是文章类:

class Article {
    private $_articleId;
    private $_pubDate;
    private $_heading;
    private $_text;

    public function __construct($articleId, $pubDateUnchecked, $headingUnescaped, $textUnescaped) {
        echo "pubDateUnchecked == $pubDateUnchecked </BR>";
            ...

 }

我在构造函数中包含了回显,因为数据库中的日期不是我初始化文章时使用的日期,果然,跟踪问题,这是构造函数中回显的输出:

pubDateUnchecked == 2005-06-01 12:00:00

也许我只是盯着这段代码太久了,但是在我开始将它作为日期操作之前,字符串如何从我实例化它的位置更改为直接实例化它的位置(我检查它是否是允许的日期格式与 strtotime () 和 date() 稍后......)。

有人对在哪里看有任何想法吗?

谢谢你,斯蒂芬。

4

1 回答 1

0

也许是缓存问题?或者你编辑了错误的文件?以前发生过;-)
在这种情况下,调试器会很有帮助。但是,如果您没有/无法安装一个,请尝试类似

public function testArticleGenerateInsertSqlString() {
  $testdata = array(
    array('articleId'=>"12345", 'pubDateUnchecked'=>"2009-09-13 20:20:20", 'headingUnescaped'=>"Test heading", 'textUnescaped'=>"Test text")
  );
  echo '<div>Test. Now=', date('Y-m-d H:i:s'),' modtime(__FILE__)=', date('Y-m-d H:i:s', filemtime(__FILE__)), "</div>\n";
  foreach( $testdata as $t ) {
    echo "<div>Test. new Article({$t['articleId']}, {$t['pubDateUnchecked']}, {$t['headingUnescaped']}, {$t['textUnescaped']})</div>";
    $testArticle = new Article($t['articleId'], $t['pubDateUnchecked'], $t['headingUnescaped'], $t['textUnescaped']); 
于 2009-08-19T10:51:17.413 回答