-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
Hi. As per the title, I can't seem to make byDefault work. Setup:
ExampleClass class:
<?php
declare(strict_types=1);
namespace Example\Plugin\DataProvider;
class ExampleClass
{
public function getExampleOption(): string
{
return get_option('example', null);
}
}Base TestCase class:
<?php
declare(strict_types=1);
namespace Example\Package\TestConfig\PhpUnit;
use Brain\Monkey;
use Brain\Monkey\Expectation\Expectation;
use Brain\Monkey\Functions;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\TestCase as Base;
abstract class TestCase extends Base
{
use MockeryPHPUnitIntegration;
protected function setUp(): void
{
parent::setUp();
Monkey\setUp();
Functions\stubEscapeFunctions();
Functions\stubTranslationFunctions();
}
protected function tearDown(): void
{
parent::tearDown();
Monkey\tearDown();
Mockery::close();
}
protected function userFunction(string $functionName): Expectation
{
return Functions\expect($functionName);
}
}And finally, an example test case
<?php
declare(strict_types=1);
namespace Example\Plugin\Tests\DataProvider;
use Example\Plugin\DataProvider\ExampleClass;
use Example\Package\TestConfig\PhpUnit\TestCase;
class ExampleClassTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->userFunction('get_option')
->with('example', null)
->andReturn('I was set in setUp')
->byDefault();
}
public function testReturnOption(): void
{
$example = new ExampleClass();
$this->assertSame('I was set in setUp', $example->getExampleOption());
$this->userFunction('get_option')
->with('example', null)
->andReturn('I was set in testReturnOption');
$this->assertSame('I was set in testReturnOption', $example->getExampleOption());
}
}What I'd expect to see is the assertions varying. What I instead see if the first scenario pass and the second fail as the text hasn't changed.
Is there something I'm doing wrong and if not, is this something we think could be supported as it's currently causing major headaches when shifting to this from WP Mock (as we want to use newer PHPUnit versions!)
Thanks
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels