Jason Swett
Jason Swett

Reputation: 45134

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:

<?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.

Upvotes: 2

Views: 821

Answers (3)

trimbletodd
trimbletodd

Reputation: 337

The current version, 0.3.2, is not backward compatible with the static method structure that is documented.

Here is the breaking commit: 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.

I would look to the tests for examples: https://github.com/chriskite/phactory/blob/next/tests/Phactory/Sql/PhactoryTest.php

Upvotes: 0

hmp5bs
hmp5bs

Reputation: 1

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.

e.g. test code 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...

Upvotes: 0

David Harkness
David Harkness

Reputation: 36562

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. 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.

Upvotes: 0

Related Questions