使用参数对类进行单元测试

Im am starting to unittest on my project, but im having some problems.

I have a class called DataReader which sends an object to FacebookRest class like this.

$facebook = new FacebookRest($this);

How do i call a unit test on this class? When i try to new the class in unittest it will tell me that i need the parameter of DataReader

I do like this:

public function testFaceBook()
{
    $facebook = new FacebookRest();
}

Any suggestions?

You can use 2 ways to solve this issue:

  1. Use AspectMock (https://github.com/Codeception/AspectMock) to mock new objects see link below:

https://github.com/Codeception/AspectMock#allows-replacement-of-class-methods

  1. As @Gordon said you can use Dependency injection pattern (https://en.wikipedia.org/wiki/Dependency_injection)

Up to you