I created this script for testing purposes, and I have a Calculadora
class that receives as an instance an instance of class Operacao
, when I perform the unit test passing the class the test occurs successfully.
But when I replace the class Operacao
with a mock
I get an error
stating that the class is not of the desired type . How do I pass%% of this class?
Calculator.php
<?php
namespace Application;
use Application\operacao;
class Calculadora
{
private $num;
private $num2;
private $operacao;
private $resul;
public function __construct(operacao $operacao, int $num, int $num2)
{
$this->operacao = $operacao;
$this->num = $num;
$this->num2 = $num2;
}
public function Somar()
{
return $this->num + $this->num2;
}
}
operacao.php
namespace Application;
class operacao
{
private $operacao;
public function __construct(String $opc)
{
$this->operacao = $opc;
}
public function getOperacao()
{
return $this->operacao;
}
}
PHPTest
use PHPUnit_Framework_TestCase as PHPUnit;
use Application\Calculadora;
use Application\operacao;
class PHPTest extends PHPUnit
{
public function setUp()
{
$this->opc = $this->getMockBuilder('operacao')
->getMock();
//$this->opc = new operacao('Soma');
$this->Calculadora = new Calculadora($this->opc, 1 , 2);
}
public function tearDown()
{
}
public function testOperacaoMatematica()
{
$this->assertEquals(3, $this->Calculadora->Somar());
}
}