2

我有一个很小的 ​​PHPUnit 测试,看起来像这样:

<?php
namespace VNN\PressboxBundle\Tests\Entity;
namespace VNN\PressboxBundle\Entity;

use VNN\PressboxBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Phactory\Sql\Phactory;

class UserTest extends EntityTest
{
    public function testCreate()
    {   
        Phactory::reset();
    }   
}

当我尝试运行它时,我得到了这个:

There was 1 error:

1) VNN\PressboxBundle\Entity\UserTest::testCreate
ErrorException: Runtime Notice: Non-static method Phactory\Sql\Phactory::reset() should not be called statically, assuming $this from incompatible context in /Users/jason/Web/pressbox/src/VNN/PressboxBundle/Tests/Entity/UserTest.php line 13

那是怎么回事?所有文档都静态地调用它。

我在 Symfony 2.0 上这样做,如果这有什么不同的话。

4

3 回答 3

0

文档说您应该直接使用顶级Phactory类——lib/而不是单个实现,例如根据您传递给Phactory/Sql/Phactory的对象实例化的实现。改变PDOsetConnection

use Phactory\Sql\Phactory;

require_once 'Phactory/lib/Phactory.php';

主类位于全局命名空间中,不需要use声明。

于 2012-10-31T22:05:47.890 回答
0

https://github.com/chriskite/phactory/issues/30

从代码来看,setConnection、define 和 create 不是静态函数,但 README 和网站指南并未反映这一点。

例如测试代码 https://github.com/chriskite/phactory/blob/next/tests/Phactory/Sql/PhactoryTest.php

use Phactory\Sql\Phactory;
...
$this->pdo = new \PDO("sqlite:test.db");
$this->phactory = new Phactory($this->pdo);
$this->phactory->define('user');
$this->phactory->reset();

不知道什么时候改的。

反正来晚了……

于 2014-02-18T10:08:35.213 回答
0

当前版本 0.3.2 与记录的静态方法结构不向后兼容。

这是中断提交:https ://github.com/chriskite/phactory/commit/d3b60eeedea955ab7b5803ec29446d19888d3849

不幸的是, http ://phactory.org上的文档尚未更新,并且 pearhub 存储库不再可用。

我会看看测试的例子:https ://github.com/chriskite/phactory/blob/next/tests/Phactory/Sql/PhactoryTest.php

于 2014-03-29T18:16:58.250 回答