简体   繁体   English

收到错误:非静态方法Phactory \\ Sql \\ Phactory :: reset()不应静态调用

[英]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基于传递给setConnectionPDO对象实例化的单个实现(例如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.

相关问题 无法在Symfony2 / PHPUnit测试中包含Phactory - Can't include Phactory in Symfony2/PHPUnit test 如何在tpl文件中调用tcpdf非静态方法 - How to call tcpdf non-static method in tpl file 我可以将非静态对象放入静态属性吗? - Can I put a non-static object in a static property? Symfony 2 / Repository:错误:在非对象上调用__clone方法 - Symfony 2 / Repository : Error: __clone method called on non-object 指定使用SymfonyStyle进行样式输出的Symfony命令时,在非对象上调用克隆方法 - Getting clone method called on non-object when specing Symfony command that uses SymfonyStyle for styled output PHP致命PHP致命错误:在非对象上调用__clone方法 - PHP Fatal PHP Fatal error: __clone method called on non-object Symfony方法未在提交操作时在jQuery中调用 - Symfony method is not getting called in jquery on submit action 在对象数组中调用的非对象上的致命错误getId() - Fatal error getId() on a non-object called in an array of objects 得到&#39;方法应该被调用1次,实际上被调用0次。 在 Symfony 中进行测试时 - Getting 'Method was expected to be called 1 times, actually called 0 times.' while testing in Symfony 当我尝试在 Laravel 中发送重置密码链接时出现解析错误 - Getting parse error when i try to send reset password link in laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM