Error: Call to undefined method DateFormatterTest::getMock()

Meteor Newbie

Update: with $stub = $this->createMock('Config'); this example works, but I get a warning:

OK, but incomplete, skipped, or risky tests! Tests: 1, Assertions: 0, Risky: 1.

In the video-tutorial this example works without any warnings. Is it possible to fix this warning?


I can't find why I am getting this error and how to fix it. This code is from a video tutorial. And in the Video it works. Maybe a typo?

Error:

c:\laragon\www\phpunit λ phpunit --colors tests\DateFormatterTest.php PHPUnit 6.0.0 by Sebastian Bergmann and contributors.

E 1 / 1 (100%)

Time: 35 ms, Memory: 4.00MB

There was 1 error:

1) DateFormatterTest::testFormattingDatesBasedOnConfig Error: Call to undefined method DateFormatterTest::getMock()

C:\laragon\www\phpunit\tests\DateFormatterTest.php:10

ERRORS! Tests: 1, Assertions: 0, Errors: 1.

Here my code:

Config.php

<?php

class Config {
    public function get() {
        return 'd-m-Y';
    }
}

DateFormatter.php

class DateFormatter { protected $config;

public function __construct (Config $config) {
    $this->config = $config;
}

public function getFormattedDate($timestamp) {
    return date($this->config->get('date.format'), $timestamp);
}

}

DateFormatterTest.php

<?php

use PHPUnit\Framework\TestCase;

require_once 'C:\laragon\www\phpunit\src\DateFormatter.php';
require_once 'C:\laragon\www\phpunit\src\Config.php';

class DateFormatterTest extends TestCase {
    public function testFormattingDatesBasedOnConfig() {
        $stub = $this->getMock('Config');

        var_dump($stub);
    }
}
Sebastian Bergmann

getMock() no longer exists in PHPUnit 6. Use createMock() or getMockBuilder() instead.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Call to undefined method error

Call to undefined method create() error

Call to undefined method error in Laravel

getMock() undefined in PHPUnit tests with HHVM

PHP Error: Fatal error: Call to undefined method

CakePHP error: Call to undefined method FlashComponent::error()

Fatal Error - Call to undefined method "Customersss::throwError()"

Fatal error: Call to undefined method PDOStatement::lastInsertId()

Fatal error: Call to undefined method db::_results()

CakePHP call to undefined method stdClass::read() error

Fatal error: Call to undefined method MongoCollection::insertMany()?

Fatal error: Call to undefined method connectDB::prepare()

PHP Classes - Fatal error: Call to undefined method

Mediawiki Error: Call to undefined method User::saveToCache()

Fatal Error :: Call to undefined method in codeigniter

Fatal error Call to undefined method VmVendorPDF::convertHTMLColorToDec()

Fatal error: Call to undefined method DB::getInstance()

xampp - Fatal error: Call to undefined method

PHP: Fatal error: Call to undefined method mysqli

Fatal error: Call to undefined method DOMDocument::getElementsById()

Call to undefined method stdClass::isEmpty() error

Error: Call to undefined method get() in PHPUnit Symfony

php error Call to an undefined static method with PHPStan

JQueryValidation plugin error: "Uncaught TypeError: Cannot call method 'call' of undefined"

PHP - Fatal Error: Call to undefined method - but method exist

Fatal error: Uncaught Error: Call to undefined method why?

How to fix 'Uncaught Error: Call to undefined method' in PHP

Routing error in Laravel resulting in: Call to undefined method ReflectionUnionType::getName()

C++ method pointer call yields undefined symbol error?