John Davidson

php - The "PHPUnit\Framework\TestCase::__construct()" method is considered internal

0 comments
Message:


I have made a phpunit test that looks like this:


class MyTest extends KernelTestCase
{

/**
* MyTest constructor.
*/
public function __construct()
{
parent::__construct();
// ...
}

public function testSomething()
{
self::assertTrue(true);
}
}

But executing the test shows this warning:


$ ./bin/phpunit
PHPUnit 8.5.14 by Sebastian Bergmann and contributors.

Testing Project Test Suite
. 1 / 1 (100%)

Time: 630 ms, Memory: 6.00 MB

OK (1 test, 1 assertion)

Other deprecation notices (1)

1x: The "PHPUnit\Framework\TestCase::__construct()" method is considered internal This method is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not extend it from "App\Tests\MyTest".

How do I get rid of that warning? I might usesetUpBeforeClass(), but then I would have to make all properties of the unit test static even if they are only used in the tests. I could use setUp() but this method is executed once for each test and I need the initialization code that is supposed to be in the constructor executed only one time. Is using static properties considered a good practice in this case? Is this the way I am expected to code my unit tests?



My Answer:
PHP (Hypertext Preprocessor) is a server-side scripting language that is widely used for web development. It can be embedded into HTML code and is commonly used to create dynamic web pages and applications. PHP is open source and supported by a large community of developers, making it a popular choice for building websites and web applications.

Rate this post

4 of 5 based on 5134 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us