2012-10-31 32 views
2

我有一個平凡的小PHPUnit的測試,看起來像這樣:四處錯誤:非靜態方法Phactory SQL Phactory ::復位()不應該被稱爲靜態

<?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上這樣做,如果這有所作爲。

回答

0

文檔說,你應該使用直屬lib/ --not個人實現,如Phactory/Sql/Phactory其中獲得基於傳遞給setConnectionPDO對象上實例頂級Phactory類。更改

use Phactory\Sql\Phactory; 

require_once 'Phactory/lib/Phactory.php'; 

主類是在全局命名空間,並不需要一個use聲明。

+0

有趣。 'Phactory/lib'中沒有'Phactory.php'。我使用Composer安裝了Phactory,條目如下所示:''chriskite/phactory「:」*「' –

+0

而在GitHub上,'lib'中沒有'Phactory.php'。 https://github.com/chriskite/phactory/tree/next/lib –

+0

另一個線索:在phactory.org的下載頁面鏈接到'Phactory-0.1.0.tgz',但最新版本的Phactory顯然是0.3 0.2。也許網站上的所有內容都過時了。 –

0

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.

例如測試代碼 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(); 

當它已經改變了,我不知道。反正

太晚了......

相關問題