Preconditions (*)
- Magento 2.3.1 upgraded from Magento 2.3.0
- Php 7.2.15
- OS : Ubuntu 18.04 Bionic
- Phpstorm 2019.1.1
- Evnironemnt : Magento development
- PHPUnit 6.5.0
- magento/magento2-functional-testing-framework": "~2.3.13"
Steps to reproduce (*)
- Follow the code to reproduce the error
Error
PHP Fatal error: Class Mock_LoggerInterface_a49cf619 contains 8 abstract >methods and must therefore be declared abstract or implement the remaining >methods (Psr\Log\LoggerInterface::emergency, Psr\Log>\LoggerInterface::alert, Psr\Log\LoggerInterface::critical, ...) in /var/www/html/myproject/vendor/phpunit/phpunit-mock-objects>/src/Generator.php(264) : eval()'d code on line 1
My class code is given below
use Psr\Log\LoggerInterface;
class Foo {
private $logger;
private $myclassObject;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function Bar ()
{
// some code
$logger->debug ('debug message')
}
}
My Test Class Code is
use PHPUnit\Framework\TestCase;
class FooTest extends TestCase
{
private $logger;
public function setUp()
{
$this->logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')
->setMethods(null)
->getMock();
$this->logger->expects($this->any())
->method('debug')
->willReturn('Message Logged');
}
$this->myclassObject = $this->getMockBuilder('MyVendor\MyModule\Model\Foo')
->setMethods(['__construct'])
->setConstructorArgs(['$logger'])
->disableOriginalConstructor()
->getMock();
public function testBar()
{
$this->assertEquals($expected_result,$this->myclassObject->Bar());
}
}
I'm expecting a successful unit test.