I'm having problems getting mockery to find the function call with shouldReceive and getting setUp to carry the $mock variable to the test method. The class I am testing is:
<?php
class MockTester
{
public function getOne()
{
return 1;
}
public function getTwo()
{
return 2;
}
public function getThree()
{
return 5;
}enter code here
}
The test I am writing looks like:
<?php
class MockTesterTest extends TestCase
{
private $mockTester;
public function setUp()
{
parent::setUp();
$mockTester = \Mockery::mock('MockTester[getOne]');
}
public function tearDown()
{
Mockery::close();
}
public function testThree()
{
//When $mocktester is declared below I get Method getOne() from enter code hereMockery_0_MockTester should be called, exactly 1 times but called 0 times.
//$mockTester = \Mockery::mock('MockTester[getOne]');
$mockTester->shouldReceive('getOne')->once();
}
}
When $mocktester is declared in getThree I get "Method getOne() from enter code hereMockery_0_MockTester should be called, exactly 1 times but called 0 times". When it is not declared in getThree, it says Undefined variable: mockTester. When I remove set up and tear down everything runs fine.
class MockTesterTest extends TestCase
{
private $mockTester;
public function testThree()
{
$mockTester = \Mockery::mock('MockTester[getOne]');
$mockTester->shouldReceive('getOne')->once();
}
}
I really need the set up and tear down for my project, but I keep running into this issue. I've tried protected, and public, but there is something I'm forgetting.
Aucun commentaire:
Enregistrer un commentaire