[英]Getting error: Non-static method Phactory\Sql\Phactory::reset() should not be called statically
I have a trivially small PHPUnit test that looks like this: 我有一个很小的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();
}
}
When I try to run it, I get this: 当我尝试运行它时,得到以下信息:
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
What's up with that? 那是怎么回事? All the docs call it statically.
所有文档都将其称为静态。
I'm doing this on Symfony 2.0, if that makes a difference. 如果可以的话,我正在Symfony 2.0上执行此操作。
The documentation says you should be using the top-level Phactory
class directly under lib/
--not the individual implementations such as Phactory/Sql/Phactory
which get instantiated based on the PDO
object you pass to setConnection
. 该文档说,您应该直接在
lib/
下使用顶级Phactory
类-而Phactory
基于传递给setConnection
的PDO
对象实例化的单个实现(例如Phactory/Sql/Phactory
setConnection
。 Change 更改
use Phactory\Sql\Phactory;
to 至
require_once 'Phactory/lib/Phactory.php';
The main class is in the global namespace and doesn't require a use
statement. 主类位于全局名称空间中,不需要
use
语句。
https://github.com/chriskite/phactory/issues/30 https://github.com/chriskite/phactory/issues/30
From the code, setConnection, define and create are not static functions but the README and website guide do not reflect that.
从代码来看,setConnection,define和create不是静态函数,但README和网站指南却没有体现这一点。
eg test code https://github.com/chriskite/phactory/blob/next/tests/Phactory/Sql/PhactoryTest.php 例如测试代码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();
I don't know when it has been changed. 我不知道什么时候改变了。
Too late anyways... 反正太晚了...
The current version, 0.3.2, is not backward compatible with the static method structure that is documented. 当前版本0.3.2与所记录的静态方法结构不向后兼容。
Here is the breaking commit: https://github.com/chriskite/phactory/commit/d3b60eeedea955ab7b5803ec29446d19888d3849 这是令人震惊的提交: https : //github.com/chriskite/phactory/commit/d3b60eeedea955ab7b5803ec29446d19888d3849
Unfortunately, the documentation has not been updated on http://phactory.org and the pearhub repo is no longer available. 不幸的是,该文档尚未在http://phactory.org上更新,并且pearhub仓库不再可用。
I would look to the tests for examples: https://github.com/chriskite/phactory/blob/next/tests/Phactory/Sql/PhactoryTest.php 我将以测试为例: https : //github.com/chriskite/phactory/blob/next/tests/Phactory/Sql/PhactoryTest.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.