I'm trying to understand how phpunit is working and how to apply phpunit to my wordpress projects.
I am able to run the official wp-tests suite of wordpress and also i made some simple test with my wordpress plugins code.
Now I'm stuck on trying to use the so called "stubbing". php manual says: The practice of replacing an object with a test double that (optionally) returns configured return values is refered to as stubbing.
i just made a sample like the one on phpunit manual but once I'm calling the getMock() method I have always a fatal error
Fatal error: Call to undefined method SampleMockTest::generate()
I'm working on
- windows 7
- XAMPP 1.7.7 with PHP: 5.3.8
- PHPUNIT 3.7.5
- phpstorm as IDE
code for file some-class.php
<?php
class SomeClass {
public function doSomething() {
return true;
}
public function doSomethingElse() {
return true;
}
}
?>
code for file samplemock.php
<?php
require_once 'C:\xampp\htdocs\wp-plugin-dev\wordpress\wp-content\plugins\secure-attachments\lib\some-class.php';
class SampleMockTest extends PHPUnit_Framework_TestCase
{
public function test_sample_mock()
{
$stub = $this->getMock('SomeClass');
$stub->expects($this->any())
->method('doSomething')
->will($this->returnValue('foo'));
$this->assertEquals('foo', $stub->doSomething());
}
}
?>
I read a tons of blogs and questions but I was not able to understand where is the problem and at least how to investigate it. I lost one day struggling on this without results.
the error once I start the test I have the error below
Fatal error: Call to undefined method SampleMockTest::generate() in C:\xampp\htdocs\wp-plugin-dev\vendor\phpunit\phpunit-mock-objects\src\Framework\MockObject\Generator.php on line 224
any idea?